Skip to content

Commit

Permalink
Setting expires consistently for seconds or Apps and AppGroup Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtkanaskie committed Dec 14, 2023
1 parent 685dd23 commit 46bad6d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 16 deletions.
15 changes: 10 additions & 5 deletions cmd/appgroups/createkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ var CreateKeyCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = appgroups.CreateKey(name, appName, key, secret, strconv.Itoa(expiry), apiProducts, scopes, attrs)
if expires != "" {
if _, err = strconv.Atoi(expires); err != nil {
return fmt.Errorf("expires must be an integer: %v", err)
}
}
_, err = appgroups.CreateKey(name, appName, key, secret, expires, apiProducts, scopes, attrs)
return
},
}

var (

Check failure on line 49 in cmd/appgroups/createkey.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 49 in cmd/appgroups/createkey.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
secret string
expiry int
secret string

Check failure on line 50 in cmd/appgroups/createkey.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 50 in cmd/appgroups/createkey.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
)

func init() {
Expand All @@ -55,8 +59,8 @@ func init() {
"", "Import an existing AppGroup app consumer key")
CreateKeyCmd.Flags().StringVarP(&secret, "secret", "r",
"", "Import an existing AppGroup app consumer secret")
CreateKeyCmd.Flags().IntVarP(&expiry, "expiry", "x",
-1, "Expiration time, in seconds, for the consumer key")
CreateKeyCmd.Flags().StringVarP(&expires, "expires", "x",
"", "A setting, in seconds, for the lifetime of the consumer key")
CreateKeyCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p",
[]string{}, "A list of api products")
CreateKeyCmd.Flags().StringArrayVarP(&scopes, "scopes", "s",
Expand All @@ -66,4 +70,5 @@ func init() {

_ = CreateKeyCmd.MarkFlagRequired("name")
_ = CreateKeyCmd.MarkFlagRequired("app-name")
_ = CreateKeyCmd.MarkFlagRequired("prods")
}
12 changes: 11 additions & 1 deletion cmd/appgroups/crtapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package appgroups

import (
"fmt"
"strconv"

"internal/apiclient"

"internal/client/appgroups"
Expand All @@ -31,6 +34,12 @@ var CreateAppCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if expires != "" {
if _, err = strconv.Atoi(expires); err != nil {
return fmt.Errorf("expires must be an integer: %v", err)
}
expires += "000"
}
_, err = appgroups.CreateApp(name, appName, expires, callback, apiProducts, scopes, attrs)
return
},
Expand All @@ -47,7 +56,7 @@ func init() {
CreateAppCmd.Flags().StringVarP(&appName, "app-name", "",
"", "Name of the app")
CreateAppCmd.Flags().StringVarP(&expires, "expires", "x",
"", "A setting, in milliseconds, for the lifetime of the consumer key")
"", "A setting, in seconds, for the lifetime of the consumer key")
CreateAppCmd.Flags().StringVarP(&callback, "callback", "c",
"", "The callbackUrl is used by OAuth")
CreateAppCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p",
Expand All @@ -59,4 +68,5 @@ func init() {

_ = CreateAppCmd.MarkFlagRequired("name")
_ = CreateAppCmd.MarkFlagRequired("app-name")
_ = CreateAppCmd.MarkFlagRequired("prods")
}
11 changes: 10 additions & 1 deletion cmd/appgroups/updateapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package appgroups

import (
"fmt"
"strconv"

"internal/apiclient"

"internal/client/appgroups"
Expand All @@ -31,6 +34,12 @@ var UpdateAppCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if expires != "" {
if _, err = strconv.Atoi(expires); err != nil {
return fmt.Errorf("expires must be an integer: %v", err)
}
expires += "000"
}
_, err = appgroups.UpdateApp(name, appName, expires, callback, apiProducts, scopes, attrs)
return
},
Expand All @@ -42,7 +51,7 @@ func init() {
UpdateAppCmd.Flags().StringVarP(&appName, "app-name", "",
"", "Name of the app")
UpdateAppCmd.Flags().StringVarP(&expires, "expires", "x",
"", "A setting, in milliseconds, for the lifetime of the consumer key")
"", "A setting, in seconds, for the lifetime of the consumer key")
UpdateAppCmd.Flags().StringVarP(&callback, "callback", "c",
"", "The callbackUrl is used by OAuth")
UpdateAppCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p",
Expand Down
11 changes: 10 additions & 1 deletion cmd/apps/crtapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package apps

import (
"fmt"
"strconv"

"internal/apiclient"

"internal/client/apps"
Expand All @@ -31,6 +34,12 @@ var CreateCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if expires != "" {
if _, err = strconv.Atoi(expires); err != nil {
return fmt.Errorf("expires must be an integer: %v", err)
}
expires += "000"
}
_, err = apps.Create(name, email, expires, callback, apiProducts, scopes, attrs)
return
},
Expand All @@ -48,7 +57,7 @@ func init() {
CreateCmd.Flags().StringVarP(&email, "email", "e",
"", "The developer's email or id")
CreateCmd.Flags().StringVarP(&expires, "expires", "x",
"", "A setting, in milliseconds, for the lifetime of the consumer key")
"", "A setting, in seconds, for the lifetime of the consumer key")
CreateCmd.Flags().StringVarP(&callback, "callback", "c",
"", "The callbackUrl is used by OAuth")
CreateCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p",
Expand Down
9 changes: 9 additions & 0 deletions cmd/apps/updateapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package apps

import (
"fmt"
"strconv"

"internal/apiclient"

"internal/client/apps"
Expand All @@ -31,6 +34,12 @@ var UpdateCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if expires != "" {
if _, err = strconv.Atoi(expires); err != nil {
return fmt.Errorf("expires must be an integer: %v", err)
}
expires += "000"
}
_, err = apps.Update(name, email, expires, callback, apiProducts, scopes, attrs)
return
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/updatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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)
_, err = apps.UpdateKey(developerEmail, name, key, apiProducts, scopes, attrs)
return
},
}
Expand Down
7 changes: 5 additions & 2 deletions internal/client/appgroups/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func CreateKey(name string, appName string, consumerKey string, consumerSecret s
key = append(key, "\"consumerSecret\":\""+consumerSecret+"\"")
}

if expiresInSeconds != "" {
key = append(key, "\"expiresInSeconds\":\""+expiresInSeconds+"\"")
}

payload := "{" + strings.Join(key, ",") + "}"

u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName, "keys")
Expand All @@ -60,9 +64,8 @@ func CreateKey(name string, appName string, consumerKey string, consumerSecret s

// since the API does not support adding products when creating a key, use a second API call to add products
if len(apiProducts) > 0 {
apiclient.ClientPrintHttpResponse.Set(false)
apiclient.ClientPrintHttpResponse.Set(true)
respBody, err = UpdateKeyProducts(name, appName, consumerKey, apiProducts)
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
}

return respBody, err
Expand Down
6 changes: 1 addition & 5 deletions internal/client/apps/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func GetKey(developerEmail string, appID string, key string) (respBody []byte, e
}

// UpdateKey
func UpdateKey(developerEmail string, appID string, consumerKey string, consumerSecret string,
func UpdateKey(developerEmail string, appID string, consumerKey string,
apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)

Expand All @@ -110,10 +110,6 @@ func UpdateKey(developerEmail string, appID string, consumerKey string, consumer

key = append(key, "\"consumerKey\":\""+consumerKey+"\"")

if consumerSecret != "" {
key = append(key, "\"consumerSecret\":\""+consumerSecret+"\"")
}

payload := "{" + strings.Join(key, ",") + "}"

u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey)
Expand Down

0 comments on commit 46bad6d

Please sign in to comment.