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-7005: Implement EnableAuthService in cli #4649

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,25 @@ var app = &cli.App{
Usage: "work with organizations",
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "auth-service",
Usage: "manage auth-service",
Subcommands: []*cli.Command{
{
Name: "enable",
Usage: "enable auth-service for OAuth applications",
UsageText: createUsageText("enable", []string{generalFlagOrgID}, true),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID tied to OAuth applications",
},
},
Action: createCommandWithT[enableAuthServiceArgs](EnableAuthServiceAction),
},
},
},
{
Name: "list",
Usage: "list organizations for the current user",
Expand Down
33 changes: 33 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,39 @@ func (c *viamClient) organizationsSupportEmailGetAction(cCtx *cli.Context, orgID
return nil
}

type enableAuthServiceArgs struct {
OrgID string
}

// EnableAuthServiceAction corresponds to 'organizations auth-service enable'.
func EnableAuthServiceAction(cCtx *cli.Context, args enableAuthServiceArgs) error {
c, err := newViamClient(cCtx)
if err != nil {
return err
}

orgID := args.OrgID
if orgID == "" {
return errors.New("cannot enable auth service without an organization ID")
}

return c.enableAuthServiceAction(cCtx, args.OrgID)
}

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

_, err := c.client.EnableAuthService(cCtx.Context, &apppb.EnableAuthServiceRequest{OrgId: orgID})
if err != nil {
return err
}

printf(cCtx.App.Writer, "enabled auth service for organization %q:\n", orgID)
return nil
}

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

func TestEnableAuthServiceAction(t *testing.T) {
enableAuthServiceFunc := func(ctx context.Context, in *apppb.EnableAuthServiceRequest, opts ...grpc.CallOption) (
*apppb.EnableAuthServiceResponse, error,
) {
return &apppb.EnableAuthServiceResponse{}, nil
}

asc := &inject.AppServiceClient{
EnableAuthServiceFunc: enableAuthServiceFunc,
}

cCtx, ac, out, errOut := setup(asc, nil, nil, nil, nil, "token")

test.That(t, ac.enableAuthServiceAction(cCtx, "test-org"), 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, "enabled auth")
}

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)
EnableAuthServiceFunc func(ctx context.Context, in *apppb.EnableAuthServiceRequest,
opts ...grpc.CallOption) (*apppb.EnableAuthServiceResponse, 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...)
}

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