Skip to content

Commit

Permalink
Merge pull request #30 from apigee/issue29
Browse files Browse the repository at this point in the history
allow disabling ts #29
  • Loading branch information
srinandan authored Jul 29, 2022
2 parents a205b5f + d7e4d42 commit 9d7204b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
2 changes: 1 addition & 1 deletion apiclient/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
50 changes: 24 additions & 26 deletions client/targetservers/targetservers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"os"
"path"
"strconv"
"sync"

"github.com/apigee/apigeecli/apiclient"
Expand All @@ -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"`
Expand All @@ -54,15 +55,15 @@ 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

return createOrUpdate("create", targetsvr, name, description, host, port, enable, grpc, keyStore, keyAlias, sslinfo, tlsenabled, clientAuthEnabled, ignoreValidationErrors)
}

//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{}
Expand All @@ -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)
Expand All @@ -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
}

Expand Down
20 changes: 14 additions & 6 deletions cmd/targetservers/crtts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package targetservers

import (
"fmt"
"strconv"

"github.com/apigee/apigeecli/apiclient"
"github.com/apigee/apigeecli/client/targetservers"
"github.com/spf13/cobra"
Expand All @@ -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) {
Expand All @@ -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() {
Expand All @@ -48,17 +56,17 @@ 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")

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().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",
Expand Down
21 changes: 17 additions & 4 deletions cmd/targetservers/updatets.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package targetservers

import (
"fmt"
"strconv"

"github.com/apigee/apigeecli/apiclient"
"github.com/apigee/apigeecli/client/targetservers"
"github.com/spf13/cobra"
Expand All @@ -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) {
Expand All @@ -43,17 +56,17 @@ 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")

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().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",
Expand Down

0 comments on commit 9d7204b

Please sign in to comment.