diff --git a/cmd/targetservers/crtts.go b/cmd/targetservers/crtts.go index 8483c5272..c001d2916 100644 --- a/cmd/targetservers/crtts.go +++ b/cmd/targetservers/crtts.go @@ -34,20 +34,20 @@ var CreateCmd = &cobra.Command{ 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 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) { - _, err = targetservers.Create(name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) + _, err = targetservers.Create(name, description, host, port, enable, grpc, keyStore, keyAlias, trustStore, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) return }, } -var description, host, keyStore, keyAlias, sslinfo, enable string -var grpc, tlsenabled, clientAuthEnabled, ignoreValidationErrors bool +var description, host, keyStore, keyAlias, trustStore, sslinfo string +var grpc, enable, tlsenabled, clientAuthEnabled, ignoreValidationErrors bool var port int func init() { @@ -58,8 +58,8 @@ func init() { "", "Description for the Target Server") CreateCmd.Flags().StringVarP(&host, "host", "s", "", "Host name of the target") - CreateCmd.Flags().StringVarP(&enable, "enable", "b", - "", "Enabling/disabling a TargetServer") + CreateCmd.Flags().BoolVarP(&enable, "enable", "b", + true, "Enabling/disabling a TargetServer") CreateCmd.Flags().BoolVarP(&grpc, "grpc", "g", false, "Enable target server for gRPC") @@ -67,6 +67,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().StringVarP(&trustStore, "trustStore", "", + "", "Trust store for the target server; must be used with sslinfo") CreateCmd.Flags().StringVarP(&sslinfo, "sslinfo", "", "", "Enable SSL Info on the target server") CreateCmd.Flags().BoolVarP(&tlsenabled, "tls", "", diff --git a/cmd/targetservers/updatets.go b/cmd/targetservers/updatets.go index f6780e11f..f14458814 100644 --- a/cmd/targetservers/updatets.go +++ b/cmd/targetservers/updatets.go @@ -37,15 +37,10 @@ var UpdateCmd = &cobra.Command{ 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) { - _, err = targetservers.Update(name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) + _, err = targetservers.Update(name, description, host, port, enable, grpc, keyStore, keyAlias, trustStore, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) return }, } @@ -58,8 +53,8 @@ func init() { "", "Description for the Target Server") UpdateCmd.Flags().StringVarP(&host, "host", "s", "", "Host name of the target") - UpdateCmd.Flags().StringVarP(&enable, "enable", "b", - "", "Enabling/disabling a TargetServer") + UpdateCmd.Flags().BoolVarP(&enable, "enable", "b", + true, "Enabling/disabling a TargetServer") UpdateCmd.Flags().BoolVarP(&grpc, "grpc", "g", false, "Enable target server for gRPC") @@ -67,6 +62,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().StringVarP(&trustStore, "trustStore", "", + "", "Trust store for the target server; must be used with sslinfo") UpdateCmd.Flags().StringVarP(&sslinfo, "sslinfo", "", "", "Enable SSL Info on the target server") UpdateCmd.Flags().BoolVarP(&tlsenabled, "tls", "", diff --git a/internal/client/targetservers/targetservers.go b/internal/client/targetservers/targetservers.go index abf4a89e4..96fa13d1b 100644 --- a/internal/client/targetservers/targetservers.go +++ b/internal/client/targetservers/targetservers.go @@ -24,7 +24,6 @@ import ( "net/url" "os" "path" - "strconv" "strings" "sync" @@ -44,15 +43,15 @@ type targetserver struct { } type sslInfo struct { - 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"` - Protocols []string `json:"protocols,omitempty"` - Ciphers []string `json:"ciphers,omitempty"` - CommonName commonName `json:"commonName,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"` + Protocols []string `json:"protocols,omitempty"` + Ciphers []string `json:"ciphers,omitempty"` + CommonName *commonName `json:"commonName,omitempty"` } type commonName struct { @@ -61,16 +60,16 @@ type commonName struct { } // Create -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) { +func Create(name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, trustStore string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { targetsvr := targetserver{ Name: name, } - return createOrUpdate("create", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) + return createOrUpdate("create", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, trustStore, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) } // Update -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) { +func Update(name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, trustStore string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { apiclient.SetPrintOutput(false) targetRespBody, err := Get(name) if err != nil { @@ -82,13 +81,13 @@ func Update(name string, description string, host string, port int, enable strin if err = json.Unmarshal(targetRespBody, &targetsvr); err != nil { return nil, err } - return createOrUpdate("update", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) + return createOrUpdate("update", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, trustStore, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors) } -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) { +func createOrUpdate(action string, targetsvr targetserver, name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, trustStore string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { targetsvr.Description = description targetsvr.Host = host - targetsvr.IsEnabled, _ = strconv.ParseBool(enable) + targetsvr.IsEnabled = enable if port != -1 { targetsvr.Port = port @@ -96,13 +95,14 @@ func createOrUpdate(action string, targetsvr targetserver, name string, descript if grpc { targetsvr.Protocol = "GRPC" } - if strings.ToLower(sslinfo) == "true" { + if strings.ToLower(sslinfo) == "true" || tlsenabled { targetsvr.SslInfo = &sslInfo{ Enabled: tlsenabled, ClientAuthEnabled: clientAuthEnabled, IgnoreValidationErrors: ignoreValidationErrors, Keyalias: keyAlias, Keystore: keyStore, + Truststore: trustStore, } }