Description
If I want to create a password with a leading - character the create-alias command will fail:
knoxcli.sh create-alias name --value "-asdf"
The same is true for the batch alias creation command. Using quotes around the value doesn't help. Generated passwords sometimes contain - character and sometimes they start with that character.
The reason for this is this check:
} else if (args[i].equals("--value")) { if (i + 1 >= args.length || args[i + 1].startsWith("-")) { printKnoxShellUsage(); return -1; }
This tries to prevent incorrect usage by checking if the next parameter is likely an another command (so the actual value is missing).
For example this prevents this case where the user mistakenly combined the --value (without defining a value) with the --generate command.
bin/knoxcli.sh create-alias test --value --generate
However we can prevent this by explicitly testing if the next parameter is any of the commands supported by the create-alias/create-aliases command. There are only 2, --generate and --cluster.
So these kind of incorrect usages can be tested with:
if (args.length > i + 1 && ("--generate".equals(args[i + 1]) || "--cluster".equals(args[i + 1]))) { // missing value printKnoxShellUsage(); return -1; }
So I think we should use the above check instead.
Misusing the batch alias command will generate error regardless of this check because the number of parameters won't match.
Here there is no value for a1.
knoxcli.sh create-aliases --alias a1 --value --alias a2 --value v2
For this no extra check is required.
Attachments
Issue Links
- links to