-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APP-7001: Add UpdateOauthApp CLI command #4641
base: main
Are you sure you want to change the base?
Conversation
cli/app.go
Outdated
authApplicationFlagName = "application-name" | ||
authApplicationFlagApplicationID = "application-id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment above these that they will be deprecated once https://viam.atlassian.net/browse/APP-6993 is complete. IDK what the standard is for adding comments in a public repo of ours, will defer to someone on the SDK/Netcode team for a decision here
cli/app.go
Outdated
authApplicationFlagClientID = "client-id" | ||
authApplicationFlagClientName = "client-name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
authApplicationFlagClientID = "client-id" | |
authApplicationFlagClientName = "client-name" | |
authApplicationFlagOAuthApplicationClientID = "client-id" | |
authApplicationFlagOAuthApplicationClientName = "client-name" |
cli/app.go
Outdated
&cli.StringFlag{ | ||
Name: generalFlagOrgID, | ||
Required: true, | ||
Usage: "organization ID that is tied to the oauth application", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage: "organization ID that is tied to the oauth application", | |
Usage: "organization ID that is tied to the OAuth application", |
ClientAuthentication string | ||
Pkce string | ||
LogoutURI string | ||
UrlValidation string //nolint:revive,stylecheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuqdog is this ok? linter wants it to be URLValidation, but parseStructFromCtx
doesn't seem to recognize that the passed in flag in the cli is associated with this field when its URLValidation, so I have the field named as UrlValidation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh yeah, that's a bit of a gotcha. I think what you did is correct, but thanks for flagging it! I'll file a ticket to revisit our struct parsing logic to see how we can avoid that in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli/app.go
Outdated
@@ -8,6 +8,7 @@ import ( | |||
"strings" | |||
|
|||
"github.com/urfave/cli/v2" | |||
apppb "go.viam.com/api/app/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look into why we are adding this dependency now (I would think this would have existed already and adding it is a mistake).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triple check to confirm the dependency on API is okay -- even though inherently this stuff is "dependent" on the API I feel like this is a red herring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting to see that this may be okay - it is imported already in this package (only in a different file) - the real question becomes whether we want to hardcode the string values that we import here instead of importing them - to maybe check against breaking changes in our API ... ? Again - deferring to someone who owns this code path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see an actual issue with this, but it is a bit jarring to see a proto being imported here
cli/client.go
Outdated
pkceEnum, ok := apppb.PKCE_value[pkcePrefix+strings.ToUpper(pkce)] | ||
if !ok { | ||
return nil, errors.Errorf("%s must be a valid PKCE, got %s. "+ | ||
"See `viam organizations auth-service oauth-app update --help` for supported options", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1001,3 +1001,31 @@ func TestShellFileCopy(t *testing.T) { | |||
}) | |||
}) | |||
} | |||
|
|||
func TestUpdateOAuthAppAction(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add cases which check that passing in bad values to each of these will result in a specific error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting on a second set of eyes for some of the qs / comments I've left on the PR. Content-wise, everything is okay to me. Some nits / renaming suggestions, a comment about adding test case coverage, and a question about importing go.viam.com/api/app/v1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of converting the enums manually each time, it would be more readable to make a shadow type of each enum with a ToProto()
function that you can use in the function.
cli/app.go
Outdated
&cli.StringFlag{ | ||
Name: oauthAppFlagClientAuthentication, | ||
Usage: "updated client authentication policy for the OAuth application. can be one of " + | ||
allEnumValues(clientAuthenticationPrefix, apppb.ClientAuthentication_value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide an example of what this would look like in the description so we know what these values mean and look like. This applies to all the other flags that also have a similar setup.
cli/app.go
Outdated
@@ -8,6 +8,7 @@ import ( | |||
"strings" | |||
|
|||
"github.com/urfave/cli/v2" | |||
apppb "go.viam.com/api/app/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see an actual issue with this, but it is a bit jarring to see a proto being imported here
cli/client.go
Outdated
const ( | ||
clientAuthenticationPrefix = "CLIENT_AUTHENTICATION_" | ||
pkcePrefix = "PKCE_" | ||
urlValidationPrefix = "URL_VALIDATION_" | ||
enabledGrantPrefix = "ENABLED_GRANT_" | ||
) | ||
|
||
// allEnumValues returns the possible values we accept for a given proto enum. | ||
func allEnumValues(prefixToTrim string, enumValueMap map[string]int32) string { | ||
var formattedValues []string | ||
for values := range enumValueMap { | ||
formattedValue := strings.ToLower(strings.TrimPrefix(values, prefixToTrim)) | ||
formattedValues = append(formattedValues, formattedValue) | ||
} | ||
slices.Sort(formattedValues) | ||
return "[" + strings.Join(formattedValues, ", ") + "]" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, I'd just make shadow types to wrap around the proto enum types. You can look at the clients in rdk/app/
folder to see examples. (i.e. app.Visibility
).
cli/client.go
Outdated
clientAuthenticationEnum, ok := apppb.ClientAuthentication_value[clientAuthenticationPrefix+strings.ToUpper(clientAuthentication)] | ||
if !ok { | ||
return nil, errors.Errorf("--%s must be a valid ClientAuthentication, got %s. "+ | ||
"See `viam organizations auth-service oauth-app update --help` for supported options", | ||
oauthAppFlagClientAuthentication, clientAuthentication) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to what my above comment, I would just use a shadow type with toProto
functions. This applies to all of the enums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really close, just some nits here and there
Usage: "updated client authentication policy for the OAuth application. can be one of " + | ||
formatAcceptedValues(string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired), | ||
string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide an example in your description to how the usage text for this entire function looks like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why there's a helper function, as this can be easily printed by writing: fmt.Sprintf("updated comma separated enabled grants for the OAuth application. values can be of [%s, %s, %s, %s, %s]", string(...), ...)
. It doesn't seem to really save that much work, but does makes it harder to read for developers.
I guess one can argue that it would be a good practice to make sure future developers use this format, so I'm okay with keeping it the way this is or removing the helper function
cli/client.go
Outdated
func formatAcceptedValues(values ...string) string { | ||
joined := strings.Join(values, ", ") | ||
return "[" + joined + "]" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're keeping this function, I feel like this helper function belongs somewhere else. Maybe utils.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To other reviewers: sync over zoom with Gloria tested manually. All looks great to me.
cli/utils.go
Outdated
func formatAcceptedValues(values ...string) string { | ||
joined := strings.Join(values, ", ") | ||
return "[" + joined + "]" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for asking you to move this again when I'm the one who said to put it here, but I realized we could put this under createUsageText()
in cli/app.go
. And then add a comment to clarify what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Ticket here