Explorar el Código

feat: potentially added support for set secrets for AWS

Signed-off-by: Nick Ruffles <nick.ruffles@engineerbetter.com>
Co-authored-by: Marcus Dantas <marcus.dantas@engineerbetter.com>
Nick Ruffles hace 3 años
padre
commit
0e842171d0

+ 5 - 1
pkg/provider/aws/parameterstore/fake/fake.go

@@ -3,7 +3,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 You may obtain a copy of the License at
 
 
-    http://www.apache.org/licenses/LICENSE-2.0
+	http://www.apache.org/licenses/LICENSE-2.0
 
 
 Unless required by applicable law or agreed to in writing, software
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 distributed under the License is distributed on an "AS IS" BASIS,
@@ -33,6 +33,10 @@ func (sm *Client) DescribeParameters(*ssm.DescribeParametersInput) (*ssm.Describ
 	return nil, nil
 	return nil, nil
 }
 }
 
 
+func (sm *Client) PutParameter(*ssm.PutParameterInput) (*ssm.PutParameterOutput, error) {
+	return nil, nil
+}
+
 func (sm *Client) WithValue(in *ssm.GetParameterInput, val *ssm.GetParameterOutput, err error) {
 func (sm *Client) WithValue(in *ssm.GetParameterInput, val *ssm.GetParameterOutput, err error) {
 	sm.valFn = func(paramIn *ssm.GetParameterInput) (*ssm.GetParameterOutput, error) {
 	sm.valFn = func(paramIn *ssm.GetParameterInput) (*ssm.GetParameterOutput, error) {
 		if !cmp.Equal(paramIn, in) {
 		if !cmp.Equal(paramIn, in) {

+ 27 - 1
pkg/provider/aws/parameterstore/parameterstore_test.go

@@ -3,7 +3,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 You may obtain a copy of the License at
 
 
-    http://www.apache.org/licenses/LICENSE-2.0
+	http://www.apache.org/licenses/LICENSE-2.0
 
 
 Unless required by applicable law or agreed to in writing, software
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 distributed under the License is distributed on an "AS IS" BASIS,
@@ -36,6 +36,7 @@ type parameterstoreTestCase struct {
 	expectError    string
 	expectError    string
 	expectedSecret string
 	expectedSecret string
 	expectedData   map[string]string
 	expectedData   map[string]string
+	setApiInput    *ssm.PutParameterInput
 }
 }
 
 
 func makeValidParameterStoreTestCase() *parameterstoreTestCase {
 func makeValidParameterStoreTestCase() *parameterstoreTestCase {
@@ -81,6 +82,31 @@ func makeValidParameterStoreTestCaseCustom(tweaks ...func(pstc *parameterstoreTe
 	return pstc
 	return pstc
 }
 }
 
 
+func TestSetSecret(t *testing.T) {
+	pm := makeValidParameterStoreTestCase()
+
+	setSimpleSecret := func(pstc *parameterstoreTestCase) {
+		pm.setApiInput.SetName("nameHere")
+		pm.setApiInput.SetValue("valueHere")
+	}
+
+	successCases := []*parameterstoreTestCase{
+		makeValidParameterStoreTestCaseCustom(setSimpleSecret),
+	}
+
+	ps := ParameterStore{}
+	for k, v := range successCases {
+		ps.client = v.fakeClient
+		out, err := ps.GetSecretMap(context.Background(), *v.remoteRef)
+		if !ErrorContains(err, v.expectError) {
+			t.Errorf("[%d] unexpected error: %s, expected: '%s'", k, err.Error(), v.expectError)
+		}
+		if cmp.Equal(out, v.expectedData) {
+			t.Errorf("[%d] unexpected secret data: expected %#v, got %#v", k, v.expectedData, out)
+		}
+	}
+}
+
 // test the ssm<->aws interface
 // test the ssm<->aws interface
 // make sure correct values are passed and errors are handled accordingly.
 // make sure correct values are passed and errors are handled accordingly.
 func TestGetSecret(t *testing.T) {
 func TestGetSecret(t *testing.T) {