Skip to content

Commit

Permalink
breaking: cleanup of file output order to use cli as override as default
Browse files Browse the repository at this point in the history
  • Loading branch information
SorsOps committed Mar 28, 2023
1 parent cbe84a5 commit 2e4ddec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
},
&cli.StringFlag{
Name: "output",
Value: "./.vault-env.env",
Value: "",
Usage: "the default file output",
Destination: &output,
},
Expand Down Expand Up @@ -91,12 +91,12 @@ func main() {
}

err := secrets.RetrieveSecrets(&models.SecretCtx{
VaultAddress: vaultAddress,
InputFile: input,
Collection: collection,
DefaultToken: defaultToken,
DefaultOutput: output,
Format: format,
VaultAddress: vaultAddress,
InputFile: input,
Collection: collection,
DefaultToken: defaultToken,
Output: output,
Format: format,
})
if err != nil {
return err
Expand Down
6 changes: 1 addition & 5 deletions models/constants/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ package constants

// Constants for the project
const (
DefaultEnvPrefix = "VAULT_ENV_VAR"
DefaultYamlOutput = "./.vars.vault-env.yml"
DefaultJSONOutput = "./.vars.vault-env.json"
DefaultDotEnvOutput = "./.vault-env.env"
DefaultSecretsOutput = "./.vault-env-secrets.env"
DefaultDotEnvOutput = "./.env.vault"
)
7 changes: 1 addition & 6 deletions models/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package models
import (
"errors"
"fmt"

"sorsops/vault-env/v2/models/constants"
"sorsops/vault-env/v2/utils/ref"
)

type SecretType string
Expand Down Expand Up @@ -75,9 +72,7 @@ func initCollection(p *Secrets, collections []Collection) ([]Collection, error)
func (p *Secrets) InitDefaults() (*Secrets, error) {

var output *string
if p.Output == nil {
output = ref.String(constants.DefaultSecretsOutput)
} else {
if p.Output != nil {
output = p.Output
}

Expand Down
12 changes: 6 additions & 6 deletions models/secretCtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package models

//SecretCtx : The inputs we receive from the CLI that need to be globally accessible
type SecretCtx struct {
VaultAddress string
InputFile string
Collection string
DefaultOutput string
DefaultToken string
Format string
VaultAddress string
InputFile string
Collection string
Output string
DefaultToken string
Format string
}
8 changes: 6 additions & 2 deletions secrets/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"sorsops/vault-env/v2/models"
"sorsops/vault-env/v2/models/constants"

"github.com/hashicorp/vault/api"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -272,10 +273,13 @@ func RetrieveSecrets(ctx *models.SecretCtx) error {
} else {

var pathVal string
if (v.config.File != nil) && (len(*v.config.File) > 0) {

if len(ctx.Output) > 0 {
pathVal = ctx.Output
} else if (v.config.File != nil) && (len(*v.config.File) > 0) {
pathVal = *v.config.File
} else {
pathVal = ctx.DefaultOutput
pathVal = constants.DefaultDotEnvOutput
}

if !filepath.IsAbs(pathVal) {
Expand Down

0 comments on commit 2e4ddec

Please sign in to comment.