Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add credential-spec to compose #71

Merged
merged 1 commit into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func convertService(
return swarm.ServiceSpec{}, err
}

var privileges swarm.Privileges
privileges.CredentialSpec, err = convertCredentialSpec(service.CredentialSpec)
if err != nil {
return swarm.ServiceSpec{}, err
}

var logDriver *swarm.Driver
if service.Logging != nil {
logDriver = &swarm.Driver{
Expand Down Expand Up @@ -130,6 +136,7 @@ func convertService(
OpenStdin: service.StdinOpen,
Secrets: secrets,
ReadOnly: service.ReadOnly,
Privileges: &privileges,
},
LogDriver: logDriver,
Resources: resources,
Expand Down Expand Up @@ -477,3 +484,17 @@ func convertDNSConfig(DNS []string, DNSSearch []string) (*swarm.DNSConfig, error
}
return nil, nil
}

func convertCredentialSpec(spec composetypes.CredentialSpecConfig) (*swarm.CredentialSpec, error) {
if spec.File == "" && spec.Registry == "" {
return nil, nil
}
if spec.File != "" && spec.Registry != "" {
return nil, errors.New("Invalid credential spec - must provide one of `File` or `Registry`")
}

return &swarm.CredentialSpec{
File: spec.File,
Registry: spec.Registry,
}, nil
}
27 changes: 27 additions & 0 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,30 @@ func TestConvertDNSConfigSearch(t *testing.T) {
Search: search,
}, dnsConfig)
}

func TestConvertCredentialSpec(t *testing.T) {
swarmSpec, err := convertCredentialSpec(composetypes.CredentialSpecConfig{})
assert.NoError(t, err)
assert.Nil(t, swarmSpec)

swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{
File: "/foo",
})
assert.NoError(t, err)
assert.Equal(t, swarmSpec.File, "/foo")
assert.Equal(t, swarmSpec.Registry, "")

swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{
Registry: "foo",
})
assert.NoError(t, err)
assert.Equal(t, swarmSpec.File, "")
assert.Equal(t, swarmSpec.Registry, "foo")

swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{
File: "/asdf",
Registry: "foo",
})
assert.Error(t, err)
assert.Nil(t, swarmSpec)
}
16 changes: 16 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ secrets:
assert.Equal(t, len(actual.Secrets), 1)
}

func TestLoadV33(t *testing.T) {
actual, err := loadYAML(`
version: "3.3"
services:
foo:
image: busybox
credential_spec:
File: "/foo"
`)
if !assert.NoError(t, err) {
return
}
assert.Equal(t, len(actual.Services), 1)
assert.Equal(t, actual.Services[0].CredentialSpec.File, "/foo")
}

func TestParseAndLoad(t *testing.T) {
actual, err := loadYAML(sampleYAML)
if !assert.NoError(t, err) {
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
]
},
"container_name": {"type": "string"},
"credential_spec": {"type": "object", "properties": {
"file": {"type": "string"},
"registry": {"type": "string"}
}},
"depends_on": {"$ref": "#/definitions/list_of_strings"},
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"dns": {"$ref": "#/definitions/string_or_list"},
Expand Down
11 changes: 9 additions & 2 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ type ServiceConfig struct {
CapDrop []string `mapstructure:"cap_drop"`
CgroupParent string `mapstructure:"cgroup_parent"`
Command ShellCommand
ContainerName string `mapstructure:"container_name"`
DependsOn []string `mapstructure:"depends_on"`
ContainerName string `mapstructure:"container_name"`
CredentialSpec CredentialSpecConfig `mapstructure:"credential_spec"`
DependsOn []string `mapstructure:"depends_on"`
Deploy DeployConfig
Devices []string
DNS StringList
Expand Down Expand Up @@ -310,3 +311,9 @@ type SecretConfig struct {
External External
Labels Labels
}

// CredentialSpecConfig for credential spec on Windows
type CredentialSpecConfig struct {
File string
Registry string
}