Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove force push/pull prompts #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/secretsEncrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ var secretsEncryptCmd = &cobra.Command{
return err
}

promptPushSecret(sm, secret)
if encryptPush {
err := promptPushSecret(sm, secret)
if err != nil {
return err
}
}

return nil
},
}

func init() {
secretsEncryptCmd.Flags().BoolVarP(&encryptPush, "push", "y", false, "Push after encrypt")
secretsEncryptCmd.Flags().BoolVarP(&forcePush, "force", "f", false, "Used with push to skip prompt")
}
5 changes: 4 additions & 1 deletion cmd/secretsPull.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var secretsPullCmd = &cobra.Command{
}

func pullSecret(sm *truss.SecretsManager, secret truss.SecretConfig) error {
areSame, err := secretCompare(sm, secret, false)
areSame, err := secretCompare(sm, secret, false, forcePull)
if err != nil {
return err
}
Expand All @@ -49,6 +49,9 @@ func pullSecret(sm *truss.SecretsManager, secret truss.SecretConfig) error {
return nil
}

if forcePull {
fmt.Println("Force pulling secrets.")
}
if forcePull || prompter.YesNo(fmt.Sprintf("Pull from environment %s?", secret.Name()), false) {
return sm.Pull(secret)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/secretsPush.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var secretsPushCmd = &cobra.Command{
}

func promptPushSecret(sm *truss.SecretsManager, secret truss.SecretConfig) error {
areSame, err := secretCompare(sm, secret, true)
areSame, err := secretCompare(sm, secret, true, forcePush)
if err != nil {
return err
}
Expand All @@ -49,6 +49,9 @@ func promptPushSecret(sm *truss.SecretsManager, secret truss.SecretConfig) error
return nil
}

if forcePush {
fmt.Println("Force pushing secrets.")
}
if forcePush || prompter.YesNo(fmt.Sprintf("Push to environment %s?", secret.Name()), false) {
return sm.Push(secret)
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/secretsView.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ var secretsViewCmd = &cobra.Command{
return err
}

_, err = secretCompare(sm, secret, true)
_, err = secretCompare(sm, secret, true, false)
return err
},
}

// return true if same
func secretCompare(sm *truss.SecretsManager, secret truss.SecretConfig, localToRemote bool) (bool, error) {
func secretCompare(sm *truss.SecretsManager, secret truss.SecretConfig, localToRemote bool, quiet bool) (bool, error) {
localContent, remoteContent, err := sm.View(secret)
if err != nil {
return false, err
Expand All @@ -42,6 +42,8 @@ func secretCompare(sm *truss.SecretsManager, secret truss.SecretConfig, localToR
} else {
diffs = dmp.DiffMain(localContent, remoteContent, false)
}
fmt.Println(dmp.DiffPrettyText(diffs))
if !quiet {
fmt.Println(dmp.DiffPrettyText(diffs))
}
return remoteContent == localContent, nil
}