-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use helm's merging of vaulefiles and files
- Loading branch information
Ole Markus With
committed
Dec 16, 2020
1 parent
b6a07c1
commit 24c9d03
Showing
31 changed files
with
1,721 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"cfg.go", | ||
"tls.go", | ||
], | ||
importmap = "k8s.io/kops/vendor/helm.sh/helm/v3/internal/tlsutil", | ||
importpath = "helm.sh/helm/v3/internal/tlsutil", | ||
visibility = ["//vendor/helm.sh/helm/v3:__subpackages__"], | ||
deps = ["//vendor/github.com/pkg/errors:go_default_library"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright The Helm Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tlsutil | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// Options represents configurable options used to create client and server TLS configurations. | ||
type Options struct { | ||
CaCertFile string | ||
// If either the KeyFile or CertFile is empty, ClientConfig() will not load them. | ||
KeyFile string | ||
CertFile string | ||
// Client-only options | ||
InsecureSkipVerify bool | ||
} | ||
|
||
// ClientConfig returns a TLS configuration for use by a Helm client. | ||
func ClientConfig(opts Options) (cfg *tls.Config, err error) { | ||
var cert *tls.Certificate | ||
var pool *x509.CertPool | ||
|
||
if opts.CertFile != "" || opts.KeyFile != "" { | ||
if cert, err = CertFromFilePair(opts.CertFile, opts.KeyFile); err != nil { | ||
if os.IsNotExist(err) { | ||
return nil, errors.Wrapf(err, "could not load x509 key pair (cert: %q, key: %q)", opts.CertFile, opts.KeyFile) | ||
} | ||
return nil, errors.Wrapf(err, "could not read x509 key pair (cert: %q, key: %q)", opts.CertFile, opts.KeyFile) | ||
} | ||
} | ||
if !opts.InsecureSkipVerify && opts.CaCertFile != "" { | ||
if pool, err = CertPoolFromFile(opts.CaCertFile); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
cfg = &tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify, Certificates: []tls.Certificate{*cert}, RootCAs: pool} | ||
return cfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright The Helm Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tlsutil | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"io/ioutil" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// NewClientTLS returns tls.Config appropriate for client auth. | ||
func NewClientTLS(certFile, keyFile, caFile string) (*tls.Config, error) { | ||
config := tls.Config{} | ||
|
||
if certFile != "" && keyFile != "" { | ||
cert, err := CertFromFilePair(certFile, keyFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.Certificates = []tls.Certificate{*cert} | ||
} | ||
|
||
if caFile != "" { | ||
cp, err := CertPoolFromFile(caFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
config.RootCAs = cp | ||
} | ||
|
||
return &config, nil | ||
} | ||
|
||
// CertPoolFromFile returns an x509.CertPool containing the certificates | ||
// in the given PEM-encoded file. | ||
// Returns an error if the file could not be read, a certificate could not | ||
// be parsed, or if the file does not contain any certificates | ||
func CertPoolFromFile(filename string) (*x509.CertPool, error) { | ||
b, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, errors.Errorf("can't read CA file: %v", filename) | ||
} | ||
cp := x509.NewCertPool() | ||
if !cp.AppendCertsFromPEM(b) { | ||
return nil, errors.Errorf("failed to append certificates from file: %s", filename) | ||
} | ||
return cp, nil | ||
} | ||
|
||
// CertFromFilePair returns an tls.Certificate containing the | ||
// certificates public/private key pair from a pair of given PEM-encoded files. | ||
// Returns an error if the file could not be read, a certificate could not | ||
// be parsed, or if the file does not contain any certificates | ||
func CertFromFilePair(certFile, keyFile string) (*tls.Certificate, error) { | ||
cert, err := tls.LoadX509KeyPair(certFile, keyFile) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "can't load key pair from cert %s and key %s", certFile, keyFile) | ||
} | ||
return &cert, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["urlutil.go"], | ||
importmap = "k8s.io/kops/vendor/helm.sh/helm/v3/internal/urlutil", | ||
importpath = "helm.sh/helm/v3/internal/urlutil", | ||
visibility = ["//vendor/helm.sh/helm/v3:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright The Helm Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package urlutil | ||
|
||
import ( | ||
"net/url" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
// URLJoin joins a base URL to one or more path components. | ||
// | ||
// It's like filepath.Join for URLs. If the baseURL is pathish, this will still | ||
// perform a join. | ||
// | ||
// If the URL is unparsable, this returns an error. | ||
func URLJoin(baseURL string, paths ...string) (string, error) { | ||
u, err := url.Parse(baseURL) | ||
if err != nil { | ||
return "", err | ||
} | ||
// We want path instead of filepath because path always uses /. | ||
all := []string{u.Path} | ||
all = append(all, paths...) | ||
u.Path = path.Join(all...) | ||
return u.String(), nil | ||
} | ||
|
||
// Equal normalizes two URLs and then compares for equality. | ||
func Equal(a, b string) bool { | ||
au, err := url.Parse(a) | ||
if err != nil { | ||
a = filepath.Clean(a) | ||
b = filepath.Clean(b) | ||
// If urls are paths, return true only if they are an exact match | ||
return a == b | ||
} | ||
bu, err := url.Parse(b) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
for _, u := range []*url.URL{au, bu} { | ||
if u.Path == "" { | ||
u.Path = "/" | ||
} | ||
u.Path = filepath.Clean(u.Path) | ||
} | ||
return au.String() == bu.String() | ||
} | ||
|
||
// ExtractHostname returns hostname from URL | ||
func ExtractHostname(addr string) (string, error) { | ||
u, err := url.Parse(addr) | ||
if err != nil { | ||
return "", err | ||
} | ||
return u.Hostname(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["version.go"], | ||
importmap = "k8s.io/kops/vendor/helm.sh/helm/v3/internal/version", | ||
importpath = "helm.sh/helm/v3/internal/version", | ||
visibility = ["//vendor/helm.sh/helm/v3:__subpackages__"], | ||
) |
Oops, something went wrong.