2020-08-18 11:38:23 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-08-18 11:38:23 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
package secrets
|
2020-04-29 20:36:00 +02:00
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2020-04-29 20:36:00 +02:00
|
|
|
)
|
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
// Service interacts with the underlying secrets backend
|
|
|
|
type Service interface {
|
|
|
|
CreateSecret(ctx context.Context, secret Secret) (string, error)
|
|
|
|
InspectSecret(ctx context.Context, id string) (Secret, error)
|
|
|
|
ListSecrets(ctx context.Context) ([]Secret, error)
|
|
|
|
DeleteSecret(ctx context.Context, id string, recover bool) error
|
2020-06-11 19:22:12 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
// Secret hold sensitive data
|
2020-04-29 20:36:00 +02:00
|
|
|
type Secret struct {
|
2020-10-08 10:29:45 +02:00
|
|
|
ID string `json:"ID"`
|
|
|
|
Name string `json:"Name"`
|
|
|
|
Labels map[string]string `json:"Tags"`
|
|
|
|
content []byte
|
2020-05-05 18:55:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
// NewSecret builds a secret
|
2020-10-08 10:29:45 +02:00
|
|
|
func NewSecret(name string, content []byte) Secret {
|
2020-05-05 18:55:03 +02:00
|
|
|
return Secret{
|
2020-10-08 10:29:45 +02:00
|
|
|
Name: name,
|
|
|
|
content: content,
|
2020-05-05 18:55:03 +02:00
|
|
|
}
|
2020-04-29 20:36:00 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
// ToJSON marshall a Secret into JSON string
|
2020-04-29 20:36:00 +02:00
|
|
|
func (s Secret) ToJSON() (string, error) {
|
|
|
|
b, err := json.MarshalIndent(&s, "", "\t")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(b), nil
|
|
|
|
}
|
2020-05-05 18:55:03 +02:00
|
|
|
|
2020-10-08 10:29:45 +02:00
|
|
|
// GetContent returns a Secret's sensitive data
|
|
|
|
func (s Secret) GetContent() []byte {
|
|
|
|
return s.content
|
2020-05-05 18:55:03 +02:00
|
|
|
}
|