Skip to content

Commit

Permalink
refactor!: Consume Secret DTO changes (#1311)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: secret DTO object in core contracts uses SecretName instead of Path

Signed-off-by: Marc-Philippe Fuller <marc-philippe.fuller@intel.com>
  • Loading branch information
marcpfuller authored Feb 22, 2023
1 parent ba1091b commit de29a59
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace github.com/edgexfoundry/app-functions-sdk-go/v3 => ../

require (
github.com/edgexfoundry/app-functions-sdk-go/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15
github.com/google/uuid v1.3.0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions app-service-template/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24 h1:H9MC0ahbkMw4w1SHeX6
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14 h1:o7CFEIyKn/quin5lrAlUbUu9x1dnecK0tZs5waLhdCc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15 h1:0fPmT+Jm2scrs9iQLX9dNTAaCPXn6fiTCwiYhcTc0fc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/diegoholiveira/jsonlogic/v3 v3.2.7
github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3
github.com/fxamacker/cbor/v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24 h1:H9MC0ahbkMw4w1SHeX6
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14 h1:o7CFEIyKn/quin5lrAlUbUu9x1dnecK0tZs5waLhdCc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15 h1:0fPmT+Jm2scrs9iQLX9dNTAaCPXn6fiTCwiYhcTc0fc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg=
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/rest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *Controller) prepareSecret(request commonDtos.SecretRequest) (string, ma
secretsKV[secret.Key] = secret.Value
}

path := strings.TrimSpace(request.Path)
path := strings.TrimSpace(request.SecretName)

return path, secretsKV
}
32 changes: 13 additions & 19 deletions internal/controller/rest/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ func TestAddSecretRequest(t *testing.T) {
expectedRequestId := "82eb2e26-0f24-48aa-ae4c-de9dac3fb9bc"

mockProvider := &mocks.SecretProvider{}
mockProvider.On("StoreSecret", "/mqtt", map[string]string{"password": "password", "username": "username"}).Return(nil)
mockProvider.On("StoreSecret", "mqtt", map[string]string{"password": "password", "username": "username"}).Return(nil)
mockProvider.On("StoreSecret", "/no", map[string]string{"password": "password", "username": "username"}).Return(errors.New("invalid w/o Vault"))
mockProvider.On("StoreSecret", "no", map[string]string{"password": "password", "username": "username"}).Return(errors.New("invalid w/o Vault"))

dic.Update(di.ServiceConstructorMap{
container.ConfigurationName: func(get di.Get) interface{} {
Expand All @@ -237,17 +236,15 @@ func TestAddSecretRequest(t *testing.T) {

validRequest := commonDtos.SecretRequest{
BaseRequest: commonDtos.BaseRequest{RequestId: expectedRequestId, Versionable: commonDtos.NewVersionable()},
Path: "mqtt",
SecretName: "mqtt",
SecretData: []commonDtos.SecretDataKeyValue{
{Key: "username", Value: "username"},
{Key: "password", Value: "password"},
},
}

NoPath := validRequest
NoPath.Path = ""
validPathWithSlash := validRequest
validPathWithSlash.Path = "/mqtt"
NoName := validRequest
NoName.SecretName = ""
validNoRequestId := validRequest
validNoRequestId.RequestId = ""
badRequestId := validRequest
Expand All @@ -263,27 +260,24 @@ func TestAddSecretRequest(t *testing.T) {
{Key: "username", Value: ""},
}
noSecretStore := validRequest
noSecretStore.Path = "/no"
noSecretStore.SecretName = "no"

tests := []struct {
Name string
Request commonDtos.SecretRequest
ExpectedRequestId string
SecretsPath string
SecretStoreEnabled string
ErrorExpected bool
ExpectedStatusCode int
}{
{"Valid - sub-path no trailing slash, SecretsPath has trailing slash", validRequest, expectedRequestId, "my-secrets/", "true", false, http.StatusCreated},
{"Valid - sub-path only with trailing slash", validPathWithSlash, expectedRequestId, "my-secrets", "true", false, http.StatusCreated},
{"Valid - both trailing slashes", validPathWithSlash, expectedRequestId, "my-secrets/", "true", false, http.StatusCreated},
{"Valid - no requestId", validNoRequestId, "", "", "true", false, http.StatusCreated},
{"Invalid - no path", NoPath, "", "", "true", true, http.StatusBadRequest},
{"Invalid - bad requestId", badRequestId, "", "", "true", true, http.StatusBadRequest},
{"Invalid - no secrets", noSecrets, "", "", "true", true, http.StatusBadRequest},
{"Invalid - missing secret key", missingSecretKey, "", "", "true", true, http.StatusBadRequest},
{"Invalid - missing secret value", missingSecretValue, "", "", "true", true, http.StatusBadRequest},
{"Invalid - No Secret Store", noSecretStore, "", "", "false", true, http.StatusInternalServerError},
{"Valid name", validRequest, expectedRequestId, "true", false, http.StatusCreated},
{"Valid - no requestId", validNoRequestId, "", "true", false, http.StatusCreated},
{"Invalid - no name", NoName, "", "true", true, http.StatusBadRequest},
{"Invalid - bad requestId", badRequestId, "", "true", true, http.StatusBadRequest},
{"Invalid - no secrets", noSecrets, "", "true", true, http.StatusBadRequest},
{"Invalid - missing secret key", missingSecretKey, "", "true", true, http.StatusBadRequest},
{"Invalid - missing secret value", missingSecretValue, "", "true", true, http.StatusBadRequest},
{"Invalid - No Secret Store", noSecretStore, "", "false", true, http.StatusInternalServerError},
}

for _, testCase := range tests {
Expand Down

0 comments on commit de29a59

Please sign in to comment.