Skip to content

Commit

Permalink
Merge pull request #322 from apigee/issue321
Browse files Browse the repository at this point in the history
feat: adds support for key expiry #321
  • Loading branch information
ssvaidyanathan authored Oct 27, 2023
2 parents 0f18af6 + b1ebcdf commit 0ccd586
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cmd/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var (
conn, revision int
)

const zipExt = ".zip"

func init() {
Cmd.PersistentFlags().StringVarP(&org, "org", "o",
"", "Apigee organization name")
Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/bundlecrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var BundleCreateCmd = &cobra.Command{
}
defer os.RemoveAll(tmpDir)

proxyBundlePath := path.Join(tmpDir, name+".zip")
proxyBundlePath := path.Join(tmpDir, name+zipExt)

if err = proxybundle.GenerateArchiveBundle(proxyFolder, proxyBundlePath, false); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/cloneapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var CloneCmd = &cobra.Command{
return err
}

proxyBundlePath := path.Join(tmpDir, name+".zip")
proxyBundlePath := path.Join(tmpDir, name+zipExt)

if err = proxybundle.GenerateArchiveBundle(path.Join(tmpDir, "apiproxy"), proxyBundlePath, false); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/apis/depapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ var DepCmd = &cobra.Command{
return true
} else if respMap["state"] == "READY" {
clilog.Info.Println("Proxy deployment completed with status: ", respMap["state"])
return false
} else {
clilog.Info.Println("Proxy deployment failed with status: ", respMap["state"])
return false
}
return false
})

<-stop
Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/gqlcrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var GqlCreateCmd = &cobra.Command{
}

if importProxy {
_, err = apis.CreateProxy(name, name+".zip")
_, err = apis.CreateProxy(name, name+zipExt)
}

return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/oascrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var OasCreateCmd = &cobra.Command{
}

if importProxy {
_, err = apis.CreateProxy(name, name+".zip")
_, err = apis.CreateProxy(name, name+zipExt)
}

return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/swaggerapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var SwaggerCreateCmd = &cobra.Command{
addCORS)

if importProxy {
_, err = apis.CreateProxy(name, name+".zip")
_, err = apis.CreateProxy(name, name+zipExt)
}

return err
Expand Down
10 changes: 9 additions & 1 deletion cmd/apps/createkey.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,7 +34,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
},
}
Expand All @@ -45,6 +51,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")

Expand Down
10 changes: 9 additions & 1 deletion cmd/apps/updatekey.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,7 +34,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
},
}
Expand All @@ -45,6 +51,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")

Expand Down
3 changes: 1 addition & 2 deletions cmd/env/crtarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ var CreateArchiveCmd = &cobra.Command{
} else {
clilog.Info.Printf("Archive deployment failed with status: %s", respMap.Error.Message)
}
return false
} else {
clilog.Info.Printf("Unknown state %s", respMap.Metadata.State)
return false
}
return false
})

<-stop
Expand Down
3 changes: 1 addition & 2 deletions cmd/sharedflows/depsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ var DepCmd = &cobra.Command{
return true
} else if respMap["state"] == "READY" {
clilog.Info.Println("Sharedflow deployment completed with status: ", respMap["state"])
return false
} else {
clilog.Info.Println("Sharedflow deployment failed with status: ", respMap["state"])
return false
}
return false
})

<-stop
Expand Down
12 changes: 10 additions & 2 deletions internal/client/apps/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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")
Expand Down Expand Up @@ -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{}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/kvm/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func ExportAllEntries() (err error) {
}

for _, proxy := range p.Proxies {
//search for only programmable proxies. standard proxies can't have KVMs
// search for only programmable proxies. standard proxies can't have KVMs
if proxy.APIProxyType == "PROGRAMMABLE" {
programmableProxies = append(programmableProxies, proxy.Name)
}
Expand Down

0 comments on commit 0ccd586

Please sign in to comment.