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