[#290] Add timeout to authmate

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2021-12-26 23:38:16 +03:00
parent 62301d8ce8
commit a23a97efd6

View file

@ -49,6 +49,7 @@ var (
lifetimeFlag time.Duration
containerPolicies string
awcCliCredFile string
timeoutFlag time.Duration
)
const (
@ -124,6 +125,13 @@ func appFlags() []cli.Flag {
Usage: "Enable debug logger level",
Destination: &logDebugEnabledFlag,
},
&cli.DurationFlag{
Name: "timeout",
Usage: "timeout of processing of the command, for example 2m " +
"(note: max time unit is an hour so to set a day you should use 24h)",
Destination: &timeoutFlag,
Value: 1 * time.Minute,
},
}
}
@ -276,10 +284,13 @@ It will be ceil rounded to the nearest amount of epoch.`,
AwsCliCredentialsFile: awcCliCredFile,
}
if err = agent.IssueSecret(ctx, os.Stdout, issueSecretOptions); err != nil {
return cli.Exit(fmt.Sprintf("failed to issue secret: %s", err), 6)
}
var tcancel context.CancelFunc
ctx, tcancel = context.WithTimeout(ctx, timeoutFlag)
defer tcancel()
if err = agent.IssueSecret(ctx, os.Stdout, issueSecretOptions); err != nil {
return cli.Exit(fmt.Sprintf("failed to issue secret: %s", err), 7)
}
return nil
},
}
@ -391,6 +402,10 @@ func obtainSecret() *cli.Command {
GatePrivateKey: gateCreds,
}
var tcancel context.CancelFunc
ctx, tcancel = context.WithTimeout(ctx, timeoutFlag)
defer tcancel()
if err = agent.ObtainSecret(ctx, os.Stdout, obtainSecretOptions); err != nil {
return cli.Exit(fmt.Sprintf("failed to obtain secret: %s", err), 5)
}