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

Function runUnlock

cli/command/swarm/unlock.go:39–67  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

37}
38
39func runUnlock(ctx context.Context, dockerCLI command.Cli) error {
40 apiClient := dockerCLI.Client()
41
42 // First see if the node is actually part of a swarm, and if it is actually locked first.
43 // If it's in any other state than locked, don't ask for the key.
44 res, err := apiClient.Info(ctx, client.InfoOptions{})
45 if err != nil {
46 return err
47 }
48
49 switch res.Info.Swarm.LocalNodeState {
50 case swarm.LocalNodeStateInactive:
51 return errors.New("error: this node is not part of a swarm")
52 case swarm.LocalNodeStateLocked:
53 break
54 case swarm.LocalNodeStatePending, swarm.LocalNodeStateActive, swarm.LocalNodeStateError:
55 return errors.New("error: swarm is not locked")
56 }
57
58 key, err := readKey(dockerCLI.In(), "Enter unlock key: ")
59 if err != nil {
60 return err
61 }
62
63 _, err = apiClient.SwarmUnlock(ctx, client.SwarmUnlockOptions{
64 Key: key,
65 })
66 return err
67}
68
69func readKey(in *streams.In, prompt string) (string, error) {
70 if in.IsTerminal() {

Callers 1

newUnlockCommandFunction · 0.85

Calls 5

readKeyFunction · 0.85
SwarmUnlockMethod · 0.80
ClientMethod · 0.65
InMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…