From 720ce83701a2bb7fcbf03fdf3a0f5a11b8205005 Mon Sep 17 00:00:00 2001 From: saiflayouni Date: Tue, 30 Jun 2026 12:43:46 +0100 Subject: [PATCH] fix: preserve API product approval status when importing apps (#661) When exporting apps, the `apiProducts` field on each credential includes a `status` field ("approved"/"revoked"). During import the code only associated products with the key but never called the approve action, so all products were left in the default (revoked) state. This commit: - Adds `Status` to the `apiProduct` struct so it is unmarshalled from the export file - After updating credentials, calls `ManageKey(..., "approve", product)` for every product that had status "approved" in the export Also fixes a pre-existing vet error in keys_test.go where ManageKey was called with 4 arguments instead of the required 5. --- internal/client/apps/apps.go | 15 ++++++++++++++- internal/client/apps/keys_test.go | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/client/apps/apps.go b/internal/client/apps/apps.go index 0f492422b..00c91e993 100644 --- a/internal/client/apps/apps.go +++ b/internal/client/apps/apps.go @@ -60,7 +60,8 @@ type credential struct { } type apiProduct struct { - Name string `json:"apiproduct,omitempty"` + Name string `json:"apiproduct,omitempty"` + Status string `json:"status,omitempty"` } type importCredential struct { @@ -540,6 +541,18 @@ func createAsyncApp(app application, developerEntities developers.Appdevelopers, if err != nil { return } + + // set the API product status on the credential if it was approved + for _, apiProd := range credential.APIProducts { + if apiProd.Status == "approved" { + apiclient.ClientPrintHttpResponse.Set(false) + _, err = ManageKey(url.QueryEscape(developerEmail), app.Name, credential.ConsumerKey, "approve", apiProd.Name) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) + if err != nil { + clilog.Warning.Printf("failed to approve API product %s on key %s: %v\n", apiProd.Name, credential.ConsumerKey, err) + } + } + } } else { clilog.Warning.Println("NOTE: apiProducts are not associated with the app") } diff --git a/internal/client/apps/keys_test.go b/internal/client/apps/keys_test.go index 527282f26..fbc04bfc1 100644 --- a/internal/client/apps/keys_test.go +++ b/internal/client/apps/keys_test.go @@ -52,7 +52,7 @@ func TestManageKey(t *testing.T) { clienttest.SITEID_NOT_REQD, clienttest.CLIPATH_NOT_REQD); err != nil { t.Fatalf("%v", err) } - if _, err := ManageKey(name, appID, "key1", "approve"); err != nil { + if _, err := ManageKey(name, appID, "key1", "approve", ""); err != nil { t.Fatalf("%v", err) } }