Add methods to extract values from Arguments
Currently, commandargs.AuthorizedKeys
and commandargs.AuthorizedPrincipals
will get their properties assigned in
their Parse()
methods.
We get the values from the Arguments
property which we also access when validating them in validate()
.
To make them a bit DRYer, add methods instead of directly accessing Arguments
.
The following discussion from !322 (merged) should be addressed:
From !322 (comment 202968166):
WDYT about applying the same pattern to
commandargs.AuthorizedKeys
too? I can do it in this MR too.
Context
> WDYT about adding `keyIdFromArgs()` & `principalsFromArgs()` and calling instead of accessing `ap.Arguments` directly twice? e.g.
>
> ```golang
> func (ap *AuthorizedPrincipals) Parse() error {
> // ...
> ap.KeyId = ap.keyIdFromArgs()
> ap.Principals = ap.principalsFromArgs()
> // ...
> }
>
> func (ap *AuthorizedPrincipals) keyIdFromArgs() string {
> return ap.Arguments[0]
> }
>
> func (ap *AuthorizedPrincipals) principalsFromArgs() []string {
> return ap.Arguments[1:]
> }
>
> func (ap *AuthorizedPrincipals) validate() error {
> // ...
> if ap.keyIdFromArgs() == "" {
> // ...
>
> for _, principal := range ap.principalsFromArgs() {
> // ...
> }
>
> ```