1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "oauth-db")]
#[command(about = "OAuth-DB CLI - Manage your OAuth-DB platform", long_about = None)]
#[command(version)]
pub struct Cli {
/// Server URL (overrides config)
#[arg(short, long, global = true)]
pub server: Option<String>,
/// Output format (table, json, yaml)
#[arg(short, long, global = true)]
pub output: Option<String>,
/// Disable colored output
#[arg(long, global = true)]
pub no_color: bool,
/// Verbose output
#[arg(short, long, global = true)]
pub verbose: bool,
/// Quiet mode
#[arg(short, long, global = true)]
pub quiet: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand)]
pub enum Commands {
/// Login to the platform
Login(LoginArgs),
/// Logout from the current account
Logout,
/// Show current user information
Whoami,
/// Manage accounts
Accounts {
#[command(subcommand)]
command: AccountsCommands,
},
/// Manage applications
App {
#[command(subcommand)]
command: AppCommands,
},
/// Manage application users
User {
#[command(subcommand)]
command: UserCommands,
},
/// Platform administration (admin only)
Admin {
#[command(subcommand)]
command: AdminCommands,
},
/// Manage CLI configuration
Config {
#[command(subcommand)]
command: ConfigCommands,
},
}
#[derive(Debug, Clone, Parser)]
pub struct LoginArgs {
/// Server URL
#[arg(short, long)]
pub server: Option<String>,
/// Username
#[arg(short, long)]
pub username: Option<String>,
/// Password (will prompt if not provided)
#[arg(short, long)]
pub password: Option<String>,
}
#[derive(Debug, Clone, Subcommand)]
pub enum AccountsCommands {
/// List all saved accounts
List,
/// Switch to a different account
Switch {
/// Account name to switch to
name: String,
},
/// Remove an account
Remove {
/// Account name to remove
name: String,
},
}
#[derive(Debug, Clone, Subcommand)]
pub enum AppCommands {
/// Create a new application
Create {
/// Application name
name: String,
#[arg(long, default_value = "main")]
default_db: String,
#[arg(long, default_value = "main")]
allowed_dbs: String,
#[arg(long, default_value = "1000")]
max_users: u32,
#[arg(long, default_value = "100")]
storage_quota: u32,
#[arg(long, default_value = "10")]
max_connections: u32,
#[arg(long, default_value = "100")]
qps_limit: u32,
},
/// List applications
List {
#[arg(long)]
status: Option<String>,
#[arg(long, default_value = "1")]
page: u32,
#[arg(long, default_value = "20")]
page_size: u32,
},
/// Show application details
Show { app_id: String },
/// Update application settings
Update {
app_id: String,
#[arg(long)]
name: Option<String>,
#[arg(long)]
default_db: Option<String>,
#[arg(long)]
allowed_dbs: Option<String>,
#[arg(long)]
max_users: Option<u32>,
#[arg(long)]
storage_quota: Option<u32>,
#[arg(long)]
max_connections: Option<u32>,
#[arg(long)]
qps_limit: Option<u32>,
},
/// Enable an application
Enable { app_id: String },
/// Disable an application
Disable { app_id: String },
/// Delete an application
Delete {
app_id: String,
#[arg(long)]
force: bool,
},
/// Reset application token
ResetToken { app_id: String },
/// Show application statistics
Stats { app_id: String },
}
#[derive(Debug, Clone, Subcommand)]
pub enum UserCommands {
/// Create a new application user
Create {
/// Application ID
app_id: String,
/// Custom token (optional)
#[arg(long)]
token: Option<String>,
/// Label for the user
#[arg(long)]
label: Option<String>,
/// Storage quota (MB)
#[arg(long)]
storage_quota: Option<u32>,
/// Max connections
#[arg(long)]
max_connections: Option<u32>,
/// QPS limit
#[arg(long)]
qps_limit: Option<u32>,
},
/// List application users
List {
/// Application ID
app_id: String,
/// Filter by status
#[arg(long)]
status: Option<String>,
/// Page number
#[arg(long, default_value = "1")]
page: u32,
/// Page size
#[arg(long, default_value = "20")]
page_size: u32,
},
/// Show user details
Show {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
},
/// Update user
Update {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
/// New label
#[arg(long)]
label: Option<String>,
/// Storage quota (MB, use 'null' to inherit)
#[arg(long)]
storage_quota: Option<String>,
/// Max connections (use 'null' to inherit)
#[arg(long)]
max_connections: Option<String>,
/// QPS limit (use 'null' to inherit)
#[arg(long)]
qps_limit: Option<String>,
},
/// Enable user
Enable {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
},
/// Disable user
Disable {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
},
/// Delete user
Delete {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
/// Skip confirmation
#[arg(long)]
force: bool,
},
/// Reset user token
ResetToken {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
},
/// Show user statistics
Stats {
/// Application ID
app_id: String,
/// User UID
user_uid: String,
},
}
#[derive(Debug, Clone, Subcommand)]
pub enum AdminCommands {
/// Manage platform users
Users {
#[command(subcommand)]
command: AdminUsersCommands,
},
/// Show system statistics
Stats,
}
#[derive(Debug, Clone, Subcommand)]
pub enum AdminUsersCommands {
List {
#[arg(long)]
role: Option<String>,
#[arg(long)]
status: Option<String>,
#[arg(long, default_value = "1")]
page: u32,
#[arg(long, default_value = "20")]
page_size: u32,
},
Show { user_id: String },
Create {
#[arg(long)]
username: String,
#[arg(long)]
email: String,
#[arg(long, default_value = "user")]
role: String,
#[arg(long)]
password: Option<String>,
},
Enable { user_id: String },
Disable { user_id: String },
SetRole {
user_id: String,
#[arg(long)]
role: String,
},
}
#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommands {
Set { key: String, value: String },
Get { key: String },
List,
Reset,
}