Skip to content

Commit

Permalink
Add a 'list-secrets' subcommand to display secrets for a deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Shados committed Feb 6, 2019
1 parent 98a14b4 commit e6fff65
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions morph.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
skipHealthChecks bool
healthCheck = healthCheckCmd(app.Command("check-health", "Run health checks"))
uploadSecrets = uploadSecretsCmd(app.Command("upload-secrets", "Upload secrets"))
listSecrets = listSecretsCmd(app.Command("list-secrets", "List secrets"))
execute = executeCmd(app.Command("exec", "Execute arbitrary commands on machines"))
executeCommand []string

Expand Down Expand Up @@ -157,6 +158,12 @@ func uploadSecretsCmd(cmd *kingpin.CmdClause) *kingpin.CmdClause {
return cmd
}

func listSecretsCmd(cmd *kingpin.CmdClause) *kingpin.CmdClause {
selectorFlags(cmd)
deploymentArg(cmd)
return cmd
}

func init() {
if err := validateEnvironment(); err != nil {
panic(err)
Expand Down Expand Up @@ -192,6 +199,8 @@ func main() {
err = execHealthCheck(hosts)
case uploadSecrets.FullCommand():
err = execUploadSecrets(createSSHContext(), hosts)
case listSecrets.FullCommand():
execListSecrets(hosts)
case execute.FullCommand():
err = execExecute(hosts)
}
Expand Down Expand Up @@ -397,6 +406,19 @@ func execUploadSecrets(sshContext *ssh.SSHContext, hosts []nix.Host) error {
return nil
}

func execListSecrets(hosts []nix.Host) {
for _, host := range hosts {
singleHostInList := []nix.Host{host}
for _, host := range singleHostInList {
fmt.Fprintf(os.Stdout, "Secrets for host %s:\n", host.Name)
for name, secret := range host.Secrets {
fmt.Fprintf(os.Stdout, "%s:\n- %v\n", name, &secret)
}
fmt.Fprintf(os.Stdout, "\n")
}
}
}

func validateEnvironment() (err error) {
dependencies := []string{"nix", "scp", "ssh"}
missingDepencies := make([]string, 0)
Expand Down

0 comments on commit e6fff65

Please sign in to comment.