Skip to content

Commit 871ebc4

Browse files
authored
feat: add policy rules commands with input hardening (#7)
1 parent 56cc104 commit 871ebc4

File tree

8 files changed

+480
-6
lines changed

8 files changed

+480
-6
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OneCLI CLI
22

3-
CLI for [OneCLI](https://onecli.sh) — manage agents, secrets, and configuration from the terminal.
3+
CLI for [OneCLI](https://onecli.sh) — manage agents, secrets, rules, and configuration from the terminal.
44

55
## Install
66

@@ -48,6 +48,16 @@ onecli secrets update --id X --value Y Update a secret
4848
onecli secrets delete --id X Delete a secret
4949
```
5050

51+
### Rules
52+
53+
```
54+
onecli rules list List all policy rules
55+
onecli rules get --id X Get a single rule
56+
onecli rules create --name X --host-pattern Y ... Create a new rule
57+
onecli rules update --id X [--action block] ... Update a rule
58+
onecli rules delete --id X Delete a rule
59+
```
60+
5161
### Auth
5262

5363
```

cmd/onecli/auth.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616

1717
// AuthCmd is the `onecli auth` command group.
1818
type AuthCmd struct {
19-
Login AuthLoginCmd `cmd:"" help:"Store API key for authentication."`
20-
Logout AuthLogoutCmd `cmd:"" help:"Remove stored API key."`
21-
Status AuthStatusCmd `cmd:"" help:"Show authentication status."`
19+
Login AuthLoginCmd `cmd:"" help:"Store API key for authentication."`
20+
Logout AuthLogoutCmd `cmd:"" help:"Remove stored API key."`
21+
Status AuthStatusCmd `cmd:"" help:"Show authentication status."`
22+
ApiKey AuthApiKeyCmd `cmd:"api-key" help:"Show your current API key."`
23+
RegenerateApiKey AuthRegenerateApiKeyCmd `cmd:"regenerate-api-key" help:"Regenerate your API key."`
2224
}
2325

2426
// AuthLoginCmd is `onecli auth login`.
@@ -131,3 +133,40 @@ func (c *AuthStatusCmd) Run(out *output.Writer) error {
131133
Name: user.Name,
132134
})
133135
}
136+
137+
// AuthApiKeyCmd is `onecli auth api-key`.
138+
type AuthApiKeyCmd struct {
139+
Fields string `optional:"" help:"Comma-separated list of fields to include in output."`
140+
}
141+
142+
func (c *AuthApiKeyCmd) Run(out *output.Writer) error {
143+
client, err := newClient()
144+
if err != nil {
145+
return err
146+
}
147+
resp, err := client.GetAPIKey(newContext())
148+
if err != nil {
149+
return err
150+
}
151+
return out.WriteFiltered(resp, c.Fields)
152+
}
153+
154+
// AuthRegenerateApiKeyCmd is `onecli auth regenerate-api-key`.
155+
type AuthRegenerateApiKeyCmd struct {
156+
DryRun bool `optional:"" name:"dry-run" help:"Validate the request without executing it."`
157+
}
158+
159+
func (c *AuthRegenerateApiKeyCmd) Run(out *output.Writer) error {
160+
if c.DryRun {
161+
return out.WriteDryRun("Would regenerate API key", nil)
162+
}
163+
client, err := newClient()
164+
if err != nil {
165+
return err
166+
}
167+
resp, err := client.RegenerateAPIKey(newContext())
168+
if err != nil {
169+
return err
170+
}
171+
return out.Write(resp)
172+
}

cmd/onecli/help.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (cmd *HelpCmd) Run(out *output.Writer) error {
3737
return out.Write(HelpResponse{
3838
Name: "onecli",
3939
Version: version,
40-
Description: "CLI for managing OneCLI agents, secrets, and configuration.",
40+
Description: "CLI for managing OneCLI agents, secrets, rules, and configuration.",
4141
Commands: []CommandInfo{
4242
{Name: "agents list", Description: "List all agents."},
4343
{Name: "agents get-default", Description: "Get the default agent."},
@@ -79,9 +79,23 @@ func (cmd *HelpCmd) Run(out *output.Writer) error {
7979
{Name: "secrets delete", Description: "Delete a secret.", Args: []ArgInfo{
8080
{Name: "--id", Required: true, Description: "ID of the secret to delete."},
8181
}},
82+
{Name: "rules list", Description: "List all policy rules."},
83+
{Name: "rules create", Description: "Create a new policy rule.", Args: []ArgInfo{
84+
{Name: "--name", Required: true, Description: "Display name for the rule."},
85+
{Name: "--host-pattern", Required: true, Description: "Host pattern to match."},
86+
{Name: "--action", Required: true, Description: "Action: 'block' or 'rate_limit'."},
87+
}},
88+
{Name: "rules update", Description: "Update an existing policy rule.", Args: []ArgInfo{
89+
{Name: "--id", Required: true, Description: "ID of the rule to update."},
90+
}},
91+
{Name: "rules delete", Description: "Delete a policy rule.", Args: []ArgInfo{
92+
{Name: "--id", Required: true, Description: "ID of the rule to delete."},
93+
}},
8294
{Name: "auth login", Description: "Store API key for authentication."},
8395
{Name: "auth logout", Description: "Remove stored API key."},
8496
{Name: "auth status", Description: "Show authentication status."},
97+
{Name: "auth api-key", Description: "Show your current API key."},
98+
{Name: "auth regenerate-api-key", Description: "Regenerate your API key."},
8599
{Name: "config get <key>", Description: "Get a config value."},
86100
{Name: "config set <key> <value>", Description: "Set a config value."},
87101
{Name: "version", Description: "Print version information."},

cmd/onecli/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type CLI struct {
2222
Help HelpCmd `cmd:"" help:"Show available commands."`
2323
Agents AgentsCmd `cmd:"" help:"Manage agents."`
2424
Secrets SecretsCmd `cmd:"" help:"Manage secrets."`
25+
Rules RulesCmd `cmd:"" help:"Manage policy rules."`
2526
Auth AuthCmd `cmd:"" help:"Manage authentication."`
2627
Config ConfigCmd `cmd:"" help:"Manage configuration settings."`
2728
}
@@ -43,7 +44,7 @@ func main() {
4344
cli := &CLI{}
4445
k, err := kong.New(cli,
4546
kong.Name("onecli"),
46-
kong.Description("CLI for managing OneCLI agents, secrets, and configuration."),
47+
kong.Description("CLI for managing OneCLI agents, secrets, rules, and configuration."),
4748
kong.Help(jsonHelpPrinter(out)),
4849
kong.Bind(out),
4950
)

0 commit comments

Comments
 (0)