(namespace Namespace, spec composetypes.CredentialSpecConfig, refs []*swarm.ConfigReference)
| 681 | } |
| 682 | |
| 683 | func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpecConfig, refs []*swarm.ConfigReference) (*swarm.CredentialSpec, error) { |
| 684 | var o []string |
| 685 | |
| 686 | if spec.Config != "" { |
| 687 | o = append(o, `"Config"`) |
| 688 | } |
| 689 | if spec.File != "" { |
| 690 | o = append(o, `"File"`) |
| 691 | } |
| 692 | if spec.Registry != "" { |
| 693 | o = append(o, `"Registry"`) |
| 694 | } |
| 695 | l := len(o) |
| 696 | switch { |
| 697 | case l == 0: |
| 698 | return nil, nil |
| 699 | case l == 2: |
| 700 | return nil, fmt.Errorf("invalid credential spec: cannot specify both %s and %s", o[0], o[1]) |
| 701 | case l > 2: |
| 702 | return nil, fmt.Errorf("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]) |
| 703 | } |
| 704 | swarmCredSpec := swarm.CredentialSpec(spec) |
| 705 | // if we're using a swarm Config for the credential spec, over-write it |
| 706 | // here with the config ID |
| 707 | if swarmCredSpec.Config != "" { |
| 708 | for _, config := range refs { |
| 709 | if swarmCredSpec.Config == config.ConfigName { |
| 710 | swarmCredSpec.Config = config.ConfigID |
| 711 | return &swarmCredSpec, nil |
| 712 | } |
| 713 | } |
| 714 | // if none of the configs match, try namespacing |
| 715 | for _, config := range refs { |
| 716 | if namespace.Scope(swarmCredSpec.Config) == config.ConfigName { |
| 717 | swarmCredSpec.Config = config.ConfigID |
| 718 | return &swarmCredSpec, nil |
| 719 | } |
| 720 | } |
| 721 | return nil, fmt.Errorf("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config) |
| 722 | } |
| 723 | return &swarmCredSpec, nil |
| 724 | } |
| 725 | |
| 726 | func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*container.Ulimit { |
| 727 | ulimits := make([]*container.Ulimit, 0, len(origUlimits)) |
searching dependent graphs…