-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add optional capability to seed service secrets #276
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
903b8e3
feat: Add optional capability to seed service secrets
7df6da5
fix: Addressed PR feeback
59902fa
build: Updated go.mo for go-mod-secrets
366f197
docs: Addressed PR review from Tony
63a0ae1
fix: update go.mod
b4238be
fix: ran GoFmt
49d0fff
feat: Add DisableScrubSecretsFile setting to control srubbing of secr…
69f7a6c
fix: Address PR feed back on parameter passing
9366fe9
refactor: refactoring per PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Intel Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*******************************************************************************/ | ||
|
||
package secret | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
validation "github.com/edgexfoundry/go-mod-core-contracts/v2/common" | ||
"github.com/edgexfoundry/go-mod-core-contracts/v2/dtos/common" | ||
"github.com/hashicorp/go-multierror" | ||
) | ||
|
||
// ServiceSecrets contains the list of secrets to import into a service's SecretStore | ||
type ServiceSecrets struct { | ||
Secrets []ServiceSecret `json:"secrets" validate:"required,gt=0,dive"` | ||
} | ||
|
||
// ServiceSecret contains the information about a service's secret to import into a service's SecretStore | ||
type ServiceSecret struct { | ||
Path string `json:"path" validate:"edgex-dto-none-empty-string"` | ||
Imported bool `json:"imported"` | ||
SecretData []common.SecretDataKeyValue `json:"secretData" validate:"required,dive"` | ||
} | ||
|
||
// MarshalJson marshal the service's secrets to JSON. | ||
func (s *ServiceSecrets) MarshalJson() ([]byte, error) { | ||
return json.Marshal(s) | ||
} | ||
|
||
// UnmarshalServiceSecretsJson un-marshals the JSON containing the services list of secrets | ||
func UnmarshalServiceSecretsJson(data []byte) (*ServiceSecrets, error) { | ||
secrets := &ServiceSecrets{} | ||
|
||
if err := json.Unmarshal(data, secrets); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := validation.Validate(secrets); err != nil { | ||
return nil, err | ||
} | ||
|
||
var validationErrs error | ||
|
||
// Since secretData len validation can't be specified to only validate when Imported=false, we have to do it manually here | ||
for _, secret := range secrets.Secrets { | ||
if !secret.Imported && len(secret.SecretData) == 0 { | ||
validationErrs = multierror.Append(validationErrs, fmt.Errorf("SecretData for '%s' must not be empty when Imported=false", secret.Path)) | ||
} | ||
} | ||
|
||
if validationErrs != nil { | ||
return nil, validationErrs | ||
} | ||
|
||
return secrets, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code would be less complex if this was changed to if len == 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? still an if/else just reversing the logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am always an advocate of early return to avoid indentation, just didn't see it here. THX!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opps, not so fast. This skips the following important code when you do the
break
that you added, so still need the if/else of have repeated code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, was able to move that code up before handling of the secrets file and now the break you added will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated