mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +02:00
custom duration type for "cscli allowlist add"
This commit is contained in:
parent
45c6c11a15
commit
11a13d64b7
2 changed files with 5 additions and 14 deletions
|
@ -399,8 +399,8 @@ func (cli *cliAllowLists) delete(ctx context.Context, db *database.Client, name
|
|||
|
||||
func (cli *cliAllowLists) newAddCmd() *cobra.Command {
|
||||
var (
|
||||
expirationStr string
|
||||
comment string
|
||||
expiration cstime.Duration
|
||||
comment string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
|
@ -424,25 +424,16 @@ func (cli *cliAllowLists) newAddCmd() *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
var expiration time.Duration
|
||||
|
||||
if expirationStr != "" {
|
||||
expiration, err = cstime.ParseDuration(expirationStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
name := args[0]
|
||||
values := args[1:]
|
||||
|
||||
return cli.add(ctx, db, name, values, expiration, comment)
|
||||
return cli.add(ctx, db, name, values, time.Duration(expiration), comment)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
flags.StringVarP(&expirationStr, "expiration", "e", "", "expiration duration")
|
||||
flags.VarP(&expiration, "expiration", "e", "expiration duration")
|
||||
flags.StringVarP(&comment, "comment", "d", "", "comment for the value")
|
||||
|
||||
return cmd
|
||||
|
|
|
@ -126,7 +126,7 @@ teardown() {
|
|||
refute_output
|
||||
assert_stderr 'Error: invalid day value in duration "1 day"'
|
||||
|
||||
rune -0 cscli allowlist add foo 10.10.10.10 -d comment -e '1d'
|
||||
rune -0 cscli allowlist add foo 10.10.10.10 -d comment -e '1d12h'
|
||||
assert_output 'added 1 values to allowlist foo'
|
||||
refute_stderr
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue