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-7004] Implement ListOAuthApplications CLI Command #4646

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,17 @@ func (c *AppClient) OrganizationGetLogo(ctx context.Context, orgID string) (stri
return resp.Url, nil
}

// ListOAuthApps gets the client's list of OAuth applications.
func (c *AppClient) ListOAuthApps(ctx context.Context, orgID string) ([]string, error) {
resp, err := c.client.ListOAuthApps(ctx, &pb.ListOAuthAppsRequest{
OrgId: orgID,
})
if err != nil {
return nil, err
}
return resp.ClientIds, nil
}

// CreateLocation creates a location with the given name under the given organization.
func (c *AppClient) CreateLocation(ctx context.Context, orgID, name string, opts *CreateLocationOptions) (*Location, error) {
var parentID *string
Expand Down
15 changes: 15 additions & 0 deletions app/app_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,21 @@ func TestAppClient(t *testing.T) {
test.That(t, resp, test.ShouldEqual, "https://logo.com")
})

t.Run("ListOAuthApps", func(t *testing.T) {
grpcClient.ListOAuthAppsFunc = func(
ctx context.Context, in *pb.ListOAuthAppsRequest, opts ...grpc.CallOption,
) (*pb.ListOAuthAppsResponse, error) {
test.That(t, in.OrgId, test.ShouldEqual, organizationID)
return &pb.ListOAuthAppsResponse{
ClientIds: []string{"clientId"},
}, nil
}

resp, err := client.ListOAuthApps(context.Background(), organizationID)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp, test.ShouldResemble, []string{"clientId"})
})

t.Run("GetSupportEmail", func(t *testing.T) {
grpcClient.OrganizationGetSupportEmailFunc = func(
ctx context.Context, in *pb.OrganizationGetSupportEmailRequest, opts ...grpc.CallOption,
Expand Down
12 changes: 12 additions & 0 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,18 @@ var app = &cli.App{
},
},
},
{
Name: "list-oauth-apps",
Copy link
Member

Choose a reason for hiding this comment

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

do we want this to be the command? or should it be something like organization oauth list so we can also have organization oauth create etc.

would check scope and check with @maxhorowitz

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the existing delete command (created by gloria) as an example to work of so it should be good now

Usage: "list oauth applications for an organization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to get applications for",
},
},
Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction),
},
{
Name: "support-email",
Usage: "manage the support email for an organization",
Expand Down
43 changes: 43 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,49 @@ func (c *viamClient) organizationsLogoGetAction(cCtx *cli.Context, orgID string)
return nil
}

type listOAuthAppsArgs struct {
OrgID string
}

// ListOAuthAppsAction corresponds to `list-oauth-apps`.
Copy link
Member

Choose a reason for hiding this comment

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

can you add tests in client_test too pls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

func ListOAuthAppsAction(cCtx *cli.Context, args listOAuthAppsArgs) error {
c, err := newViamClient(cCtx)
if err != nil {
return err
}

orgID := args.OrgID
if orgID == "" {
return errors.New("organization ID is required to list OAuth apps")
}

return c.listOAuthAppsAction(cCtx, orgID)
}

func (c *viamClient) listOAuthAppsAction(cCtx *cli.Context, orgID string) error {
if err := c.ensureLoggedIn(); err != nil {
return err
}

resp, err := c.client.ListOAuthApps(cCtx.Context, &apppb.ListOAuthAppsRequest{
OrgId: orgID,
})
if err != nil {
return err
}

if len(resp.ClientIds) == 0 {
printf(cCtx.App.Writer, "No OAuth apps found for organization %q\n", orgID)
return nil
}

printf(cCtx.App.Writer, "OAuth apps for organization %q:\n", orgID)
for _, id := range resp.ClientIds {
printf(cCtx.App.Writer, " - %s\n", id)
}
return nil
}

// ListLocationsAction is the corresponding Action for 'locations list'.
func ListLocationsAction(c *cli.Context, args emptyArgs) error {
client, err := newViamClient(c)
Expand Down
12 changes: 12 additions & 0 deletions testutils/inject/app_service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type AppServiceClient struct {
opts ...grpc.CallOption) (*apppb.OrganizationSetLogoResponse, error)
OrganizationGetLogoFunc func(ctx context.Context, in *apppb.OrganizationGetLogoRequest,
opts ...grpc.CallOption) (*apppb.OrganizationGetLogoResponse, error)
ListOAuthAppsFunc func(ctx context.Context, in *apppb.ListOAuthAppsRequest,
opts ...grpc.CallOption) (*apppb.ListOAuthAppsResponse, error)
CreateLocationFunc func(ctx context.Context, in *apppb.CreateLocationRequest,
opts ...grpc.CallOption) (*apppb.CreateLocationResponse, error)
GetLocationFunc func(ctx context.Context, in *apppb.GetLocationRequest,
Expand Down Expand Up @@ -403,6 +405,16 @@ func (asc *AppServiceClient) OrganizationGetLogo(
return asc.OrganizationGetLogoFunc(ctx, in, opts...)
}

// ListOAuthApps calls the injected ListOAuthAppsFunc or the real version.
func (asc *AppServiceClient) ListOAuthApps(
ctx context.Context, in *apppb.ListOAuthAppsRequest, opts ...grpc.CallOption,
) (*apppb.ListOAuthAppsResponse, error) {
if asc.ListOAuthAppsFunc == nil {
return asc.AppServiceClient.ListOAuthApps(ctx, in, opts...)
}
return asc.ListOAuthAppsFunc(ctx, in, opts...)
}

// CreateLocation calls the injected CreateLocationFunc or the real version.
func (asc *AppServiceClient) CreateLocation(
ctx context.Context, in *apppb.CreateLocationRequest, opts ...grpc.CallOption,
Expand Down
Loading