From d777fc23c26ab9d3347bdfe060e036a8ea1dab38 Mon Sep 17 00:00:00 2001 From: max furman Date: Thu, 28 Oct 2021 23:58:18 -0700 Subject: [PATCH] Add ca.WithInsecure and use methods for file names --- ca/client.go | 13 ++++++++++++- ca/identity/identity.go | 4 ++-- pki/pki.go | 7 ++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ca/client.go b/ca/client.go index aa1e38dd..9bcf1eb4 100644 --- a/ca/client.go +++ b/ca/client.go @@ -226,7 +226,7 @@ func (o *clientOptions) getTransport(endpoint string) (tr http.RoundTripper, err return tr, nil } -// WithTransport adds a custom transport to the Client. It will fail if a +// WithTransport adds a custom transport to the Client. It will fail if a // previous option to create the transport has been configured. func WithTransport(tr http.RoundTripper) ClientOption { return func(o *clientOptions) error { @@ -238,6 +238,17 @@ func WithTransport(tr http.RoundTripper) ClientOption { } } +// WithInsecure adds a insecure transport that bypasses TLS verification. +func WithInsecure() ClientOption { + return func(o *clientOptions) error { + o.transport = &http.Transport{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + return nil + } +} + // WithRootFile will create the transport using the given root certificate. It // will fail if a previous option to create the transport has been configured. func WithRootFile(filename string) ClientOption { diff --git a/ca/identity/identity.go b/ca/identity/identity.go index e8760c50..c294d982 100644 --- a/ca/identity/identity.go +++ b/ca/identity/identity.go @@ -72,11 +72,11 @@ func LoadDefaultIdentity() (*Identity, error) { } func profileConfigDir() string { - return filepath.Join(step.ProfilePath(), "config") + return filepath.Join(step.Path(), "config") } func profileIdentityDir() string { - return filepath.Join(step.ProfilePath(), "identity") + return filepath.Join(step.Path(), "identity") } // WriteDefaultIdentity writes the given certificates and key and the diff --git a/pki/pki.go b/pki/pki.go index 8bc07dae..ae6b712c 100644 --- a/pki/pki.go +++ b/pki/pki.go @@ -376,15 +376,12 @@ func New(o apiv1.Options, opts ...Option) (*PKI, error) { } // Create profile directory and stub for default profile configuration. - if currentCtx := step.GetCurrentContext(); currentCtx != nil { + if currentCtx := step.Contexts().GetCurrent(); currentCtx != nil { profile := GetProfileConfigPath() if err := os.MkdirAll(profile, 0700); err != nil { return nil, errs.FileError(err, profile) } - if p.profileDefaults, err = getPath(profile, "defaults.json"); err != nil { - return nil, err - } - if err := ioutil.WriteFile(p.profileDefaults, + if err := ioutil.WriteFile(step.ProfileDefaultsFile(), []byte("{}"), 0600); err != nil { return nil, err }