diff --git a/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets.go b/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets.go index 83f65663..3aa5a4d1 100644 --- a/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets.go +++ b/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets.go @@ -58,24 +58,7 @@ func NewProvider( // Provide implements a ProviderFunc to retrieve and push secrets to K8s secrets. func (p k8sProvider) Provide() error { - return ProvideConjurSecretsToK8sSecrets( - p.retrieveK8sSecret, - p.updateK8sSecret, - p.podNamespace, - p.requiredK8sSecrets, - p.retrieveSecretsFunc, - ) -} - -// ProvideConjurSecretsToK8sSecrets is an implementation of Provide that accepts dependencies as arguments. -func ProvideConjurSecretsToK8sSecrets( - retrieveSecretFunc k8s.RetrieveK8sSecretFunc, - updateSecretFunc k8s.UpdateK8sSecretFunc, - namespace string, - requiredK8sSecrets []string, - retrieveSecrets conjur.RetrieveSecretsFunc, -) error { - k8sSecretsMap, err := RetrieveRequiredK8sSecrets(retrieveSecretFunc, namespace, requiredK8sSecrets) + k8sSecretsMap, err := RetrieveRequiredK8sSecrets(p.retrieveK8sSecret, p.podNamespace, p.requiredK8sSecrets) if err != nil { return log.RecordedError(messages.CSPFK021E) @@ -86,7 +69,7 @@ func ProvideConjurSecretsToK8sSecrets( return log.RecordedError(messages.CSPFK037E) } - retrievedConjurSecrets, err := retrieveSecrets(variableIDs) + retrievedConjurSecrets, err := p.retrieveSecretsFunc(variableIDs) if err != nil { return log.RecordedError(messages.CSPFK034E, err.Error()) } @@ -96,7 +79,7 @@ func ProvideConjurSecretsToK8sSecrets( return log.RecordedError(messages.CSPFK027E) } - err = UpdateRequiredK8sSecrets(updateSecretFunc, namespace, k8sSecretsMap) + err = UpdateRequiredK8sSecrets(p.updateK8sSecret, p.podNamespace, k8sSecretsMap) if err != nil { return log.RecordedError(messages.CSPFK023E) diff --git a/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets_test.go b/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets_test.go index 1f6e994e..09d3d4cc 100644 --- a/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets_test.go +++ b/pkg/secrets/k8s_secrets_storage/provide_conjur_secrets_test.go @@ -238,13 +238,13 @@ func TestProvideConjurSecrets(t *testing.T) { kubeMockClient.AddSecret("k8s_secret2", "secret_key2", "conjur_variable2") requiredSecrets := []string{"k8s_secret1"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Finishes without raising an error", func() { So(err, ShouldEqual, nil) @@ -269,13 +269,13 @@ func TestProvideConjurSecrets(t *testing.T) { kubeMockClient.AddSecret("k8s_secret2", "secret_key2", "conjur_variable2") requiredSecrets := []string{"k8s_secret1", "k8s_secret2"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Finishes without raising an error", func() { So(err, ShouldEqual, nil) @@ -296,13 +296,13 @@ func TestProvideConjurSecrets(t *testing.T) { requiredSecrets := []string{"k8s_secret1", "k8s_secret2"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Finishes without raising an error", func() { So(err, ShouldEqual, nil) @@ -322,13 +322,13 @@ func TestProvideConjurSecrets(t *testing.T) { requiredSecrets := []string{"k8s_secret1"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Raises proper error", func() { So(err.Error(), ShouldEqual, fmt.Sprintf(messages.CSPFK034E, "no_conjur_secret_error")) @@ -342,13 +342,13 @@ func TestProvideConjurSecrets(t *testing.T) { kubeMockClient.AddSecret("k8s_secret_with_empty_conjur_variable", "secret_key", "conjur_variable_empty_secret") requiredSecrets := []string{"k8s_secret_with_empty_conjur_variable"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Finishes without raising an error", func() { So(err, ShouldEqual, nil) @@ -368,13 +368,13 @@ func TestProvideConjurSecrets(t *testing.T) { kubeMockClient.AddSecret("k8s_secret_with_no_permission_conjur_variable", "secret_key", "no_execute_permission_conjur_secret") requiredSecrets := []string{"k8s_secret_with_no_permission_conjur_variable"} - err := ProvideConjurSecretsToK8sSecrets( - kubeMockClient.RetrieveSecret, - kubeMockClient.UpdateSecret, - "someNameSpace", - requiredSecrets, - conjurMockClient.RetrieveSecrets, - ) + err := k8sProvider{ + retrieveK8sSecret: kubeMockClient.RetrieveSecret, + updateK8sSecret: kubeMockClient.UpdateSecret, + retrieveSecretsFunc: conjurMockClient.RetrieveSecrets, + podNamespace: "someNamespace", + requiredK8sSecrets: requiredSecrets, + }.Provide() Convey("Raises proper error", func() { So(err.Error(), ShouldEqual, fmt.Sprintf(messages.CSPFK034E, "custom error"))