Refactor secrets

- create secrets from files
  - update Secret structure

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2020-10-08 10:29:45 +02:00
parent f5f87e342a
commit 8f31ad59be
4 changed files with 66 additions and 68 deletions

View file

@ -31,21 +31,17 @@ type Service interface {
// Secret hold sensitive data
type Secret struct {
ID string `json:"ID"`
Name string `json:"Name"`
Labels map[string]string `json:"Labels"`
Description string `json:"Description"`
username string
password string
ID string `json:"ID"`
Name string `json:"Name"`
Labels map[string]string `json:"Tags"`
content []byte
}
// NewSecret builds a secret
func NewSecret(name, username, password, description string) Secret {
func NewSecret(name string, content []byte) Secret {
return Secret{
Name: name,
username: username,
password: password,
Description: description,
Name: name,
content: content,
}
}
@ -58,15 +54,7 @@ func (s Secret) ToJSON() (string, error) {
return string(b), nil
}
// GetCredString marshall a Secret's sensitive data into JSON string
func (s Secret) GetCredString() (string, error) {
creds := map[string]string{
"username": s.username,
"password": s.password,
}
b, err := json.Marshal(&creds)
if err != nil {
return "", err
}
return string(b), nil
// GetContent returns a Secret's sensitive data
func (s Secret) GetContent() []byte {
return s.content
}