-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
configs.rs
94 lines (87 loc) · 2.39 KB
/
configs.rs
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
use actix_web::{web, HttpRequest, Responder};
use router_env::{instrument, tracing, Flow};
use super::app::AppState;
use crate::{
core::{api_locking, configs},
services::{api, authentication as auth},
types::api as api_types,
};
#[instrument(skip_all, fields(flow = ?Flow::CreateConfigKey))]
pub async fn config_key_create(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<api_types::Config>,
) -> impl Responder {
let flow = Flow::CreateConfigKey;
let payload = json_payload.into_inner();
api::server_wrap(
flow,
state,
&req,
payload,
|state, _, data, _| configs::set_config(state, data),
&auth::AdminApiAuth,
api_locking::LockAction::NotApplicable,
)
.await
}
#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyFetch))]
pub async fn config_key_retrieve(
state: web::Data<AppState>,
req: HttpRequest,
path: web::Path<String>,
) -> impl Responder {
let flow = Flow::ConfigKeyFetch;
let key = path.into_inner();
api::server_wrap(
flow,
state,
&req,
&key,
|state, _, key, _| configs::read_config(state, key),
&auth::AdminApiAuth,
api_locking::LockAction::NotApplicable,
)
.await
}
#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyUpdate))]
pub async fn config_key_update(
state: web::Data<AppState>,
req: HttpRequest,
path: web::Path<String>,
json_payload: web::Json<api_types::ConfigUpdate>,
) -> impl Responder {
let flow = Flow::ConfigKeyUpdate;
let mut payload = json_payload.into_inner();
let key = path.into_inner();
payload.key = key;
api::server_wrap(
flow,
state,
&req,
&payload,
|state, _, payload, _| configs::update_config(state, payload),
&auth::AdminApiAuth,
api_locking::LockAction::NotApplicable,
)
.await
}
#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyDelete))]
pub async fn config_key_delete(
state: web::Data<AppState>,
req: HttpRequest,
path: web::Path<String>,
) -> impl Responder {
let flow = Flow::ConfigKeyDelete;
let key = path.into_inner();
api::server_wrap(
flow,
state,
&req,
key,
|state, _, key, _| configs::config_delete(state, key),
&auth::AdminApiAuth,
api_locking::LockAction::NotApplicable,
)
.await
}