mirror of https://github.com/docker/cli.git
Add secret.name and config.name in compose.
Signed-off-by: Ilya Sotkov <ilya@sotkov.com>
This commit is contained in:
parent
2d0e2d22ca
commit
4f7f3d2f61
|
@ -101,6 +101,12 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if secret.Name != "" {
|
||||||
|
name = secret.Name
|
||||||
|
} else {
|
||||||
|
name = namespace.Scope(name)
|
||||||
|
}
|
||||||
|
|
||||||
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret))
|
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -118,6 +124,12 @@ func Configs(namespace Namespace, configs map[string]composetypes.ConfigObjConfi
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Name != "" {
|
||||||
|
name = config.Name
|
||||||
|
} else {
|
||||||
|
name = namespace.Scope(name)
|
||||||
|
}
|
||||||
|
|
||||||
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(config))
|
obj, err := fileObjectConfig(namespace, name, composetypes.FileObjectConfig(config))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -140,7 +152,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
|
||||||
|
|
||||||
return swarmFileObject{
|
return swarmFileObject{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: namespace.Scope(name),
|
Name: name,
|
||||||
Labels: AddStackLabel(namespace, obj.Labels),
|
Labels: AddStackLabel(namespace, obj.Labels),
|
||||||
},
|
},
|
||||||
Data: data,
|
Data: data,
|
||||||
|
|
|
@ -258,14 +258,14 @@ func convertServiceSecrets(
|
||||||
refs := []*swarm.SecretReference{}
|
refs := []*swarm.SecretReference{}
|
||||||
|
|
||||||
lookup := func(key string) (composetypes.FileObjectConfig, error) {
|
lookup := func(key string) (composetypes.FileObjectConfig, error) {
|
||||||
configSpec, exists := secretSpecs[key]
|
secretSpec, exists := secretSpecs[key]
|
||||||
if !exists {
|
if !exists {
|
||||||
return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key)
|
return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key)
|
||||||
}
|
}
|
||||||
return composetypes.FileObjectConfig(configSpec), nil
|
return composetypes.FileObjectConfig(secretSpec), nil
|
||||||
}
|
}
|
||||||
for _, config := range secrets {
|
for _, secret := range secrets {
|
||||||
obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(config), lookup)
|
obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(secret), lookup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -353,8 +353,8 @@ func convertFileObject(
|
||||||
}
|
}
|
||||||
|
|
||||||
source := namespace.Scope(config.Source)
|
source := namespace.Scope(config.Source)
|
||||||
if obj.External.External {
|
if obj.Name != "" {
|
||||||
source = obj.External.Name
|
source = obj.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
uid := config.UID
|
uid := config.UID
|
||||||
|
|
|
@ -490,7 +490,7 @@ func LoadSecrets(source map[string]interface{}, details types.ConfigDetails) (ma
|
||||||
return secrets, err
|
return secrets, err
|
||||||
}
|
}
|
||||||
for name, secret := range secrets {
|
for name, secret := range secrets {
|
||||||
obj, err := loadFileObjectConfig(name, types.FileObjectConfig(secret), details)
|
obj, err := loadFileObjectConfig(name, "secret", types.FileObjectConfig(secret), details)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ func LoadConfigObjs(source map[string]interface{}, details types.ConfigDetails)
|
||||||
return configs, err
|
return configs, err
|
||||||
}
|
}
|
||||||
for name, config := range configs {
|
for name, config := range configs {
|
||||||
obj, err := loadFileObjectConfig(name, types.FileObjectConfig(config), details)
|
obj, err := loadFileObjectConfig(name, "config", types.FileObjectConfig(config), details)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -516,13 +516,32 @@ func LoadConfigObjs(source map[string]interface{}, details types.ConfigDetails)
|
||||||
return configs, nil
|
return configs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFileObjectConfig(name string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) {
|
func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfig, details types.ConfigDetails) (types.FileObjectConfig, error) {
|
||||||
if obj.External.External && obj.External.Name == "" {
|
// if "external: true"
|
||||||
obj.External.Name = name
|
if obj.External.External {
|
||||||
}
|
// handle deprecated external.name
|
||||||
if obj.File != "" {
|
if obj.External.Name != "" {
|
||||||
|
if obj.Name != "" {
|
||||||
|
return obj, errors.Errorf("%[1]s %[2]s: %[1]s.external.name and %[1]s.name conflict; only use %[1]s.name", objType, name)
|
||||||
|
}
|
||||||
|
if versions.GreaterThanOrEqualTo(details.Version, "3.5") {
|
||||||
|
logrus.Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name)
|
||||||
|
}
|
||||||
|
obj.Name = obj.External.Name
|
||||||
|
obj.External.Name = ""
|
||||||
|
} else {
|
||||||
|
if obj.Name == "" {
|
||||||
|
obj.Name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if not "external: true"
|
||||||
|
} else {
|
||||||
|
if obj.File == "" {
|
||||||
|
return obj, errors.Errorf("%[1]s %[2]s: specify a file or \"external: true\"", objType, name)
|
||||||
|
}
|
||||||
obj.File = absPath(details.WorkingDir, obj.File)
|
obj.File = absPath(details.WorkingDir, obj.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -470,6 +470,7 @@
|
||||||
"id": "#/definitions/secret",
|
"id": "#/definitions/secret",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {"type": "string"},
|
||||||
"file": {"type": "string"},
|
"file": {"type": "string"},
|
||||||
"external": {
|
"external": {
|
||||||
"type": ["boolean", "object"],
|
"type": ["boolean", "object"],
|
||||||
|
@ -486,6 +487,7 @@
|
||||||
"id": "#/definitions/config",
|
"id": "#/definitions/config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {"type": "string"},
|
||||||
"file": {"type": "string"},
|
"file": {"type": "string"},
|
||||||
"external": {
|
"external": {
|
||||||
"type": ["boolean", "object"],
|
"type": ["boolean", "object"],
|
||||||
|
|
|
@ -348,6 +348,7 @@ type CredentialSpecConfig struct {
|
||||||
|
|
||||||
// FileObjectConfig is a config type for a file used by a service
|
// FileObjectConfig is a config type for a file used by a service
|
||||||
type FileObjectConfig struct {
|
type FileObjectConfig struct {
|
||||||
|
Name string
|
||||||
File string
|
File string
|
||||||
External External
|
External External
|
||||||
Labels Labels
|
Labels Labels
|
||||||
|
|
Loading…
Reference in New Issue