mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 20:36:12 +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 {
|
func (cli *cliAllowLists) newAddCmd() *cobra.Command {
|
||||||
var (
|
var (
|
||||||
expirationStr string
|
expiration cstime.Duration
|
||||||
comment string
|
comment string
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
@ -424,25 +424,16 @@ func (cli *cliAllowLists) newAddCmd() *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var expiration time.Duration
|
|
||||||
|
|
||||||
if expirationStr != "" {
|
|
||||||
expiration, err = cstime.ParseDuration(expirationStr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
values := args[1:]
|
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 := 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")
|
flags.StringVarP(&comment, "comment", "d", "", "comment for the value")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
@ -126,7 +126,7 @@ teardown() {
|
||||||
refute_output
|
refute_output
|
||||||
assert_stderr 'Error: invalid day value in duration "1 day"'
|
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'
|
assert_output 'added 1 values to allowlist foo'
|
||||||
refute_stderr
|
refute_stderr
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue