2021-09-19 12:00:00 +00:00
|
|
|
// Copyright (c) 2019, Drone IO Inc.
|
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Secret is a resource that provides encrypted data
|
|
|
|
// and pointers to external data (i.e. from vault).
|
|
|
|
Secret struct {
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Kind string `json:"kind,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
2019-02-22 03:08:33 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
2019-01-22 23:44:17 +00:00
|
|
|
|
2019-03-18 02:25:35 +00:00
|
|
|
Data string `json:"data,omitempty"`
|
|
|
|
Get SecretGet `json:"get,omitempty"`
|
2019-02-22 03:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SecretGet defines a request to get a secret from
|
2022-04-25 10:56:05 +00:00
|
|
|
// an external service at the specified path, or with the
|
2019-02-22 03:08:33 +00:00
|
|
|
// specified name.
|
|
|
|
SecretGet struct {
|
|
|
|
Path string `json:"path,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Key string `json:"key,omitempty"`
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExternalData defines the path and name of external
|
|
|
|
// data located in an external or remote storage system.
|
|
|
|
ExternalData struct {
|
|
|
|
Path string `json:"path,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-02-08 09:14:20 +00:00
|
|
|
var ErrInvalidSecret = errors.New("yaml: invalid secret resource")
|
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
// GetVersion returns the resource version.
|
|
|
|
func (s *Secret) GetVersion() string { return s.Version }
|
|
|
|
|
|
|
|
// GetKind returns the resource kind.
|
|
|
|
func (s *Secret) GetKind() string { return s.Kind }
|
|
|
|
|
|
|
|
// Validate returns an error if the secret is invalid.
|
|
|
|
func (s *Secret) Validate() error {
|
2019-03-18 02:25:35 +00:00
|
|
|
if len(s.Data) == 0 && len(s.Get.Path) == 0 && len(s.Get.Name) == 0 {
|
2023-02-08 09:14:20 +00:00
|
|
|
return ErrInvalidSecret
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
return nil
|
|
|
|
}
|