diff --git a/cmd/apps/createkey.go b/cmd/apps/createkey.go index 651c27b05..d5283ebd8 100644 --- a/cmd/apps/createkey.go +++ b/cmd/apps/createkey.go @@ -15,7 +15,9 @@ package apps import ( + "fmt" "internal/apiclient" + "strconv" "internal/client/apps" @@ -31,7 +33,10 @@ var CreateKeyCmd = &cobra.Command{ return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { - _, err = apps.CreateKey(developerEmail, name, key, secret, apiProducts, scopes, attrs) + if _, err = strconv.Atoi(expires); err != nil { + return fmt.Errorf("expires must be an integer: %v", err) + } + _, err = apps.CreateKey(developerEmail, name, key, secret, apiProducts, scopes, expires, attrs) return }, } @@ -45,6 +50,8 @@ func init() { []string{}, "A list of api products") CreateKeyCmd.Flags().StringArrayVarP(&scopes, "scopes", "s", []string{}, "OAuth scopes") + CreateKeyCmd.Flags().StringVarP(&expires, "expires", "x", + "", "A setting, in milliseconds, for the lifetime of the consumer key") CreateKeyCmd.Flags().StringToStringVar(&attrs, "attrs", nil, "Custom attributes") diff --git a/cmd/apps/updatekey.go b/cmd/apps/updatekey.go index 0f3effd11..742710bd3 100644 --- a/cmd/apps/updatekey.go +++ b/cmd/apps/updatekey.go @@ -15,7 +15,9 @@ package apps import ( + "fmt" "internal/apiclient" + "strconv" "internal/client/apps" @@ -31,7 +33,10 @@ var UpdateKeyCmd = &cobra.Command{ return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { - _, err = apps.UpdateKey(developerEmail, name, key, secret, apiProducts, scopes, attrs) + if _, err = strconv.Atoi(expires); err != nil { + return fmt.Errorf("expires must be an integer: %v", err) + } + _, err = apps.UpdateKey(developerEmail, name, key, secret, apiProducts, scopes, expires, attrs) return }, } @@ -45,6 +50,8 @@ func init() { []string{}, "A list of api products") UpdateKeyCmd.Flags().StringArrayVarP(&scopes, "scopes", "s", []string{}, "OAuth scopes") + UpdateKeyCmd.Flags().StringVarP(&expires, "expires", "x", + "", "A setting, in milliseconds, for the lifetime of the consumer key") UpdateKeyCmd.Flags().StringToStringVar(&attrs, "attrs", nil, "Custom attributes") diff --git a/internal/client/apps/keys.go b/internal/client/apps/keys.go index 27f211071..4ab8d6f98 100644 --- a/internal/client/apps/keys.go +++ b/internal/client/apps/keys.go @@ -24,7 +24,7 @@ import ( ) // CreateKey -func CreateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) { +func CreateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, apiProducts []string, scopes []string, expires string, attrs map[string]string) (respBody []byte, err error) { u, _ := url.Parse(apiclient.BaseURL) key := []string{} @@ -43,6 +43,10 @@ func CreateKey(developerEmail string, appID string, consumerKey string, consumer key = append(key, "\"consumerKey\":\""+consumerKey+"\"") key = append(key, "\"consumerSecret\":\""+consumerSecret+"\"") + if expires != "" { + key = append(key, "\"expiresAt\":\""+expires+"\"") + } + payload := "{" + strings.Join(key, ",") + "}" u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys") @@ -83,7 +87,7 @@ func GetKey(developerEmail string, appID string, key string) (respBody []byte, e } // UpdateKey -func UpdateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) { +func UpdateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, apiProducts []string, scopes []string, expires string, attrs map[string]string) (respBody []byte, err error) { u, _ := url.Parse(apiclient.BaseURL) key := []string{} @@ -96,6 +100,10 @@ func UpdateKey(developerEmail string, appID string, consumerKey string, consumer key = append(key, "\"scopes\":[\""+getArrayStr(scopes)+"\"]") } + if expires != "" { + key = append(key, "\"expiresAt\":\""+expires+"\"") + } + if len(attrs) > 0 { attributes := []string{} for keyattr, value := range attrs {