github.com/pojntfx/hydrapp/hydrapp@v0.0.0-20240516002902-d08759d6ca9f/cmd/secrets_show.go (about) 1 package cmd 2 3 import ( 4 "encoding/base64" 5 "fmt" 6 "os" 7 8 "github.com/pojntfx/hydrapp/hydrapp/pkg/secrets" 9 "github.com/spf13/cobra" 10 "github.com/spf13/viper" 11 ) 12 13 var secretsShowCmd = &cobra.Command{ 14 Use: "show", 15 Aliases: []string{"s"}, 16 Short: "Show hydrapp secrets as env variables", 17 RunE: func(cmd *cobra.Command, args []string) error { 18 if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil { 19 return err 20 } 21 22 secretsFile, err := os.Open(viper.GetString(secretsFlag)) 23 if err != nil { 24 return err 25 } 26 defer secretsFile.Close() 27 28 scs, err := secrets.Parse(secretsFile) 29 if err != nil { 30 return err 31 } 32 33 fmt.Printf(`export JAVA_KEYSTORE="%v" 34 export JAVA_KEYSTORE_PASSWORD="%v" 35 export JAVA_CERTIFICATE_PASSWORD="%v" 36 export PGP_KEY="%v" 37 export PGP_KEY_ID="%v" 38 export PGP_KEY_PASSWORD="%v" 39 `, 40 41 base64.StdEncoding.EncodeToString(scs.JavaSecrets.Keystore), 42 base64.StdEncoding.EncodeToString([]byte(scs.JavaSecrets.KeystorePassword)), 43 base64.StdEncoding.EncodeToString([]byte(scs.JavaSecrets.CertificatePassword)), 44 45 base64.StdEncoding.EncodeToString([]byte(scs.PGPSecrets.Key)), 46 base64.StdEncoding.EncodeToString([]byte(scs.PGPSecrets.KeyID)), 47 base64.StdEncoding.EncodeToString([]byte(scs.PGPSecrets.KeyPassword)), 48 ) 49 50 return nil 51 }, 52 } 53 54 func init() { 55 viper.AutomaticEnv() 56 57 secretsCmd.AddCommand(secretsShowCmd) 58 }