Skip to content
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-6999: Implement “ReadOAuthApplication” CLI command #4652

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gloriacai01
Copy link
Member

@gloriacai01 gloriacai01 commented Dec 20, 2024

Adds viam organizations auth-service oauth-app read --org-id=<org-id> --client-id=<client-id>

Manual Testing:
Screenshot 2024-12-20 at 3 37 59 PM

@gloriacai01 gloriacai01 requested a review from a team as a code owner December 20, 2024 20:32
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Dec 20, 2024
Copy link
Member

@RoxyFarhad RoxyFarhad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good! Only real actionable change is for testing + have some other questions.

Usage: "manage the OAuth applications for an organization",
Subcommands: []*cli.Command{
{
Name: "read",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing get to read for pulling the config for an OAuth application. Copied this from the scope:

"viam organization auth-service oauth-app create / read / update / delete " is a very logical replacement for "*viam auth-app register / update / get*". From a UX perspective, it is cleaner to create oauth-apps within the auth-service.

The other changes make sense to me but read doesn't seem either industry or viam standard to encapsulate making a GET request for an object.

We use get for logo / support email and get-config for branded billing, and it seems the standard for our CLI is get or just the name of the object being returned (i.e. robot logs returns the robot logs) . I've also never seen read an alias in other SDKs (happy to be proven wrong here) but this alias doesn't make logical sense to me.

Something like config to show that we return the config for the auth application makes a lot more sense to me.

@maxhorowitz @ohEmily

return nil
}

func protoToString(protoString, prefixToTrim string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit: I would make this something like formatStringForOutput() or something more along those lines. This is both taking an input and returning a string as output so it not really doing the conversion / there isn't really a conversion to be done.

May also make sense to put this in utils.go file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also agree on changing the name of this function, since there's no conversion going on, but reformatting.

config := resp.OauthConfig
printf(cCtx.App.Writer, "OAuth config for client ID %s:", clientID)
printf(cCtx.App.Writer, "")
printf(cCtx.App.Writer, "Client Authentication: %s", protoToString(config.ClientAuthentication.String(), clientAuthenticationPrefix))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we return these prefixes if we are going to be removing them? I know this isn't your problem but that is the case we should be doing this formatting in the server itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix is there for all proto enums. In the Go SDK, we put these enums into shadow types with prefixes as well because funcCall(passwordRequired, methodUnspecified) is more readable than funcCall(required, unspecified ...). In this case, it's a little annoying to present, but I think it's good practice to keep these as is since the configs are returning specific enum values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, can you elaborate more on what this means for my general learning?

we put these enums into shadow types with prefixes

Where do we define how to do this?

Copy link
Member

@purplenicole730 purplenicole730 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general rule, we avoid giving users direct access to proto types, so we define shadow types that wrap around proto types. There are a lot of examples in the app wrappers (i.e. FragmentVisibility). Then we have helper functions to convert them.

Copy link
Member

@purplenicole730 purplenicole730 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see that we keep these prefixes as it's a good idea to have an inkling of what public means when it's used. Which is why in this case when we're trying to present them, it's a little annoying.

OauthConfig: &apppb.OAuthConfig{
ClientAuthentication: apppb.ClientAuthentication_CLIENT_AUTHENTICATION_REQUIRED,
Pkce: apppb.PKCE_PKCE_REQUIRED,
UrlValidation: apppb.URLValidation_URL_VALIDATION_ALLOW_WILDCARDS,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a test with some of the prefixes as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test not already testing the prefixes? These variables wouldn't pass otherwise (i.e. CLIENT_AUTHENTICATION_REQUIRED becoming required)

Copy link
Member

@purplenicole730 purplenicole730 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, barring a helper function rename

return nil
}

func protoToString(protoString, prefixToTrim string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also agree on changing the name of this function, since there's no conversion going on, but reformatting.

OauthConfig: &apppb.OAuthConfig{
ClientAuthentication: apppb.ClientAuthentication_CLIENT_AUTHENTICATION_REQUIRED,
Pkce: apppb.PKCE_PKCE_REQUIRED,
UrlValidation: apppb.URLValidation_URL_VALIDATION_ALLOW_WILDCARDS,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test not already testing the prefixes? These variables wouldn't pass otherwise (i.e. CLIENT_AUTHENTICATION_REQUIRED becoming required)

config := resp.OauthConfig
printf(cCtx.App.Writer, "OAuth config for client ID %s:", clientID)
printf(cCtx.App.Writer, "")
printf(cCtx.App.Writer, "Client Authentication: %s", protoToString(config.ClientAuthentication.String(), clientAuthenticationPrefix))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix is there for all proto enums. In the Go SDK, we put these enums into shadow types with prefixes as well because funcCall(passwordRequired, methodUnspecified) is more readable than funcCall(required, unspecified ...). In this case, it's a little annoying to present, but I think it's good practice to keep these as is since the configs are returning specific enum values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants