mirror of https://github.com/docker/cli.git
Merge pull request #29470 from cyli/ask-for-unlock-key-only-if-locked
Check if a swarm is locked before asking a user to enter their unlock key
This commit is contained in:
commit
df760c86cf
|
@ -2,6 +2,7 @@ package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -24,6 +25,22 @@ func newUnlockCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
client := dockerCli.Client()
|
client := dockerCli.Client()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// First see if the node is actually part of a swarm, and if it's is actually locked first.
|
||||||
|
// If it's in any other state than locked, don't ask for the key.
|
||||||
|
info, err := client.Info(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch info.Swarm.LocalNodeState {
|
||||||
|
case swarm.LocalNodeStateInactive:
|
||||||
|
return errors.New("Error: This node is not part of a swarm")
|
||||||
|
case swarm.LocalNodeStateLocked:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return errors.New("Error: swarm is not locked")
|
||||||
|
}
|
||||||
|
|
||||||
key, err := readKey(dockerCli.In(), "Please enter unlock key: ")
|
key, err := readKey(dockerCli.In(), "Please enter unlock key: ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue