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