systemprompt_cli/commands/admin/config/rate_limits/
mod.rs1mod diff;
2mod helpers;
3mod import_export;
4mod preset;
5mod reset;
6mod set;
7mod show;
8mod validate;
9
10use anyhow::Result;
11use clap::{Args, Subcommand};
12
13use crate::shared::render_result;
14use crate::CliConfig;
15
16#[derive(Debug, Subcommand)]
17pub enum RateLimitsCommands {
18 #[command(about = "Show current rate limits configuration")]
19 Show,
20
21 #[command(about = "Show effective limits for a specific tier")]
22 Tier(TierArgs),
23
24 #[command(about = "Show rate limits documentation")]
25 Docs,
26
27 #[command(about = "Set a rate limit value")]
28 Set(SetArgs),
29
30 #[command(about = "Enable rate limiting")]
31 Enable,
32
33 #[command(about = "Disable rate limiting")]
34 Disable,
35
36 #[command(about = "Validate rate limit configuration")]
37 Validate,
38
39 #[command(about = "Compare effective limits across all tiers")]
40 Compare,
41
42 #[command(about = "Reset rate limits to defaults")]
43 Reset(ResetArgs),
44
45 #[command(subcommand, about = "Manage rate limit presets")]
46 Preset(PresetCommands),
47
48 #[command(about = "Export rate limits to file")]
49 Export(ExportArgs),
50
51 #[command(about = "Import rate limits from file")]
52 Import(ImportArgs),
53
54 #[command(about = "Compare rate limits with defaults or file")]
55 Diff(DiffArgs),
56}
57
58#[derive(Debug, Clone, Args)]
59pub struct TierArgs {
60 #[arg(
61 value_name = "TIER",
62 help = "Tier name: admin, user, a2a, mcp, service, anon"
63 )]
64 pub tier: String,
65}
66
67#[derive(Debug, Clone, Args)]
68pub struct SetArgs {
69 #[arg(
70 long,
71 help = "Endpoint to modify: oauth_public, oauth_auth, contexts, tasks, artifacts, \
72 agent_registry, agents, mcp_registry, mcp, stream, content"
73 )]
74 pub endpoint: Option<String>,
75
76 #[arg(long, help = "Rate per second (requires --endpoint)")]
77 pub rate: Option<u64>,
78
79 #[arg(
80 long,
81 help = "Tier to modify multiplier: admin, user, a2a, mcp, service, anon"
82 )]
83 pub tier: Option<String>,
84
85 #[arg(long, help = "Multiplier value (requires --tier)")]
86 pub multiplier: Option<f64>,
87
88 #[arg(long, help = "Burst multiplier value")]
89 pub burst: Option<u64>,
90}
91
92#[derive(Debug, Clone, Args)]
93pub struct ResetArgs {
94 #[arg(short = 'y', long, help = "Skip confirmation")]
95 pub yes: bool,
96
97 #[arg(long, help = "Preview changes without applying")]
98 pub dry_run: bool,
99
100 #[arg(long, help = "Reset only this endpoint")]
101 pub endpoint: Option<String>,
102
103 #[arg(long, help = "Reset only this tier multiplier")]
104 pub tier: Option<String>,
105}
106
107#[derive(Debug, Subcommand)]
108pub enum PresetCommands {
109 #[command(about = "List available presets")]
110 List,
111
112 #[command(about = "Show preset configuration")]
113 Show(PresetShowArgs),
114
115 #[command(about = "Apply a preset")]
116 Apply(PresetApplyArgs),
117}
118
119#[derive(Debug, Clone, Args)]
120pub struct PresetShowArgs {
121 #[arg(help = "Preset name: development, production, high-traffic")]
122 pub name: String,
123}
124
125#[derive(Debug, Clone, Args)]
126pub struct PresetApplyArgs {
127 #[arg(help = "Preset name: development, production, high-traffic")]
128 pub name: String,
129
130 #[arg(short = 'y', long, help = "Skip confirmation")]
131 pub yes: bool,
132}
133
134#[derive(Debug, Clone, Args)]
135pub struct ExportArgs {
136 #[arg(long, short = 'o', help = "Output file path")]
137 pub output: String,
138
139 #[arg(long, default_value = "yaml", help = "Format: yaml, json")]
140 pub format: String,
141}
142
143#[derive(Debug, Clone, Args)]
144pub struct ImportArgs {
145 #[arg(long, short = 'f', help = "Input file path")]
146 pub file: String,
147
148 #[arg(short = 'y', long, help = "Skip confirmation")]
149 pub yes: bool,
150}
151
152#[derive(Debug, Clone, Args)]
153pub struct DiffArgs {
154 #[arg(long, help = "Compare with defaults")]
155 pub defaults: bool,
156
157 #[arg(long, short = 'f', help = "Compare with file")]
158 pub file: Option<String>,
159}
160
161pub fn execute(command: RateLimitsCommands, config: &CliConfig) -> Result<()> {
162 match command {
163 RateLimitsCommands::Show => show::execute_show(config),
164 RateLimitsCommands::Tier(args) => show::execute_tier(args, config),
165 RateLimitsCommands::Docs => show::execute_docs(config),
166 RateLimitsCommands::Set(args) => set::execute_set(&args, config),
167 RateLimitsCommands::Enable => set::execute_enable(config),
168 RateLimitsCommands::Disable => set::execute_disable(config),
169 RateLimitsCommands::Validate => validate::execute_validate(config),
170 RateLimitsCommands::Compare => validate::execute_compare(config),
171 RateLimitsCommands::Reset(args) => reset::execute_reset(&args, config),
172 RateLimitsCommands::Preset(cmd) => preset::execute_preset(cmd, config),
173 RateLimitsCommands::Export(args) => {
174 let result = import_export::execute_export(&args, config)?;
175 render_result(&result);
176 Ok(())
177 },
178 RateLimitsCommands::Import(args) => {
179 let result = import_export::execute_import(&args, config)?;
180 render_result(&result);
181 Ok(())
182 },
183 RateLimitsCommands::Diff(args) => diff::execute_diff(&args, config),
184 }
185}