From ea965d33ed5349ac42f91f9fdbe2fb9891434038 Mon Sep 17 00:00:00 2001 From: srinandan <13950006+srinandan@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:55:05 -0800 Subject: [PATCH] feat: add fwd proxy uri #327 --- cmd/env/crtenv.go | 12 ++++++++++-- internal/client/env/env.go | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/env/crtenv.go b/cmd/env/crtenv.go index 347f5483a..d87809eca 100644 --- a/cmd/env/crtenv.go +++ b/cmd/env/crtenv.go @@ -15,7 +15,9 @@ package env import ( + "fmt" "internal/apiclient" + "net/url" "internal/client/env" @@ -28,16 +30,20 @@ var CreateCmd = &cobra.Command{ Short: "Create a new environment", Long: "Create a new environment", Args: func(cmd *cobra.Command, args []string) (err error) { + _, err = url.Parse(fwdProxyURI) + if err != nil { + return fmt.Errorf("invalid URI string for fwdProxyURI: %v", err) + } apiclient.SetApigeeEnv(environment) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { - _, err = env.Create(deploymentType, apiProxyType) + _, err = env.Create(deploymentType, apiProxyType, fwdProxyURI) return }, } -var deploymentType, apiProxyType string +var deploymentType, apiProxyType, fwdProxyURI string func init() { CreateCmd.Flags().StringVarP(&environment, "env", "e", @@ -46,5 +52,7 @@ func init() { "", "Deployment type - must be PROXY or ARCHIVE") CreateCmd.Flags().StringVarP(&apiProxyType, "proxtype", "p", "", "Proxy type - must be PROGRAMMABLE or CONFIGURABLE") + CreateCmd.Flags().StringVarP(&fwdProxyURI, "fowdproxyuri", "f", + "", "URL of the forward proxy to be applied to the runtime instances in this env") _ = CreateCmd.MarkFlagRequired("env") } diff --git a/internal/client/env/env.go b/internal/client/env/env.go index 872e1c8a4..e03148181 100644 --- a/internal/client/env/env.go +++ b/internal/client/env/env.go @@ -26,7 +26,7 @@ import ( ) // Create -func Create(deploymentType string, apiProxyType string) (respBody []byte, err error) { +func Create(deploymentType string, apiProxyType string, fwdProxyURI string) (respBody []byte, err error) { environment := []string{} environment = append(environment, "\"name\":\""+apiclient.GetApigeeEnv()+"\"") @@ -44,6 +44,10 @@ func Create(deploymentType string, apiProxyType string) (respBody []byte, err er environment = append(environment, "\"apiProxyType\":\""+apiProxyType+"\"") } + if fwdProxyURI != "" { + environment = append(environment, "\"forwardProxyUri\":\""+fwdProxyURI+"\"") + } + payload := "{" + strings.Join(environment, ",") + "}" u, _ := url.Parse(apiclient.BaseURL)