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-6821: Adding the cli command to disable the billing service #4611

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
13 changes: 10 additions & 3 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,21 @@ var app = &cli.App{
Action: GetBillingConfigAction,
},
{
Name: "update",
Usage: "update the billing service update for an organization",
Name: "disable",
Usage: "disable the billing service for an organization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to update the billing service for",
Usage: "the org to disable the billing service for",
},
},
Action: OrganizationDisableBillingServiceAction,
},
{
Name: "update",
Usage: "update the billing service update for an organization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: organizationBillingAddress,
Required: true,
Expand Down
28 changes: 28 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,34 @@ func (c *viamClient) getBillingConfig(cCtx *cli.Context, orgID string) error {
return nil
}

// OrganizationDisableBillingServiceAction corresponds to `organizations billing disable`.
func OrganizationDisableBillingServiceAction(cCtx *cli.Context) error {
client, err := newViamClient(cCtx)
if err != nil {
return err
}
orgID := cCtx.String(generalFlagOrgID)
if orgID == "" {
return errors.New("cannot disable billing service without an organization ID")
}
return client.organizationDisableBillingServiceAction(cCtx, orgID)
}

func (c *viamClient) organizationDisableBillingServiceAction(cCtx *cli.Context, orgID string) error {
JosephBorodach marked this conversation as resolved.
Show resolved Hide resolved
if err := c.ensureLoggedIn(); err != nil {
return err
}

if _, err := c.client.DisableBillingService(cCtx.Context, &apppb.DisableBillingServiceRequest{
OrgId: orgID,
}); err != nil {
return errors.WithMessage(err, "could not disable billing service")
}

printf(cCtx.App.Writer, "Successfully disabled billing service for organization: %s", orgID)
return nil
}

// ListLocationsAction is the corresponding Action for 'locations list'.
func ListLocationsAction(c *cli.Context) error {
client, err := newViamClient(c)
Expand Down
19 changes: 19 additions & 0 deletions cli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ func TestGetSupportEmailAction(t *testing.T) {
test.That(t, out.messages[0], test.ShouldContainSubstring, "test-email")
}

func TestBillingServiceDisableAction(t *testing.T) {
JosephBorodach marked this conversation as resolved.
Show resolved Hide resolved
disableBillingFunc := func(ctx context.Context, in *apppb.DisableBillingServiceRequest, opts ...grpc.CallOption) (
*apppb.DisableBillingServiceResponse, error,
) {
return &apppb.DisableBillingServiceResponse{}, nil
}

asc := &inject.AppServiceClient{
DisableBillingServiceFunc: disableBillingFunc,
}

cCtx, ac, out, errOut := setup(asc, nil, nil, nil, nil, "token")
test.That(t, ac.organizationDisableBillingServiceAction(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, "Successfully disabled billing service for organization: ")
}

func TestGetBillingConfigAction(t *testing.T) {
getConfigEmailFunc := func(ctx context.Context, in *apppb.GetBillingServiceConfigRequest, opts ...grpc.CallOption) (
*apppb.GetBillingServiceConfigResponse, error,
Expand Down
Loading