Skip to content

Commit

Permalink
Fix CodeClimate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
john-odonnell committed Oct 27, 2021
1 parent f1818dc commit bc9fffa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 62 deletions.
23 changes: 3 additions & 20 deletions pkg/secrets/k8s_secrets_storage/provide_conjur_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
}
Expand All @@ -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)
Expand Down
84 changes: 42 additions & 42 deletions pkg/secrets/k8s_secrets_storage/provide_conjur_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"))
Expand All @@ -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)
Expand All @@ -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"))
Expand Down

0 comments on commit bc9fffa

Please sign in to comment.