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:
Tibor Vass 2016-12-20 13:21:48 -08:00 committed by GitHub
commit df760c86cf
1 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package swarm
import (
"bufio"
"errors"
"fmt"
"io"
"strings"
@ -24,6 +25,22 @@ func newUnlockCommand(dockerCli *command.DockerCli) *cobra.Command {
client := dockerCli.Client()
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: ")
if err != nil {
return err