(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts caOptions)
| 56 | } |
| 57 | |
| 58 | func 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 | |
| 100 | func updateSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet, opts caOptions) { |
| 101 | caCert := opts.rootCACert.Contents() |
no test coverage detected
searching dependent graphs…