mirror of
https://github.com/containers/podman.git
synced 2025-12-02 11:08:36 +08:00
Use new secret store API
Refactored secrets API in common for stability purposes. Move podman to said API. [NO NEW TESTS NEEDED] Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
committed by
Paul Holzinger
parent
cd32b929e3
commit
72e715a110
33
vendor/github.com/containers/common/pkg/secrets/secrets.go
generated
vendored
33
vendor/github.com/containers/common/pkg/secrets/secrets.go
generated
vendored
@@ -72,13 +72,15 @@ type Secret struct {
|
||||
Name string `json:"name"`
|
||||
// ID is the unique secret ID
|
||||
ID string `json:"id"`
|
||||
// Labels are labels on the secret
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
// Metadata stores other metadata on the secret
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
// CreatedAt is when the secret was created
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
// Driver is the driver used to store secret data
|
||||
Driver string `json:"driver"`
|
||||
// DriverOptions is other metadata needed to use the driver
|
||||
// DriverOptions are extra options used to run this driver
|
||||
DriverOptions map[string]string `json:"driverOptions"`
|
||||
}
|
||||
|
||||
@@ -100,6 +102,16 @@ type SecretsDriver interface {
|
||||
Delete(id string) error
|
||||
}
|
||||
|
||||
// StoreOptions are optional metadata fields that can be set when storing a new secret
|
||||
type StoreOptions struct {
|
||||
// DriverOptions are extra options used to run this driver
|
||||
DriverOpts map[string]string
|
||||
// Metadata stores extra metadata on the secret
|
||||
Metadata map[string]string
|
||||
// Labels are labels on the secret
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
// NewManager creates a new secrets manager
|
||||
// rootPath is the directory where the secrets data file resides
|
||||
func NewManager(rootPath string) (*SecretsManager, error) {
|
||||
@@ -129,7 +141,7 @@ func NewManager(rootPath string) (*SecretsManager, error) {
|
||||
// Store takes a name, creates a secret and stores the secret metadata and the secret payload.
|
||||
// It returns a generated ID that is associated with the secret.
|
||||
// The max size for secret data is 512kB.
|
||||
func (s *SecretsManager) Store(name string, data []byte, driverType string, driverOpts map[string]string, metadata map[string]string) (string, error) {
|
||||
func (s *SecretsManager) Store(name string, data []byte, driverType string, options StoreOptions) (string, error) {
|
||||
err := validateSecretName(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -168,16 +180,23 @@ func (s *SecretsManager) Store(name string, data []byte, driverType string, driv
|
||||
}
|
||||
}
|
||||
|
||||
if metadata == nil {
|
||||
metadata = make(map[string]string)
|
||||
if options.Metadata == nil {
|
||||
options.Metadata = make(map[string]string)
|
||||
}
|
||||
if options.Labels == nil {
|
||||
options.Labels = make(map[string]string)
|
||||
}
|
||||
if options.DriverOpts == nil {
|
||||
options.DriverOpts = make(map[string]string)
|
||||
}
|
||||
|
||||
secr.Driver = driverType
|
||||
secr.Metadata = metadata
|
||||
secr.Metadata = options.Metadata
|
||||
secr.CreatedAt = time.Now()
|
||||
secr.DriverOptions = driverOpts
|
||||
secr.DriverOptions = options.DriverOpts
|
||||
secr.Labels = options.Labels
|
||||
|
||||
driver, err := getDriver(driverType, driverOpts)
|
||||
driver, err := getDriver(driverType, options.DriverOpts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user