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-7002: Implement “DeleteOAuthApplication” CLI command #4648

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
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
31 changes: 31 additions & 0 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const (
authApplicationFlagOriginURIs = "origin-uris"
authApplicationFlagRedirectURIs = "redirect-uris"
authApplicationFlagLogoutURI = "logout-uri"
authApplicationFlagClientID = "client-id"

cpFlagRecursive = "recursive"
cpFlagPreserve = "preserve"
Expand Down Expand Up @@ -425,6 +426,36 @@ var app = &cli.App{
Usage: "work with organizations",
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "auth-service",
Usage: "manage auth-service",
Subcommands: []*cli.Command{
{
Name: "oauth-app",
Usage: "manage the oauth applications for an organization",
Subcommands: []*cli.Command{
{
Name: "delete",
Usage: "delete an oauth application",
UsageText: createUsageText("delete", []string{generalFlagOrgID, authApplicationFlagClientID}, true),
Copy link
Member

Choose a reason for hiding this comment

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

Please provide an image in the description of what this looks like so that it's easy for us to check what this looks like in the end

Copy link
Member

Choose a reason for hiding this comment

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

Oh, never mind! I didn't know what UsageText was and thought this was Usage. Looks good!

Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID tied to the oauth application",
},
&cli.StringFlag{
Name: authApplicationFlagClientID,
Required: true,
Usage: "ID of the application to delete",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Usage: "ID of the application to delete",
Usage: "client ID of the OAuth application to delete",

},
},
Action: createCommandWithT[deleteOAuthAppArgs](DeleteOAuthAppAction),
},
},
},
},
},
{
Name: "list",
Usage: "list organizations for the current user",
Expand Down
34 changes: 34 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2050,3 +2050,37 @@ func logEntryFieldsToString(fields []*structpb.Struct) (string, error) {
}
return message + "}", nil
}

type deleteOAuthAppArgs struct {
OrgID string
ClientID string
}

// DeleteOAuthAppAction is the corresponding action for 'auth-service update'.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// DeleteOAuthAppAction is the corresponding action for 'auth-service update'.
// DeleteOAuthAppAction is the corresponding action for 'auth-service delete'.

func DeleteOAuthAppAction(c *cli.Context, args deleteOAuthAppArgs) error {
client, err := newViamClient(c)
if err != nil {
return err
}

return client.deleteOAuthAppAction(c, args.OrgID, args.ClientID)
}

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

req := &apppb.DeleteOAuthAppRequest{
OrgId: orgID,
ClientId: clientID,
}

_, err := c.client.DeleteOAuthApp(c.c.Context, req)
if err != nil {
return err
}

printf(cCtx.App.Writer, "Successfully deleted oauth application")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
printf(cCtx.App.Writer, "Successfully deleted oauth application")
printf(cCtx.App.Writer, "Successfully deleted OAuth application")

return nil
}
19 changes: 19 additions & 0 deletions cli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ func TestGetLogoAction(t *testing.T) {
test.That(t, out.messages[0], test.ShouldContainSubstring, "https://logo.com")
}

func TestDeleteOAuthAppAction(t *testing.T) {
deleteOAuthAppFunc := func(ctx context.Context, in *apppb.DeleteOAuthAppRequest, opts ...grpc.CallOption) (
*apppb.DeleteOAuthAppResponse, error,
) {
return &apppb.DeleteOAuthAppResponse{}, nil
}

asc := &inject.AppServiceClient{
DeleteOAuthAppFunc: deleteOAuthAppFunc,
}

cCtx, ac, out, errOut := setup(asc, nil, nil, nil, nil, "token")
test.That(t, ac.deleteOAuthAppAction(cCtx, "test-org", "client-id"), test.ShouldBeNil)
test.That(t, len(errOut.messages), test.ShouldEqual, 0)
test.That(t, len(out.messages), test.ShouldEqual, 1)
test.That(t, out.messages[0], test.ShouldContainSubstring, "Successfully deleted oauth application")

}

func TestUpdateBillingServiceAction(t *testing.T) {
updateConfigFunc := func(ctx context.Context, in *apppb.UpdateBillingServiceRequest, opts ...grpc.CallOption) (
*apppb.UpdateBillingServiceResponse, error,
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)
DeleteOAuthAppFunc func(ctx context.Context, in *apppb.DeleteOAuthAppRequest,
opts ...grpc.CallOption) (*apppb.DeleteOAuthAppResponse, 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...)
}

// DeleteOAuthApp calls the injected DeleteOAuthAppFunc or the real version.
func (asc *AppServiceClient) DeleteOAuthApp(
ctx context.Context, in *apppb.DeleteOAuthAppRequest, opts ...grpc.CallOption,
) (*apppb.DeleteOAuthAppResponse, error) {
if asc.DeleteOAuthAppFunc == nil {
return asc.AppServiceClient.DeleteOAuthApp(ctx, in, opts...)
}
return asc.DeleteOAuthAppFunc(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