Repository navigation
add sub-account deletion to the CLI #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
19480be
add organizations delete-sub-account command
oshchyhol 6fe6532
document organizations delete-sub-account
oshchyhol 67c1109
update the permission note for deleting a sub-account
oshchyhol fa7133d
document the feature and conflict refusals for delete-sub-account
oshchyhol db8cbe1
reject non-numeric ids in delete-sub-account
oshchyhol 87f6fbb
test that delete-sub-account reports API errors
oshchyhol a4dc748
ask agents to confirm before deleting a sub-account
oshchyhol 71ac6ad
say a concurrent sub-account deletion may fail with 409
oshchyhol 7de8d5a
pass --org-id in the organizations test plan rows
oshchyhol f0fc219
reject extra positional arguments in delete-sub-account
oshchyhol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package organizations | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/mailtrap/mailtrap-cli/internal/client" | ||
| "github.com/mailtrap/mailtrap-cli/internal/cmdutil" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewCmdDeleteSubAccount(f *cmdutil.Factory) *cobra.Command { | ||
| var orgID int64 | ||
| var subAccountID int64 | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "delete-sub-account", | ||
| Args: cobra.NoArgs, | ||
| Short: "Delete a sub-account from an organization", | ||
| Long: `Delete a sub-account from an organization. Requires organization admin permissions. | ||
| The organization must have the Organization & Sub-accounts feature enabled; otherwise the command fails with 403. | ||
|
|
||
| The deletion is permanent: the sub-account and all of its data are removed and cannot be restored. | ||
| Deleting the organization's last sub-account also deletes the organization. | ||
|
|
||
| A repeated call for the same sub-account returns 404. A concurrent deletion of the same sub-account may fail with 409. Rate limit: 10 requests per minute per organization.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if !cmd.Flags().Changed("org-id") { | ||
| return fmt.Errorf("--org-id is required") | ||
| } | ||
| if orgID <= 0 { | ||
| return fmt.Errorf("--org-id must be greater than 0") | ||
| } | ||
| if !cmd.Flags().Changed("sub-account-id") { | ||
| return fmt.Errorf("--sub-account-id is required") | ||
| } | ||
| if subAccountID <= 0 { | ||
| return fmt.Errorf("--sub-account-id must be greater than 0") | ||
| } | ||
|
|
||
| c, err := f.NewClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| path := fmt.Sprintf("/api/organizations/%d/sub_accounts/%d", orgID, subAccountID) | ||
|
|
||
| if err := c.Delete(context.Background(), client.BaseGeneral, path, nil); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Fprintf(f.IOStreams.Out, "Sub-account %d deleted successfully\n", subAccountID) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().Int64Var(&orgID, "org-id", 0, "Organization ID") | ||
| cmd.Flags().Int64Var(&subAccountID, "sub-account-id", 0, "Sub-account ID") | ||
|
|
||
| return cmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.