-
Notifications
You must be signed in to change notification settings - Fork 26
chore: improve delete orga command #616
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package pkg | |
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
|
|
@@ -13,6 +14,36 @@ import ( | |
| "github.com/qovery/qovery-cli/utils" | ||
| ) | ||
|
|
||
| func printOrganizationsPreview(organizationIds []string) { | ||
| tokenType, token, err := utils.GetAccessToken() | ||
| if err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Double token acquisition
Suggestion: fetch the token once in |
||
| log.Warnf("Could not fetch organization details: %v", err) | ||
| for _, id := range organizationIds { | ||
| fmt.Printf(" - %s\n", id) | ||
| } | ||
| return | ||
| } | ||
| client := utils.GetQoveryClient(tokenType, token) | ||
|
|
||
| for _, orgId := range organizationIds { | ||
| org, _, err := client.OrganizationMainCallsAPI.GetOrganization(context.Background(), orgId).Execute() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 No timeout on API calls
Suggestion: ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
org, _, err := client.OrganizationMainCallsAPI.GetOrganization(ctx, orgId).Execute() |
||
| if err != nil { | ||
| fmt.Printf(" - %s (name: unknown)\n", orgId) | ||
| } else { | ||
| fmt.Printf(" - %s (%s)\n", orgId, org.Name) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Inconsistent indentation in output 2 spaces for orgs, 6 spaces for clusters. Not aligned with the rest of the codebase (e.g. Suggestion: fmt.Printf(" - cluster: %s (%s)\n", c.Id, c.Name) |
||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 No pagination on cluster list
At minimum, add a warning if there are more pages, or implement full pagination. |
||
| clusters, _, err := client.ClustersAPI.ListOrganizationCluster(context.Background(), orgId).Execute() | ||
| if err != nil { | ||
| log.Warnf("Could not fetch clusters for organization %s: %v", orgId, err) | ||
| } else if clusters != nil { | ||
| for _, c := range clusters.GetResults() { | ||
| fmt.Printf(" cluster: %s (%s)\n", c.Id, c.Name) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| type DeleteOrganizationsResponse struct { | ||
| Deleted []string `json:"deleted"` | ||
| Failed []DeleteOrganizationFailure `json:"failed"` | ||
|
|
@@ -33,7 +64,15 @@ func DeleteOrganizations(organizationIds []string, allowFailedClusters bool, dry | |
| os.Exit(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking bug — security regression
This is a regression introduced by this PR (verifiable on commit Suggestion: if !utils.Validate("delete") {
return
}
if !dryRunDisabled {
log.Info("Dry run: no deletion performed")
return
} |
||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Mixed The preview uses |
||
| if !utils.Validate("delete") { | ||
| fmt.Printf("The following %d organization(s) will be deleted (allowFailedClusters=%t):\n", len(organizationIds), allowFailedClusters) | ||
| printOrganizationsPreview(organizationIds) | ||
| fmt.Println() | ||
|
|
||
| if !dryRunDisabled { | ||
| if !utils.Validate("delete") { | ||
| return | ||
| } | ||
| log.Info("Dry run: no deletion performed") | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -49,14 +88,6 @@ func DeleteOrganizations(organizationIds []string, allowFailedClusters bool, dry | |
| log.Fatalf("Failed to marshal organization IDs: %v", err) | ||
| } | ||
|
|
||
| if !dryRunDisabled { | ||
| fmt.Printf("Would delete %d organization(s) (allowFailedClusters=%t):\n", len(organizationIds), allowFailedClusters) | ||
| for _, id := range organizationIds { | ||
| fmt.Printf(" - %s\n", id) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // Make HTTP request | ||
| res := deleteWithBody(url, http.MethodDelete, true, bytes.NewReader(body)) | ||
| if res == nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Missing period in
Long:descriptionMissing a period at the end of the sentence before the newline.