Skip to content

Commit c88cd3d

Browse files
author
Otávio Fernandes
committed
Adding flag for dot-env creation on download.
1 parent ced369d commit c88cd3d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

cmd/vault-handler/download.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package main
33
import (
44
"os"
55

6-
vh "github.com/otaviof/vault-handler/pkg/vault-handler"
76
log "github.com/sirupsen/logrus"
87
"github.com/spf13/cobra"
98
"github.com/spf13/viper"
9+
10+
vh "github.com/otaviof/vault-handler/pkg/vault-handler"
1011
)
1112

1213
var downloadCmd = &cobra.Command{
@@ -39,6 +40,7 @@ func init() {
3940
flags := downloadCmd.PersistentFlags()
4041

4142
flags.String("output-dir", ".", "Output directory.")
43+
flags.Bool("dot-env", false, "Create a dot-env file with downloaded secrets")
4244

4345
rootCmd.AddCommand(downloadCmd)
4446

cmd/vault-handler/vault_handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"os"
55
"strings"
66

7-
vh "github.com/otaviof/vault-handler/pkg/vault-handler"
87
log "github.com/sirupsen/logrus"
98
"github.com/spf13/cobra"
109
"github.com/spf13/viper"
10+
11+
vh "github.com/otaviof/vault-handler/pkg/vault-handler"
1112
)
1213

1314
var rootCmd = &cobra.Command{
@@ -65,6 +66,7 @@ func configFromEnv() *vh.Config {
6566
return &vh.Config{
6667
DryRun: viper.GetBool("dry-run"),
6768
OutputDir: viper.GetString("output-dir"),
69+
DotEnv: viper.GetBool("dot-env"),
6870
InputDir: viper.GetString("input-dir"),
6971
VaultAddr: viper.GetString("vault-addr"),
7072
VaultToken: viper.GetString("vault-token"),

pkg/vault-handler/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Config struct {
99
DryRun bool // dry-run flag
1010
OutputDir string // output directory path
1111
InputDir string // input directory, when uploading
12+
DotEnv bool // create a dot-env file with secrets
1213
VaultAddr string // vault api endpoint
1314
VaultToken string // vault token
1415
VaultRoleID string // vault approle role-id
@@ -47,7 +48,7 @@ func (c *Config) ValidateKubernetes() error {
4748
if c.Namespace == "" {
4849
return fmt.Errorf("namespace is not informed")
4950
}
50-
if c.KubeConfig != "" && !fileExists(c.KubeConfig) {
51+
if c.KubeConfig != "" && !FileExists(c.KubeConfig) {
5152
return fmt.Errorf("can't find kube-config file at '%s'", c.KubeConfig)
5253
}
5354
return nil

0 commit comments

Comments
 (0)