diff --git a/internal/cli/gateway_keys_cli.go b/internal/cli/gateway_keys_cli.go index 7f013b991..93227f723 100644 --- a/internal/cli/gateway_keys_cli.go +++ b/internal/cli/gateway_keys_cli.go @@ -296,7 +296,9 @@ func perPhrase(l *access.Limit) string { // --cost and --cache-reads. func parseKeyLimit(window string, rest []string, usage error) (*access.Limit, error) { lim := &access.Limit{Period: window} - if n, ok := strings.CutSuffix(window, "d"); ok { + if window == "day" || window == "week" || window == "month" { + // a period by its name: month ends in an h, and is no count of hours + } else if n, ok := strings.CutSuffix(window, "d"); ok { days, err := strconv.Atoi(n) if err != nil || days < 1 || days > access.MaxDays { return nil, fmt.Errorf("an N-day cycle is a whole number of days from 1 to %d, like 10d: %q", access.MaxDays, window) diff --git a/internal/cli/gateway_keys_cli_test.go b/internal/cli/gateway_keys_cli_test.go index 6867695b4..51df153c9 100644 --- a/internal/cli/gateway_keys_cli_test.go +++ b/internal/cli/gateway_keys_cli_test.go @@ -208,6 +208,16 @@ func TestGatewayKeyLimitCLI(t *testing.T) { t.Error("accepted", args) } } + // month ends in an h, and is the month, not a count of hours + if got, err = call("limit", id, "month", "--cost", "20"); err != nil || !strings.Contains(got, "this month") { + t.Fatal(got, err) + } + if keys, _ = access.List(); keys[0].Limit == nil || keys[0].Limit.Period != "month" || keys[0].Limit.Cost != 20 { + t.Fatalf("limit kept as %+v", keys[0].Limit) + } + if got, err = call("limit", id, "add", "week", "--tokens", "1m"); err != nil || !strings.Contains(got, "Limit 2") { + t.Fatal(got, err) + } if got, err := call("limit", id, "off"); err != nil || !strings.Contains(got, "no limit") { t.Fatal(got, err) }