structs: reorganize

Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-28 12:30:02 +02:00
parent bab21a9bae
commit 09879a3cee
2 changed files with 20 additions and 20 deletions

View file

@ -4,6 +4,8 @@ clients:
write_metrics: write_metrics:
- irradiance - irradiance
- temperature - temperature
read_metrics:
- weather.*
auth: auth:
type: sha256 type: sha256
hash: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb # a hash: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb # a
@ -32,16 +34,9 @@ clients:
auth: auth:
# ... # ...
# Anonymous login
- name: public_consumer
read_metrics:
- weather.*
auth:
type: anonymous
config: config:
opentsdb: opentsdb:
url: http://opentsdb/api/ url: http://192.168.30.2/api/
server: server:
port: 8080 port: 8080

View file

@ -16,33 +16,38 @@ struct ClientData {
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct QSParams { struct QPutParams {
token: String,
}
#[derive(Debug, Deserialize, Serialize)]
struct OtsdbPutData {
metric: String,
value: StringIntFloat,
timestamp: i64,
tags: HashMap<String, StringIntFloat>,
}
#[derive(Debug, Deserialize)]
struct QQueryParams {
token: String, token: String,
} }
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)] #[serde(untagged)]
enum OtsdbValue { enum StringIntFloat {
String(String), String(String),
Integer(i64), Integer(i64),
Float(f64), Float(f64),
} }
#[derive(Debug, Deserialize, Serialize)]
struct OtsdbData {
metric: String,
value: OtsdbValue,
timestamp: i64,
tags: HashMap<String, OtsdbValue>,
}
const CONFIG_FILE: &str = "config.yaml"; const CONFIG_FILE: &str = "config.yaml";
#[actix_web::post("/put")] #[actix_web::post("/put")]
async fn put_post( async fn put_post(
shared: web::Data<ClientData>, shared: web::Data<ClientData>,
qs: web::Query<QSParams>, qs: web::Query<QPutParams>,
body: web::Json<OtsdbData>, body: web::Json<OtsdbPutData>,
) -> impl Responder { ) -> impl Responder {
let authenticated_client = config::try_authenticate_client(&shared.cfg.clients, &qs.token); let authenticated_client = config::try_authenticate_client(&shared.cfg.clients, &qs.token);