From 089882f289149ed964f870fd053027718bc113fd Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 19 Jun 2019 17:01:10 +0100 Subject: [PATCH] chore: refactor vaulturl -> secreturl Signed-off-by: James Strachan --- pkg/apps/values.go | 4 ++-- pkg/helm/helm_helpers.go | 12 ++++++------ pkg/helm/helm_helpers_test.go | 2 +- .../vaulturl_client.go => secreturl/client.go} | 2 +- pkg/{vaulturl => secreturl}/helpers.go | 2 +- pkg/{vaulturl => secreturl}/localvault/client.go | 4 ++-- pkg/vault/helpers_test.go | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) rename pkg/{vaulturl/vaulturl_client.go => secreturl/client.go} (97%) rename pkg/{vaulturl => secreturl}/helpers.go (98%) rename pkg/{vaulturl => secreturl}/localvault/client.go (95%) diff --git a/pkg/apps/values.go b/pkg/apps/values.go index 890dcc7ccd..f0cca26b8f 100644 --- a/pkg/apps/values.go +++ b/pkg/apps/values.go @@ -10,7 +10,7 @@ import ( "path/filepath" "strings" - "github.com/jenkins-x/jx/pkg/vaulturl" + "github.com/jenkins-x/jx/pkg/secreturl" "gopkg.in/AlecAivazis/survey.v1/terminal" "github.com/ghodss/yaml" @@ -188,7 +188,7 @@ func GenerateQuestions(schema []byte, batchMode bool, askExisting bool, basePath secrets = append(secrets, secret) if passthrough { if useVault { - return vaulturl.ToURI(secret.Path, secret.Key), nil + return secreturl.ToURI(secret.Path, secret.Key), nil } return value, nil } diff --git a/pkg/helm/helm_helpers.go b/pkg/helm/helm_helpers.go index f9bcb5cd5a..6c17c4aad9 100644 --- a/pkg/helm/helm_helpers.go +++ b/pkg/helm/helm_helpers.go @@ -22,9 +22,9 @@ import ( "github.com/jenkins-x/jx/pkg/kube" "github.com/jenkins-x/jx/pkg/log" + "github.com/jenkins-x/jx/pkg/secreturl" "github.com/jenkins-x/jx/pkg/table" "github.com/jenkins-x/jx/pkg/util" - "github.com/jenkins-x/jx/pkg/vaulturl" "github.com/jenkins-x/jx/pkg/version" "k8s.io/client-go/kubernetes" @@ -517,7 +517,7 @@ type InstallChartOptions struct { // respecting the installTimeout, looking up or updating Vault with the username and password for the repo. // If vaultClient is nil then username and passwords for repos will not be looked up in Vault. func InstallFromChartOptions(options InstallChartOptions, helmer Helmer, kubeClient kubernetes.Interface, - installTimeout string, vaultClient vaulturl.Client) error { + installTimeout string, vaultClient secreturl.Client) error { chart := options.Chart if options.Version == "" { versionsDir := options.VersionsDir @@ -573,7 +573,7 @@ type HelmRepoCredential struct { // DecorateWithSecrets will replace any vault: URIs with the secret from vault. Safe to call with a nil client ( // no replacement will take place). -func DecorateWithSecrets(options *InstallChartOptions, vaultClient vaulturl.Client) (func(), error) { +func DecorateWithSecrets(options *InstallChartOptions, vaultClient secreturl.Client) (func(), error) { cleanup := func() { } if vaultClient != nil { @@ -595,7 +595,7 @@ func DecorateWithSecrets(options *InstallChartOptions, vaultClient vaulturl.Clie if err != nil { return cleanup, errors.Wrapf(err, "reading file %s", valueFile) } - newValues, err := vaulturl.ReplaceURIs(string(bytes), vaultClient) + newValues, err := secreturl.ReplaceURIs(string(bytes), vaultClient) if err != nil { return cleanup, errors.Wrapf(err, "replacing vault URIs") } @@ -615,7 +615,7 @@ func DecorateWithSecrets(options *InstallChartOptions, vaultClient vaulturl.Clie // The repo name may have a suffix added in order to prevent name collisions, and is returned for this reason. // The username and password will be stored in vault for the URL (if vault is enabled). func AddHelmRepoIfMissing(helmURL, repoName, username, password string, helmer Helmer, - vaultClient vaulturl.Client, in terminal.FileReader, + vaultClient secreturl.Client, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error) { missing, existingName, err := helmer.IsRepoMissing(helmURL) if err != nil { @@ -662,7 +662,7 @@ func AddHelmRepoIfMissing(helmURL, repoName, username, password string, helmer H } // DecorateWithCredentials will, if vault is installed, store or replace the username or password -func DecorateWithCredentials(repo string, username string, password string, vaultClient vaulturl.Client, in terminal.FileReader, +func DecorateWithCredentials(repo string, username string, password string, vaultClient secreturl.Client, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, string, error) { if repo != "" && vaultClient != nil { diff --git a/pkg/helm/helm_helpers_test.go b/pkg/helm/helm_helpers_test.go index 7bbfd03f82..09e6ba9445 100644 --- a/pkg/helm/helm_helpers_test.go +++ b/pkg/helm/helm_helpers_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/jenkins-x/jx/pkg/vaulturl/localvault" + "github.com/jenkins-x/jx/pkg/secreturl/localvault" "github.com/pborman/uuid" "github.com/petergtz/pegomock" "github.com/stretchr/testify/require" diff --git a/pkg/vaulturl/vaulturl_client.go b/pkg/secreturl/client.go similarity index 97% rename from pkg/vaulturl/vaulturl_client.go rename to pkg/secreturl/client.go index 3c8fd03ec8..76c974e4c2 100644 --- a/pkg/vaulturl/vaulturl_client.go +++ b/pkg/secreturl/client.go @@ -1,4 +1,4 @@ -package vaulturl +package secreturl // Client is a simple interface for Vault-like things such as `vault.Client` or a file system we can use to // access secret files and values in helm. diff --git a/pkg/vaulturl/helpers.go b/pkg/secreturl/helpers.go similarity index 98% rename from pkg/vaulturl/helpers.go rename to pkg/secreturl/helpers.go index 23980493c5..fd1f5d9ab9 100644 --- a/pkg/vaulturl/helpers.go +++ b/pkg/secreturl/helpers.go @@ -1,4 +1,4 @@ -package vaulturl +package secreturl import ( "fmt" diff --git a/pkg/vaulturl/localvault/client.go b/pkg/secreturl/localvault/client.go similarity index 95% rename from pkg/vaulturl/localvault/client.go rename to pkg/secreturl/localvault/client.go index 7c3a0b7d2d..c048080780 100644 --- a/pkg/vaulturl/localvault/client.go +++ b/pkg/secreturl/localvault/client.go @@ -6,8 +6,8 @@ import ( "path/filepath" "github.com/jenkins-x/jx/pkg/helm" + "github.com/jenkins-x/jx/pkg/secreturl" "github.com/jenkins-x/jx/pkg/util" - "github.com/jenkins-x/jx/pkg/vaulturl" "github.com/pkg/errors" ) @@ -17,7 +17,7 @@ type FileSystemClient struct { } // NewFileSystemClient create a new local file system based client loading content from the given URL -func NewFileSystemClient(dir string) vaulturl.Client { +func NewFileSystemClient(dir string) secreturl.Client { return &FileSystemClient{ Dir: dir, } diff --git a/pkg/vault/helpers_test.go b/pkg/vault/helpers_test.go index 8adf58beac..13850e2f34 100644 --- a/pkg/vault/helpers_test.go +++ b/pkg/vault/helpers_test.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "testing" - "github.com/jenkins-x/jx/pkg/vaulturl" + "github.com/jenkins-x/jx/pkg/secreturl" "github.com/pborman/uuid" "github.com/stretchr/testify/assert" @@ -35,7 +35,7 @@ func TestReplaceURIs(t *testing.T) { pegomock.When(vaultClient.Read(pegomock.EqString(path))).ThenReturn(map[string]interface{}{ key: secret, }, nil) - result, err := vaulturl.ReplaceURIs(valuesyaml, vaultClient) + result, err := secreturl.ReplaceURIs(valuesyaml, vaultClient) assert.NoError(t, err) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`foo: @@ -63,7 +63,7 @@ func TestReplaceRealExampleURI(t *testing.T) { pegomock.When(vaultClient.Read(pegomock.EqString(path))).ThenReturn(map[string]interface{}{ key: secret, }, nil) - result, err := vaulturl.ReplaceURIs(valuesyaml, vaultClient) + result, err := secreturl.ReplaceURIs(valuesyaml, vaultClient) assert.NoError(t, err) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`foo: