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

Function runUnlockKey

cli/command/swarm/unlock_key.go:45–89  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts unlockKeyOptions)

Source from the content-addressed store, hash-verified

43}
44
45func runUnlockKey(ctx context.Context, dockerCLI command.Cli, opts unlockKeyOptions) error {
46 apiClient := dockerCLI.Client()
47
48 if opts.rotate {
49 res, err := apiClient.SwarmInspect(ctx, client.SwarmInspectOptions{})
50 if err != nil {
51 return err
52 }
53
54 if !res.Swarm.Spec.EncryptionConfig.AutoLockManagers {
55 return errors.New("cannot rotate because autolock is not turned on")
56 }
57
58 _, err = apiClient.SwarmUpdate(ctx, client.SwarmUpdateOptions{
59 Version: res.Swarm.Version,
60 Spec: res.Swarm.Spec,
61
62 RotateManagerUnlockKey: true,
63 })
64 if err != nil {
65 return err
66 }
67
68 if !opts.quiet {
69 _, _ = fmt.Fprintln(dockerCLI.Out(), "Successfully rotated manager unlock key.")
70 }
71 }
72
73 resp, err := apiClient.SwarmGetUnlockKey(ctx)
74 if err != nil {
75 return fmt.Errorf("could not fetch unlock key: %w", err)
76 }
77
78 if resp.Key == "" {
79 return errors.New("no unlock key is set")
80 }
81
82 if opts.quiet {
83 _, _ = fmt.Fprintln(dockerCLI.Out(), resp.Key)
84 return nil
85 }
86
87 printUnlockCommand(dockerCLI.Out(), resp.Key)
88 return nil
89}
90
91func printUnlockCommand(out io.Writer, unlockKey string) {
92 if len(unlockKey) > 0 {

Callers 1

newUnlockKeyCommandFunction · 0.85

Calls 6

printUnlockCommandFunction · 0.85
SwarmInspectMethod · 0.80
SwarmUpdateMethod · 0.80
SwarmGetUnlockKeyMethod · 0.80
ClientMethod · 0.65
OutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…