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