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