MCPcopy Index your code
hub / github.com/docker/cli / getUpdatedConfigs

Function getUpdatedConfigs

cli/command/service/update.go:798–855  ·  view source on GitHub ↗
(ctx context.Context, apiClient client.ConfigAPIClient, flags *pflag.FlagSet, spec *swarm.ContainerSpec)

Source from the content-addressed store, hash-verified

796}
797
798func getUpdatedConfigs(ctx context.Context, apiClient client.ConfigAPIClient, flags *pflag.FlagSet, spec *swarm.ContainerSpec) ([]*swarm.ConfigReference, error) {
799 var (
800 // credSpecConfigName stores the name of the config specified by the
801 // credential-spec flag. if a Runtime target Config with this name is
802 // already in the containerSpec, then this value will be set to
803 // emptystring in the removeConfigs stage. otherwise, a ConfigReference
804 // will be created to pass to ParseConfigs to get the ConfigID.
805 credSpecConfigName string
806 // credSpecConfigID stores the ID of the credential spec config if that
807 // config is being carried over from the old set of references
808 credSpecConfigID string
809 )
810
811 if flags.Changed(flagCredentialSpec) {
812 credSpec := flags.Lookup(flagCredentialSpec).Value.(*credentialSpecOpt).Value()
813 credSpecConfigName = credSpec.Config
814 } else { //nolint:gocritic // ignore elseif: can replace 'else {if cond {}}' with 'else if cond {}'
815 // if the credential spec flag has not changed, then check if there
816 // already is a credentialSpec. if there is one, and it's for a Config,
817 // then it's from the old object, and its value is the config ID. we
818 // need this so we don't remove the config if the credential spec is
819 // not being updated.
820 if spec.Privileges != nil && spec.Privileges.CredentialSpec != nil {
821 if config := spec.Privileges.CredentialSpec.Config; config != "" {
822 credSpecConfigID = config
823 }
824 }
825 }
826
827 newConfigs := removeConfigs(flags, spec, credSpecConfigName, credSpecConfigID)
828
829 // resolveConfigs is a slice of any new configs that need to have the ID
830 // resolved
831 resolveConfigs := []*swarm.ConfigReference{}
832
833 if flags.Changed(flagConfigAdd) {
834 resolveConfigs = append(resolveConfigs, flags.Lookup(flagConfigAdd).Value.(*swarmopts.ConfigOpt).Value()...)
835 }
836
837 // if credSpecConfigNameis non-empty at this point, it means its a new
838 // config, and we need to resolve its ID accordingly.
839 if credSpecConfigName != "" {
840 resolveConfigs = append(resolveConfigs, &swarm.ConfigReference{
841 ConfigName: credSpecConfigName,
842 Runtime: &swarm.ConfigReferenceRuntimeTarget{},
843 })
844 }
845
846 if len(resolveConfigs) > 0 {
847 addConfigs, err := ParseConfigs(ctx, apiClient, resolveConfigs)
848 if err != nil {
849 return nil, err
850 }
851 newConfigs = append(newConfigs, addConfigs...)
852 }
853
854 return newConfigs, nil
855}

Callers 2

runUpdateFunction · 0.85

Calls 3

ParseConfigsFunction · 0.85
removeConfigsFunction · 0.70
ValueMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…