bios_basic/rbum/dto/rbum_cert_dto.rs
1use serde::{Deserialize, Serialize};
2use tardis::basic::field::TrimString;
3use tardis::chrono::{DateTime, Utc};
4
5use tardis::db::sea_orm;
6
7use tardis::web::poem_openapi;
8
9use crate::rbum::rbum_enumeration::{RbumCertRelKind, RbumCertStatusKind};
10
11/// Add request for certificate
12///
13/// 凭证添加请求
14#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
15pub struct RbumCertAddReq {
16 /// Certification access key
17 ///
18 /// 凭证名
19 ///
20 /// see [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::ak_rule`]
21 #[oai(validator(min_length = "2", max_length = "2000"))]
22 pub ak: TrimString,
23 /// Certification secret key
24 ///
25 /// 凭证密钥
26 ///
27 /// see [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::sk_rule`]
28 #[oai(validator(min_length = "2", max_length = "10000"))]
29 pub sk: Option<TrimString>,
30 /// Whether to hide the sk
31 ///
32 /// 是否隐藏密钥
33 ///
34 /// Default is ``false``
35 ///
36 /// 默认为 ``false``
37 ///
38 /// In some scenarios with high security requirements, you can choose to hide the key, such as: display as "******".
39 ///
40 /// 在一些安全性要求较高的场景下,可以选择隐藏密钥,如:显示为“******”。
41 pub sk_invisible: Option<bool>,
42 /// Whether to ignore the key check
43 ///
44 /// 是否忽略密钥校验
45 ///
46 /// WARNING: This field is only for special scenarios, please use it with caution.
47 ///
48 /// 警告:此字段仅用于特殊场景,请谨慎使用。
49 pub ignore_check_sk: bool,
50 /// Certificate type
51 ///
52 /// 凭证类型
53 ///
54 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::kind`], when this data exists, it indicates that the certificate does not need to be associated with the certificate configuration.
55 ///
56 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::kind`] 不同,当存在此数据时表明该凭证不用关联凭证配置。
57 pub kind: Option<String>,
58 /// Certificate supplier
59 ///
60 /// 凭证供应商
61 ///
62 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::supplier`], when this data exists, it indicates that the certificate does not need to be associated with the certificate configuration.
63 ///
64 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::supplier`] 不同,当存在此数据时表明该凭证不用关联凭证配置。
65 pub supplier: Option<String>,
66 /// Certificate extension information
67 ///
68 /// 凭证扩展信息
69 ///
70 /// Such as database connection pool configuration.
71 ///
72 /// 比如数据库连接池配置。
73 ///
74 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::ext`], this field is used to identify the specific extension information of the certificate.
75 ///
76 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::ext`] 不同,此字段用于标识该条凭证的特有的扩展信息。
77 #[oai(validator(min_length = "2", max_length = "2000"))]
78 pub ext: Option<String>,
79 /// Certificate effective time
80 ///
81 /// Default is ``Current time``
82 ///
83 /// 默认为 ``当前时间``
84 ///
85 /// 凭证的生效时间
86 pub start_time: Option<DateTime<Utc>>,
87 /// Certificate expiration time
88 ///
89 /// When associated with [certificate configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp), it defaults to ``start_time + expiration time of the certificate configuration``,
90 /// otherwise it defaults to ``start_time + 100 years``.
91 ///
92 /// 当关联了 [凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) 时,默认为 ``start_time + 凭证配置的过期时间``, 否则默认为 ``start_time + 100年``。
93 ///
94 /// NOTE: When associated with [certificate configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) and ``is dynamic sk``, it defaults to ``start_time + 100 years``.
95 ///
96 /// NOTE: 当关联了 [凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) 且 ``为动态sk时`` 默认为 ``start_time + 100年``
97 pub end_time: Option<DateTime<Utc>>,
98 /// Certificate connection address
99 ///
100 /// 凭证连接地址
101 ///
102 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::conn_uri`], this field is used to identify the specific connection address of the certificate.
103 ///
104 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::conn_uri`] 不同,此字段用于标识该条凭证的特有的连接地址。
105 #[oai(validator(min_length = "2", max_length = "2000"))]
106 pub conn_uri: Option<String>,
107 /// Credential status
108 ///
109 /// 凭证的状态
110 pub status: RbumCertStatusKind,
111
112 /// Dynamic sk(verification code)
113 ///
114 /// 动态sk(验证码)
115 ///
116 /// NOTE: Only valid when [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::sk_dynamic`] is ``true``.
117 ///
118 /// NOTE: This field cannot exist with the ``sk`` field at the same time.
119 ///
120 /// NOTE: 仅当 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::sk_dynamic`] 为 ``true`` 时有效。
121 ///
122 /// NOTE: 此字段不可与 ``sk`` 字段同时存在。
123 #[oai(validator(min_length = "2", max_length = "2000"))]
124 pub vcode: Option<TrimString>,
125
126 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) id
127 ///
128 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)id
129 #[oai(validator(min_length = "2", max_length = "255"))]
130 pub rel_rbum_cert_conf_id: Option<String>,
131 /// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
132 ///
133 /// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
134 pub rel_rbum_kind: RbumCertRelKind,
135 /// Associated resource id
136 ///
137 /// 关联的资源id
138 ///
139 /// # examples:
140 ///
141 /// * if rel_rbum_kind == Item
142 /// - rel_rbum_id same as the rel_rbum_item_id of cert configuration:E.g. Gitlab token
143 /// - rel_rbum_id different as the rel_rbum_item_id of cert configuration:E.g. User password (the cert configuration is bound to the tenant, and the cert instance corresponds to the user)
144 ///
145 /// * if rel_rbum_kind == Set
146 /// - E.g. In the Plug-in service, it can be bound to the plug-in instance library
147 ///
148 /// * if rel_rbum_kind == Rel
149 /// - In the CMDB service, a resource can be sliced (E.g. DB instance), we can specify slice information of association
150 ///
151 /// # 使用示例:
152 ///
153 /// * 如果 rel_rbum_kind == Item
154 /// - rel_rbum_id 与 cert configuration 的 rel_rbum_item_id 相同:比如 Gitlab token
155 /// - rel_rbum_id 与 cert configuration 的 rel_rbum_item_id 不同:比如 用户密码(cert configuration 绑定租户,cert 实例对应用户)
156 ///
157 /// * 如果 rel_rbum_kind == Set
158 /// - 比如在插件服务中,可以绑定到插件实例库
159 ///
160 /// * 如果 rel_rbum_kind == Rel
161 /// - 在 CMDB 服务中,一个资源可以被切片(比如 DB 实例),我们可以指定关联的切片信息
162 #[oai(validator(min_length = "2", max_length = "255"))]
163 pub rel_rbum_id: String,
164 /// Whether ``rel_rbum_id`` is an external value
165 ///
166 /// ``rel_rbum_id`` 是否是外部值
167 ///
168 /// If ``true``, ignore the scope check for ``rel_rbum_id``.
169 ///
170 /// 当为 ``true`` 时忽略对 ``rel_rbum_id`` 的作用域检查.
171 pub is_outside: bool,
172}
173
174/// Modify request for certificate
175///
176/// 凭证修改请求
177#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object)]
178pub struct RbumCertModifyReq {
179 /// Certification access key
180 ///
181 /// 凭证名
182 ///
183 /// see [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfModifyReq::ak_rule`]
184 #[oai(validator(min_length = "2", max_length = "2000"))]
185 pub ak: Option<TrimString>,
186 /// Certification secret key
187 ///
188 /// 凭证密钥
189 ///
190 /// see [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfAddReq::sk_rule`]
191 #[oai(validator(min_length = "2", max_length = "10000"))]
192 pub sk: Option<TrimString>,
193 /// Whether to hide the sk
194 ///
195 /// 是否隐藏密钥
196 ///
197 /// In some scenarios with high security requirements, you can choose to hide the key, such as: display as "******".
198 ///
199 /// 在一些安全性要求较高的场景下,可以选择隐藏密钥,如:显示为“******”。
200 pub sk_invisible: Option<bool>,
201 /// Whether to ignore the key check
202 ///
203 /// 是否忽略密钥校验
204 ///
205 /// WARNING: This field is only for special scenarios, please use it with caution.
206 ///
207 /// 警告:此字段仅用于特殊场景,请谨慎使用。
208 pub ignore_check_sk: bool,
209 /// Certificate extension information
210 ///
211 /// 凭证扩展信息
212 ///
213 /// Such as database connection pool configuration.
214 ///
215 /// 比如数据库连接池配置。
216 ///
217 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfModifyReq::ext`], this field is used to identify the specific extension information of the certificate.
218 ///
219 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfModifyReq::ext`] 不同,此字段用于标识该条凭证的特有的扩展信息。
220 #[oai(validator(min_length = "2", max_length = "2000"))]
221 pub ext: Option<String>,
222 /// Certificate effective time
223 ///
224 /// 凭证的生效时间
225 pub start_time: Option<DateTime<Utc>>,
226 /// Certificate expiration time
227 ///
228 /// 凭证的失效时间
229 pub end_time: Option<DateTime<Utc>>,
230 /// Certificate connection address
231 ///
232 /// 凭证连接地址
233 ///
234 /// Different from [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfModifyReq::conn_uri`], this field is used to identify the specific connection address of the certificate.
235 ///
236 /// 与 [`crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfModifyReq::conn_uri`] 不同,此字段用于标识该条凭证的特有的连接地址。
237 #[oai(validator(min_length = "2", max_length = "2000"))]
238 pub conn_uri: Option<String>,
239 /// Credential status
240 ///
241 /// 凭证的状态
242 pub status: Option<RbumCertStatusKind>,
243}
244
245/// Certificate summary information
246///
247/// 凭证概要信息
248#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
249pub struct RbumCertSummaryResp {
250 /// Certification id
251 ///
252 /// 凭证id
253 pub id: String,
254 /// Certification access key
255 ///
256 /// 凭证名
257 pub ak: String,
258 /// Certificate type
259 ///
260 /// 凭证类型
261 pub kind: String,
262 /// Certificate supplier
263 ///
264 /// 凭证供应商
265 pub supplier: String,
266 /// Certificate extension information
267 ///
268 /// 凭证扩展信息
269 pub ext: String,
270 /// Certificate effective time
271 ///
272 /// 凭证的生效时间
273 pub start_time: DateTime<Utc>,
274 /// Certificate expiration time
275 ///
276 /// 凭证的失效时间
277 pub end_time: DateTime<Utc>,
278 /// Credential status
279 ///
280 /// 凭证的状态
281 pub status: RbumCertStatusKind,
282
283 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) id
284 ///
285 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)id
286 pub rel_rbum_cert_conf_id: Option<String>,
287 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) name
288 ///
289 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
290 pub rel_rbum_cert_conf_name: Option<String>,
291 /// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
292 ///
293 /// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
294 pub rel_rbum_kind: RbumCertRelKind,
295 /// Associated resource id
296 ///
297 /// 关联的资源id
298 pub rel_rbum_id: String,
299
300 pub own_paths: String,
301 pub owner: String,
302 pub create_time: DateTime<Utc>,
303 pub update_time: DateTime<Utc>,
304}
305
306/// Certificate summary information with secret key
307///
308/// 带有密钥的凭证概要信息
309#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
310pub struct RbumCertSummaryWithSkResp {
311 /// Certification id
312 ///
313 /// 凭证id
314 pub id: String,
315 /// Certification access key
316 ///
317 /// 凭证名
318 pub ak: String,
319 /// Certification secret key
320 ///
321 /// 凭证密钥
322 pub sk: String,
323 /// Whether to hide the sk
324 ///
325 /// 是否隐藏密钥
326 pub sk_invisible: bool,
327 /// Certificate type
328 ///
329 /// 凭证类型
330 pub kind: String,
331 /// Certificate supplier
332 ///
333 /// 凭证供应商
334 pub supplier: String,
335 /// Certificate extension information
336 ///
337 /// 凭证扩展信息
338 pub ext: String,
339 /// Certificate effective time
340 ///
341 /// 凭证的生效时间
342 pub start_time: DateTime<Utc>,
343 /// Certificate expiration time
344 ///
345 /// 凭证的失效时间
346 pub end_time: DateTime<Utc>,
347 /// Certificate connection address
348 ///
349 /// 凭证连接地址
350 pub conn_uri: String,
351 /// Credential status
352 ///
353 /// 凭证的状态
354 pub status: RbumCertStatusKind,
355
356 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) id
357 ///
358 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)id
359 pub rel_rbum_cert_conf_id: Option<String>,
360 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) name
361 ///
362 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
363 pub rel_rbum_cert_conf_name: Option<String>,
364 /// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
365 ///
366 /// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
367 pub rel_rbum_kind: RbumCertRelKind,
368 /// Associated resource id
369 ///
370 /// 关联的资源id
371 pub rel_rbum_id: String,
372
373 pub own_paths: String,
374 pub owner: String,
375 pub create_time: DateTime<Utc>,
376 pub update_time: DateTime<Utc>,
377}
378
379/// Certificate detail information
380///
381/// 凭证详细信息
382#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
383pub struct RbumCertDetailResp {
384 /// Certification id
385 ///
386 /// 凭证id
387 pub id: String,
388 /// Certification access key
389 ///
390 /// 凭证名
391 pub ak: String,
392 /// Whether to hide the sk
393 ///
394 /// 是否隐藏密钥
395 pub sk_invisible: bool,
396 /// Certificate type
397 ///
398 /// 凭证类型
399 pub kind: String,
400 /// Certificate supplier
401 ///
402 /// 凭证供应商
403 pub supplier: String,
404 /// Certificate extension information
405 ///
406 /// 凭证扩展信息
407 pub ext: String,
408 /// Certificate effective time
409 ///
410 /// 凭证的生效时间
411 pub start_time: DateTime<Utc>,
412 /// Certificate expiration time
413 ///
414 /// 凭证的失效时间
415 pub end_time: DateTime<Utc>,
416 /// Certificate connection address
417 ///
418 /// 凭证连接地址
419 pub conn_uri: String,
420 /// Credential status
421 ///
422 /// 凭证的状态
423 pub status: RbumCertStatusKind,
424
425 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) id
426 ///
427 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)id
428 pub rel_rbum_cert_conf_id: Option<String>,
429 /// Associated [cert configuration](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp) name
430 ///
431 /// 关联的[凭证配置](crate::rbum::dto::rbum_cert_conf_dto::RbumCertConfDetailResp)名称
432 pub rel_rbum_cert_conf_name: Option<String>,
433 /// Associated [resource kind](crate::rbum::rbum_enumeration::RbumCertRelKind)
434 ///
435 /// 关联的[资源类型](crate::rbum::rbum_enumeration::RbumCertRelKind)
436 pub rel_rbum_kind: RbumCertRelKind,
437 /// Associated resource id
438 ///
439 /// 关联的资源id
440 pub rel_rbum_id: String,
441
442 pub own_paths: String,
443 pub owner: String,
444 pub owner_name: Option<String>,
445 pub create_time: DateTime<Utc>,
446 pub update_time: DateTime<Utc>,
447}