mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
Refactor secrets
- create secrets from files - update Secret structure Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
f5f87e342a
commit
8f31ad59be
4 changed files with 66 additions and 68 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue