diff --git a/cmd/apis/apis.go b/cmd/apis/apis.go index 7d979b85f..343299b5f 100644 --- a/cmd/apis/apis.go +++ b/cmd/apis/apis.go @@ -30,6 +30,8 @@ var ( conn, revision int ) +const zipExt = ".zip" + func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") diff --git a/cmd/apis/bundlecrtapis.go b/cmd/apis/bundlecrtapis.go index 14e4a42af..323b72bf9 100644 --- a/cmd/apis/bundlecrtapis.go +++ b/cmd/apis/bundlecrtapis.go @@ -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 diff --git a/cmd/apis/cloneapi.go b/cmd/apis/cloneapi.go index 158c43d0c..924f1fd1c 100644 --- a/cmd/apis/cloneapi.go +++ b/cmd/apis/cloneapi.go @@ -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 diff --git a/cmd/apis/depapi.go b/cmd/apis/depapi.go index 5735330fe..d812271f7 100644 --- a/cmd/apis/depapi.go +++ b/cmd/apis/depapi.go @@ -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 diff --git a/cmd/apis/gqlcrtapis.go b/cmd/apis/gqlcrtapis.go index 9b7d3463c..d4930718c 100644 --- a/cmd/apis/gqlcrtapis.go +++ b/cmd/apis/gqlcrtapis.go @@ -97,7 +97,7 @@ var GqlCreateCmd = &cobra.Command{ } if importProxy { - _, err = apis.CreateProxy(name, name+".zip") + _, err = apis.CreateProxy(name, name+zipExt) } return err diff --git a/cmd/apis/oascrtapis.go b/cmd/apis/oascrtapis.go index 1e123e999..18fb0b4f9 100644 --- a/cmd/apis/oascrtapis.go +++ b/cmd/apis/oascrtapis.go @@ -113,7 +113,7 @@ var OasCreateCmd = &cobra.Command{ } if importProxy { - _, err = apis.CreateProxy(name, name+".zip") + _, err = apis.CreateProxy(name, name+zipExt) } return err diff --git a/cmd/apis/swaggerapis.go b/cmd/apis/swaggerapis.go index cfa93dcb3..5caee770c 100644 --- a/cmd/apis/swaggerapis.go +++ b/cmd/apis/swaggerapis.go @@ -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 diff --git a/cmd/apps/createkey.go b/cmd/apps/createkey.go index 651c27b05..2de6e0d13 100644 --- a/cmd/apps/createkey.go +++ b/cmd/apps/createkey.go @@ -15,6 +15,9 @@ package apps import ( + "fmt" + "strconv" + "internal/apiclient" "internal/client/apps" @@ -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 }, } @@ -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") diff --git a/cmd/apps/updatekey.go b/cmd/apps/updatekey.go index 0f3effd11..4e377b2d1 100644 --- a/cmd/apps/updatekey.go +++ b/cmd/apps/updatekey.go @@ -15,6 +15,9 @@ package apps import ( + "fmt" + "strconv" + "internal/apiclient" "internal/client/apps" @@ -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 }, } @@ -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") diff --git a/cmd/env/crtarchive.go b/cmd/env/crtarchive.go index afe9627b6..5b50ab60c 100644 --- a/cmd/env/crtarchive.go +++ b/cmd/env/crtarchive.go @@ -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 diff --git a/cmd/sharedflows/depsf.go b/cmd/sharedflows/depsf.go index 578b8fa28..2295b12e3 100644 --- a/cmd/sharedflows/depsf.go +++ b/cmd/sharedflows/depsf.go @@ -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 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 { diff --git a/internal/client/kvm/entries.go b/internal/client/kvm/entries.go index bc8d40be1..300f9c29d 100644 --- a/internal/client/kvm/entries.go +++ b/internal/client/kvm/entries.go @@ -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) }