Skip to content

Commit faf0ad4

Browse files
authored
Merge pull request #36 from hhollenstain/exit-early
feat: exit-early flag when provider or secret not found
2 parents ff49794 + 3650278 commit faf0ad4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ 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"},
5256
&cli.StringFlag{
5357
Name: "google-project",
5458
Usage: "the google cloud project for secrets without a project prefix",
@@ -137,11 +141,14 @@ func mainCmd(c *cli.Context) error {
137141
}
138142
if err != nil {
139143
log.WithField("provider", c.String("provider")).WithError(err).Error("failed to initialize secrets provider")
144+
if c.Bool("exit-early") {
145+
os.Exit(1)
146+
}
140147
}
141148

142149
// Launch main command
143150
var childPid int
144-
childPid, err = run(ctx, provider, c.Args().Slice())
151+
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Args().Slice())
145152
if err != nil {
146153
log.WithError(err).Error("failed to run")
147154
os.Exit(1)
@@ -181,7 +188,7 @@ func removeZombies(childPid int) {
181188
}
182189

183190
// run passed command
184-
func run(ctx context.Context, provider secrets.Provider, commandSlice []string) (childPid int, err error) {
191+
func run(ctx context.Context, provider secrets.Provider, exitEarly bool, commandSlice []string) (childPid int, err error) {
185192
var commandStr string
186193
var argsSlice []string
187194

@@ -213,6 +220,10 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
213220
cmd.Env, err = provider.ResolveSecrets(ctx, os.Environ())
214221
if err != nil {
215222
log.WithError(err).Error("failed to resolve secrets")
223+
if exitEarly {
224+
log.Error("Exiting early unable to retrieve secrets")
225+
os.Exit(1)
226+
}
216227
}
217228
} else {
218229
log.Warn("no secrets provider available; using environment without resolving secrets")

0 commit comments

Comments
 (0)