diff --git a/apiclient/options.go b/apiclient/options.go index 06ba31721..045b5e776 100644 --- a/apiclient/options.go +++ b/apiclient/options.go @@ -200,7 +200,7 @@ func SetProxyURL(proxyurl string) { //DryRun func DryRun() bool { - if os.Getenv("APIGEECLI_DRYNRUN") != "" { + if os.Getenv("APIGEECLI_DRYRUN") != "" { clilog.Warning.Println("Dry run mode enabled! unset APIGEECLI_DRYRUN to disable dry run") return true } diff --git a/client/targetservers/targetservers.go b/client/targetservers/targetservers.go index a1627dd45..888db39fe 100644 --- a/client/targetservers/targetservers.go +++ b/client/targetservers/targetservers.go @@ -20,6 +20,7 @@ import ( "net/url" "os" "path" + "strconv" "sync" "github.com/apigee/apigeecli/apiclient" @@ -31,18 +32,18 @@ type targetserver struct { Description string `json:"description,omitempty"` Host string `json:"host,omitempty"` Port int `json:"port,omitempty"` - IsEnabled bool `json:"isEnabled,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` Protocol string `json:"protocol,omitempty"` SslInfo *sslInfo `json:"sSLInfo,omitempty"` } type sslInfo struct { - Enabled bool `json:"enabled,omitempty"` - ClientAuthEnabled bool `json:"clientAuthEnabled,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + ClientAuthEnabled *bool `json:"clientAuthEnabled,omitempty"` Keystore string `json:"keyStore,omitempty"` Keyalias string `json:"keyAlias,omitempty"` Truststore string `json:"trustStore,omitempty"` - IgnoreValidationErrors bool `json:"ignoreValidationErrors,omitempty"` + IgnoreValidationErrors *bool `json:"ignoreValidationErrors,omitempty"` Protocols []string `json:"protocols,omitempty"` Ciphers []string `json:"ciphers,omitempty"` CommonName *commonName `json:"commonName,omitempty"` @@ -54,7 +55,7 @@ type commonName struct { } //Create -func Create(name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, sslinfo bool, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { +func Create(name string, description string, host string, port int, enable string, grpc bool, keyStore string, keyAlias string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { targetsvr := targetserver{} targetsvr.Name = name @@ -62,7 +63,7 @@ func Create(name string, description string, host string, port int, enable bool, } //Update -func Update(name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, sslinfo bool, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { +func Update(name string, description string, host string, port int, enable string, grpc bool, keyStore string, keyAlias string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { var targetRespBody []byte var targetsvr = targetserver{} @@ -80,7 +81,7 @@ func Update(name string, description string, host string, port int, enable bool, return createOrUpdate("update", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) } -func createOrUpdate(action string, targetsvr targetserver, name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, sslinfo bool, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { +func createOrUpdate(action string, targetsvr targetserver, name string, description string, host string, port int, enable string, grpc bool, keyStore string, keyAlias string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { var reqBody []byte sslInfoObj := new(sslInfo) @@ -101,31 +102,28 @@ func createOrUpdate(action string, targetsvr targetserver, name string, descript targetsvr.Protocol = "GRPC" } - if enable { - targetsvr.IsEnabled = enable + if enable != "" { + targetsvr.IsEnabled = new(bool) + *targetsvr.IsEnabled, _ = strconv.ParseBool(enable) } - if tlsenabled { - sslInfoObj.Enabled = tlsenabled - } - - if clientAuthEnabled { - sslInfoObj.ClientAuthEnabled = clientAuthEnabled - } + if sslinfo != "" { + sslInfoObj.Enabled = new(bool) + sslInfoObj.ClientAuthEnabled = new(bool) + sslInfoObj.IgnoreValidationErrors = new(bool) - if ignoreValidationErrors { - sslInfoObj.IgnoreValidationErrors = ignoreValidationErrors - } + *sslInfoObj.Enabled = tlsenabled + *sslInfoObj.ClientAuthEnabled = clientAuthEnabled + *sslInfoObj.IgnoreValidationErrors = ignoreValidationErrors - if keyAlias != "" { - sslInfoObj.Keyalias = keyAlias - } + if keyAlias != "" { + sslInfoObj.Keyalias = keyAlias + } - if keyStore != "" { - sslInfoObj.Keystore = keyStore - } + if keyStore != "" { + sslInfoObj.Keystore = keyStore + } - if sslinfo { targetsvr.SslInfo = sslInfoObj } diff --git a/cmd/targetservers/crtts.go b/cmd/targetservers/crtts.go index ef6dc20f0..24d750430 100644 --- a/cmd/targetservers/crtts.go +++ b/cmd/targetservers/crtts.go @@ -15,6 +15,9 @@ package targetservers import ( + "fmt" + "strconv" + "github.com/apigee/apigeecli/apiclient" "github.com/apigee/apigeecli/client/targetservers" "github.com/spf13/cobra" @@ -27,6 +30,11 @@ var CreateCmd = &cobra.Command{ Long: "Create a Target Server", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + if sslinfo != "" { + if _, err = strconv.ParseBool(sslinfo); err != nil { + return fmt.Errorf("Invalid value for sslinfo. Must be set to true or false") + } + } return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -36,8 +44,8 @@ var CreateCmd = &cobra.Command{ }, } -var description, host, keyStore, keyAlias string -var enable, grpc, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors bool +var description, host, keyStore, keyAlias, sslinfo, enable string +var grpc, tlsenabled, clientAuthEnabled, ignoreValidationErrors bool var port int func init() { @@ -48,8 +56,8 @@ func init() { "", "Description for the Target Server") CreateCmd.Flags().StringVarP(&host, "host", "s", "", "Host name of the target") - CreateCmd.Flags().BoolVarP(&enable, "enable", "b", - true, "Enabling/disabling a TargetServer") + CreateCmd.Flags().StringVarP(&enable, "enable", "b", + "", "Enabling/disabling a TargetServer") CreateCmd.Flags().BoolVarP(&grpc, "grpc", "g", false, "Enable target server for gRPC") @@ -57,8 +65,8 @@ func init() { "", "Key store for the target server; must be used with sslinfo") CreateCmd.Flags().StringVarP(&keyAlias, "keyAlias", "", "", "Key alias for the target server; must be used with sslinfo") - CreateCmd.Flags().BoolVarP(&sslinfo, "sslinfo", "", - false, "Enable SSL Info on the target server") + CreateCmd.Flags().StringVarP(&sslinfo, "sslinfo", "", + "", "Enable SSL Info on the target server") CreateCmd.Flags().BoolVarP(&tlsenabled, "tls", "", false, "Enable TLS for the target server; must be used with sslinfo") CreateCmd.Flags().BoolVarP(&clientAuthEnabled, "clientAuth", "c", diff --git a/cmd/targetservers/updatets.go b/cmd/targetservers/updatets.go index 086196772..a61bfb0b5 100644 --- a/cmd/targetservers/updatets.go +++ b/cmd/targetservers/updatets.go @@ -15,6 +15,9 @@ package targetservers import ( + "fmt" + "strconv" + "github.com/apigee/apigeecli/apiclient" "github.com/apigee/apigeecli/client/targetservers" "github.com/spf13/cobra" @@ -27,6 +30,16 @@ var UpdateCmd = &cobra.Command{ Long: "Update a Target Server", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + if sslinfo != "" { + if _, err = strconv.ParseBool(sslinfo); err != nil { + return fmt.Errorf("Invalid value for sslinfo. Must be set to true or false") + } + } + if enable != "" { + if _, err = strconv.ParseBool(enable); err != nil { + return fmt.Errorf("Invalid value for enable. Must be set to true or false") + } + } return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -43,8 +56,8 @@ func init() { "", "Description for the Target Server") UpdateCmd.Flags().StringVarP(&host, "host", "s", "", "Host name of the target") - UpdateCmd.Flags().BoolVarP(&enable, "enable", "b", - true, "Enabling/disabling a TargetServer") + UpdateCmd.Flags().StringVarP(&enable, "enable", "b", + "", "Enabling/disabling a TargetServer") UpdateCmd.Flags().BoolVarP(&grpc, "grpc", "g", false, "Enable target server for gRPC") @@ -52,8 +65,8 @@ func init() { "", "Key store for the target server; must be used with sslinfo") UpdateCmd.Flags().StringVarP(&keyAlias, "keyAlias", "", "", "Key alias for the target server; must be used with sslinfo") - UpdateCmd.Flags().BoolVarP(&sslinfo, "sslinfo", "", - false, "Enable SSL Info on the target server") + UpdateCmd.Flags().StringVarP(&sslinfo, "sslinfo", "", + "", "Enable SSL Info on the target server") UpdateCmd.Flags().BoolVarP(&tlsenabled, "tls", "", false, "Enable TLS for the target server; must be used with sslinfo") UpdateCmd.Flags().BoolVarP(&clientAuthEnabled, "clientAuth", "c",