这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cmd/targetservers/crtts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -58,15 +58,17 @@ 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")

CreateCmd.Flags().StringVarP(&keyStore, "keyStore", "",
"", "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", "",
Expand Down
13 changes: 5 additions & 8 deletions cmd/targetservers/updatets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand All @@ -58,15 +53,17 @@ 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")

UpdateCmd.Flags().StringVarP(&keyStore, "keyStore", "",
"", "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", "",
Expand Down
34 changes: 17 additions & 17 deletions internal/client/targetservers/targetservers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"net/url"
"os"
"path"
"strconv"
"strings"
"sync"

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -82,27 +81,28 @@ 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
}
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,
}
}

Expand Down