Skip to content

Commit a543068

Browse files
authored
feat: adds ability to manage key on apiproduct #628 (#629)
1 parent 70d53a6 commit a543068

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/client/apps/keys.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,17 @@ func UpdateKey(developerEmail string, appID string, consumerKey string,
165165
return respBody, err
166166
}*/
167167

168-
func ManageKey(developerEmail string, appID string, consumerKey string, action string) (respBody []byte, err error) {
168+
func ManageKey(developerEmail string, appID string, consumerKey string, action string, product string) (respBody []byte, err error) {
169169
if action != "revoke" && action != "approve" {
170170
return nil, fmt.Errorf("invalid action. action must be revoke or approve")
171171
}
172172

173173
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
174-
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey)
174+
if product == "" {
175+
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey)
176+
} else {
177+
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey, "apiproducts", product)
178+
}
175179
q := u.Query()
176180
q.Set("action", action)
177181
u.RawQuery = q.Encode()

internal/cmd/apps/managekey.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var ManageKeyCmd = &cobra.Command{
3333
RunE: func(cmd *cobra.Command, args []string) (err error) {
3434
cmd.SilenceUsage = true
3535

36-
_, err = apps.ManageKey(developerEmail, name, key, action)
36+
_, err = apps.ManageKey(developerEmail, name, key, action, productName)
3737
return
3838
},
3939
}
@@ -45,6 +45,8 @@ func init() {
4545
"", "Developer app consumer key")
4646
ManageKeyCmd.Flags().StringVarP(&action, "action", "x",
4747
"revoke", "Action to perform - revoke or approve")
48+
ManageKeyCmd.Flags().StringVarP(&productName, "product", "",
49+
"", "Name of the API Product; If not set the action is performed on all the API Products")
4850

4951
_ = ManageKeyCmd.MarkFlagRequired("key")
5052
_ = ManageKeyCmd.MarkFlagRequired("action")

0 commit comments

Comments
 (0)