Skip to content

Commit 7d6d805

Browse files
committed
feat: exit-early flag when provider or secret not found
1 parent a134c43 commit 7d6d805

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func main() {
4949
Usage: "supported secrets manager provider ['aws', 'google']",
5050
Value: "aws",
5151
},
52+
&cli.BoolFlag{
53+
Name: "exit-early",
54+
Usage: "exit when a provider fails or a secret is not found",
55+
EnvVars: []string{"EXIT_EARLY"},
56+
},
5257
},
5358
Commands: []*cli.Command{
5459
{
@@ -133,11 +138,14 @@ func mainCmd(c *cli.Context) error {
133138
}
134139
if err != nil {
135140
log.WithField("provider", c.String("provider")).WithError(err).Error("failed to initialize secrets provider")
141+
if c.Bool("exit-early") {
142+
os.Exit(1)
143+
}
136144
}
137145

138146
// Launch main command
139147
var childPid int
140-
childPid, err = run(ctx, provider, c.Args().Slice())
148+
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Args().Slice())
141149
if err != nil {
142150
log.WithError(err).Error("failed to run")
143151
os.Exit(1)
@@ -177,7 +185,7 @@ func removeZombies(childPid int) {
177185
}
178186

179187
// run passed command
180-
func run(ctx context.Context, provider secrets.Provider, commandSlice []string) (childPid int, err error) {
188+
func run(ctx context.Context, provider secrets.Provider, exitEarly bool, commandSlice []string) (childPid int, err error) {
181189
var commandStr string
182190
var argsSlice []string
183191

@@ -209,6 +217,10 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
209217
cmd.Env, err = provider.ResolveSecrets(ctx, os.Environ())
210218
if err != nil {
211219
log.WithError(err).Error("failed to resolve secrets")
220+
if exitEarly {
221+
log.Error("Exiting early unable to retrieve secrets")
222+
os.Exit(1)
223+
}
212224
}
213225
} else {
214226
log.Warn("no secrets provider available; using environment without resolving secrets")

0 commit comments

Comments
 (0)