make error actionable when adding operator+leafnodes

There are many examples in the documentation for one half of this configuration or the other,
but none which configure a leafnode remote on an operator-authenticated cluster.

The error "operator mode requires account nkeys in remotes." is not very clear or actionable.
This commit is contained in:
David Laban
2021-08-17 17:34:57 +01:00
parent a5afa86790
commit 1d5cc21c3c
2 changed files with 7 additions and 2 deletions

View File

@@ -276,7 +276,10 @@ func validateLeafNode(o *Options) error {
}
for _, r := range o.LeafNode.Remotes {
if !nkeys.IsValidPublicAccountKey(r.LocalAccount) {
return fmt.Errorf("operator mode requires account nkeys in remotes")
return fmt.Errorf(
"operator mode requires account nkeys in remotes. " +
"Please add an `account` key to each remote in your `leafnodes` section, to assign it to an account. " +
"Each account value should be a 56 character public key, starting with the letter 'A'")
}
}
if o.LeafNode.Port != 0 && o.LeafNode.Account != "" && !nkeys.IsValidPublicAccountKey(o.LeafNode.Account) {

View File

@@ -2483,7 +2483,9 @@ func TestLeafNodeOperatorBadCfg(t *testing.T) {
authorization {
account: notankey
}`,
`operator mode requires account nkeys in remotes`: `remotes: [{url: u}]`,
("operator mode requires account nkeys in remotes. " +
"Please add an `account` key to each remote in your `leafnodes` section, to assign it to an account. " +
"Each account value should be a 56 character public key, starting with the letter 'A'"): `remotes: [{url: u}]`,
} {
t.Run(errorText, func(t *testing.T) {
conf := createConfFile(t, []byte(fmt.Sprintf(`