api: Remove SecretRequestOption type

This type is only used by CLI code. It duplicates SecretReference in the
types/swarm package. Change the CLI code to use that type instead.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2017-03-16 10:54:18 -07:00
parent bc771127d8
commit 395081fc6b
2 changed files with 18 additions and 25 deletions

View File

@ -10,27 +10,19 @@ import (
"golang.org/x/net/context"
)
// ParseSecrets retrieves the secrets from the requested names and converts
// them to secret references to use with the spec
func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*types.SecretRequestOption) ([]*swarmtypes.SecretReference, error) {
// ParseSecrets retrieves the secrets with the requested names and fills
// secret IDs into the secret references.
func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.SecretReference) ([]*swarmtypes.SecretReference, error) {
secretRefs := make(map[string]*swarmtypes.SecretReference)
ctx := context.Background()
for _, secret := range requestedSecrets {
if _, exists := secretRefs[secret.Target]; exists {
return nil, fmt.Errorf("duplicate secret target for %s not allowed", secret.Source)
if _, exists := secretRefs[secret.File.Name]; exists {
return nil, fmt.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
}
secretRef := &swarmtypes.SecretReference{
File: &swarmtypes.SecretReferenceFileTarget{
Name: secret.Target,
UID: secret.UID,
GID: secret.GID,
Mode: secret.Mode,
},
SecretName: secret.Source,
}
secretRefs[secret.Target] = secretRef
secretRef := new(swarmtypes.SecretReference)
*secretRef = *secret
secretRefs[secret.File.Name] = secretRef
}
args := filters.NewArgs()

View File

@ -7,7 +7,6 @@ import (
"strings"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm"
servicecli "github.com/docker/docker/cli/command/service"
@ -196,7 +195,7 @@ func convertServiceSecrets(
secrets []composetypes.ServiceSecretConfig,
secretSpecs map[string]composetypes.SecretConfig,
) ([]*swarm.SecretReference, error) {
opts := []*types.SecretRequestOption{}
refs := []*swarm.SecretReference{}
for _, secret := range secrets {
target := secret.Target
if target == "" {
@ -222,16 +221,18 @@ func convertServiceSecrets(
mode = uint32Ptr(0444)
}
opts = append(opts, &types.SecretRequestOption{
Source: source,
Target: target,
refs = append(refs, &swarm.SecretReference{
File: &swarm.SecretReferenceFileTarget{
Name: target,
UID: uid,
GID: gid,
Mode: os.FileMode(*mode),
},
SecretName: source,
})
}
return servicecli.ParseSecrets(client, opts)
return servicecli.ParseSecrets(client, refs)
}
func uint32Ptr(value uint32) *uint32 {