diff --git a/internal/client/apps/apps.go b/internal/client/apps/apps.go index 0f492422..00c91e99 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 527282f2..fbc04bfc 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) } }