Skip to content

Commit

Permalink
add --insecure option
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed May 11, 2020
1 parent 8bcaf05 commit ff78568
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
15 changes: 11 additions & 4 deletions apigee/edge_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package apigee

import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -148,7 +149,6 @@ func addOptions(s string, opt interface{}) (string, error) {

// EdgeClientOptions sets options for accessing edge APIs
type EdgeClientOptions struct {
httpClient *http.Client

// MgmtURL is the Admin base URL. Optional. For example, if using OPDK this might be
// http://192.168.10.56:8080. It defaults to https://api.enterprise.apigee.com.
Expand All @@ -168,6 +168,9 @@ type EdgeClientOptions struct {

// Optional. For hybrid and NG must be true.
GCPManaged bool

// Optional. Skip cert verification.
InsecureSkipVerify bool
}

// EdgeAuth holds information about how to authenticate to the Edge Management server.
Expand Down Expand Up @@ -219,10 +222,14 @@ func retrieveAuthFromNetrc(netrcPath, host string) (*EdgeAuth, error) {

// NewEdgeClient returns a new EdgeClient.
func NewEdgeClient(o *EdgeClientOptions) (*EdgeClient, error) {
httpClient := o.httpClient
if o.httpClient == nil {
httpClient = http.DefaultClient
httpClient := http.DefaultClient

if o.InsecureSkipVerify {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
httpClient = &http.Client{Transport: tr}
}

mgmtURL := o.MgmtURL
if o.MgmtURL == "" {
mgmtURL = defaultBaseURL
Expand Down
33 changes: 19 additions & 14 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,22 @@ var BuildInfo BuildInfoType

// RootArgs is the base struct to hold all command arguments
type RootArgs struct {
RuntimeBase string // "https://org-env.apigee.net"
ManagementBase string // "https://api.enterprise.apigee.com"
Verbose bool
Org string
Env string
Username string
Password string
Token string
NetrcPath string
IsOPDK bool
IsLegacySaaS bool
IsGCPManaged bool
ConfigPath string
ServerConfig *server.Config // config loaded from ConfigPath
RuntimeBase string // "https://org-env.apigee.net"
ManagementBase string // "https://api.enterprise.apigee.com"
Verbose bool
Org string
Env string
Username string
Password string
Token string
NetrcPath string
IsOPDK bool
IsLegacySaaS bool
IsGCPManaged bool
ConfigPath string
InsecureSkipVerify bool

ServerConfig *server.Config // config loaded from ConfigPath

// the following is derived in Resolve()
InternalProxyURL string
Expand All @@ -98,6 +100,9 @@ func AddCommandWithFlags(c *cobra.Command, rootArgs *RootArgs, cmds ...*cobra.Co
subC.PersistentFlags().StringVarP(&rootArgs.ConfigPath, "config", "c",
"", "Path to Apigee Remote Service config file")

subC.PersistentFlags().BoolVarP(&rootArgs.InsecureSkipVerify, "insecure", "",
false, "Allow insecure server connections when using SSL")

c.AddCommand(subC)
}
}
Expand Down

0 comments on commit ff78568

Please sign in to comment.