Skip to content

Commit

Permalink
fix run command error
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamvernekar committed Nov 4, 2023
1 parent a3991a0 commit 5a592be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cmd/dolores/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,46 @@ import (
"net/url"
"os"

"github.com/rs/zerolog/log"
"github.com/scalescape/dolores"
"github.com/scalescape/dolores/config"
"github.com/scalescape/dolores/secrets"
"github.com/urfave/cli/v2"
)

func parseDecryptConfig(ctx *cli.Context) (secrets.DecryptConfig, error) {
env := ctx.String("environment")
name := ctx.String("name")
func parseKeyConfig(ctx *cli.Context, cfg *secrets.DecryptConfig) error {
log.Trace().Msgf("parsing configuration required to decrypt config")
key := ctx.String("key")
keyFile := ctx.String("key-file")

if keyFile == "" {
d, err := config.LoadFromDisk()
if err != nil {
return secrets.DecryptConfig{}, fmt.Errorf("dolores not initialized yet: %w", err)
return fmt.Errorf("dolores not initialized yet: %w", err)
}
keyFile = d.Environments[env].KeyFile
keyFile = d.Environments[cfg.Environment].KeyFile
}
if keyFile == "" {
keyFile = os.Getenv("DOLORES_SECRETS_KEY_FILE")
}
if key == "" {
key = os.Getenv("DOLORES_SECRETS_KEY")
}
cfg.KeyFile = keyFile
cfg.Key = key

return nil
}

func parseDecryptConfig(ctx *cli.Context) (secrets.DecryptConfig, error) {
env := ctx.String("environment")
name := ctx.String("name")
req := secrets.DecryptConfig{
Environment: env,
Name: name,
Out: os.Stdout,
KeyFile: keyFile,
Key: ctx.String("key"),
}
if err := parseKeyConfig(ctx, &req); err != nil {
return secrets.DecryptConfig{}, fmt.Errorf("unable to load key-file from config: %w", err)
}
if err := req.Valid(); err != nil {
return secrets.DecryptConfig{}, fmt.Errorf("pass appropriate key or key-file to decrypt: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/dolores/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func (c *Runner) parse(ctx *cli.Context) error {
Environment: c.environment,
Out: c.configBuffer,
}
if err := parseKeyConfig(ctx, &c.DecryptConfig); err != nil {
return err
}
if err := c.DecryptConfig.Valid(); err != nil {
return err
}
Expand Down

0 comments on commit 5a592be

Please sign in to comment.