mirror of
https://github.com/docker/docs.git
synced 2026-10-31 10:34:26 +03:00
basic caching of root password for notary cli
Signed-off-by: Nathan McCauley <nathan.mccauley@docker.com>
This commit is contained in:
@@ -275,13 +275,21 @@ func verify(cmd *cobra.Command, args []string) {
|
||||
func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever {
|
||||
userEnteredTargetsSnapshotsPass := false
|
||||
targetsSnapshotsPass := ""
|
||||
userEnteredRootsPass := false
|
||||
rootsPass := ""
|
||||
|
||||
return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
|
||||
if numAttempts == 0 && userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") {
|
||||
fmt.Println("return cached value")
|
||||
|
||||
return targetsSnapshotsPass, false, nil
|
||||
// First, check if we have a password cached for this alias.
|
||||
if numAttempts == 0 {
|
||||
if userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") {
|
||||
return targetsSnapshotsPass, false, nil
|
||||
}
|
||||
if userEnteredRootsPass && (alias == "root") {
|
||||
return rootsPass, false, nil
|
||||
}
|
||||
}
|
||||
|
||||
if numAttempts > 3 && !createNew {
|
||||
return "", true, errors.New("Too many attempts")
|
||||
}
|
||||
@@ -314,6 +322,10 @@ func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever {
|
||||
userEnteredTargetsSnapshotsPass = true
|
||||
targetsSnapshotsPass = retPass
|
||||
}
|
||||
if alias == "root" {
|
||||
userEnteredRootsPass = true
|
||||
rootsPass = retPass
|
||||
}
|
||||
return string(passphrase), false, nil
|
||||
}
|
||||
|
||||
@@ -335,10 +347,14 @@ func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever {
|
||||
}
|
||||
retPass := string(passphrase)
|
||||
|
||||
if alias == "snapshots" || alias == "targets" {
|
||||
if alias == "snapshot" || alias == "targets" {
|
||||
userEnteredTargetsSnapshotsPass = true
|
||||
targetsSnapshotsPass = retPass
|
||||
}
|
||||
if alias == "root" {
|
||||
userEnteredRootsPass = true
|
||||
rootsPass = retPass
|
||||
}
|
||||
|
||||
return retPass, false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user