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

Function runCA

cli/command/swarm/ca.go:58–98  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts caOptions)

Source from the content-addressed store, hash-verified

56}
57
58func runCA(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts caOptions) error {
59 apiClient := dockerCLI.Client()
60
61 res, err := apiClient.SwarmInspect(ctx, client.SwarmInspectOptions{})
62 if err != nil {
63 return err
64 }
65
66 if !opts.rotate {
67 for _, f := range []string{flagCACert, flagCAKey, flagCertExpiry, flagExternalCA} {
68 if flags.Changed(f) {
69 return fmt.Errorf("`--%s` flag requires the `--rotate` flag to update the CA", f)
70 }
71 }
72 return displayTrustRoot(dockerCLI.Out(), res)
73 }
74
75 if flags.Changed(flagExternalCA) && len(opts.externalCA.Value()) > 0 && !flags.Changed(flagCACert) {
76 return fmt.Errorf(
77 "rotating to an external CA requires the `--%s` flag to specify the external CA's cert - "+
78 "to add an external CA with the current root CA certificate, use the `update` command instead", flagCACert)
79 }
80
81 if flags.Changed(flagCACert) && len(opts.externalCA.Value()) == 0 && !flags.Changed(flagCAKey) {
82 return fmt.Errorf("the --%s flag requires that a --%s flag and/or --%s flag be provided as well",
83 flagCACert, flagCAKey, flagExternalCA)
84 }
85
86 updateSwarmSpec(&res.Swarm.Spec, flags, opts)
87 if _, err := apiClient.SwarmUpdate(ctx, client.SwarmUpdateOptions{
88 Version: res.Swarm.Version,
89 Spec: res.Swarm.Spec,
90 }); err != nil {
91 return err
92 }
93
94 if opts.detach {
95 return nil
96 }
97 return attach(ctx, dockerCLI, opts)
98}
99
100func updateSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet, opts caOptions) {
101 caCert := opts.rootCACert.Contents()

Callers 1

newCACommandFunction · 0.85

Calls 8

displayTrustRootFunction · 0.85
updateSwarmSpecFunction · 0.85
attachFunction · 0.85
SwarmInspectMethod · 0.80
SwarmUpdateMethod · 0.80
ClientMethod · 0.65
OutMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…