mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Register indpendent service token
This commit is contained in:
42
src/helpers/independent_push_notification_service_helper.rs
Normal file
42
src/helpers/independent_push_notification_service_helper.rs
Normal file
@ -0,0 +1,42 @@
|
||||
//! # Independent push notification service
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
|
||||
use actix_web::http::HeaderValue;
|
||||
use reqwest::blocking::Client;
|
||||
use reqwest::header::HeaderMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::data::config::{conf, IndependentPushService};
|
||||
use crate::data::error::{ExecError, Res};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CreateTokenResult {
|
||||
token: String
|
||||
}
|
||||
|
||||
fn svc_conf() -> Res<&'static IndependentPushService> {
|
||||
match &conf().independent_push_service {
|
||||
Some(c) => Ok(c),
|
||||
None => Err(ExecError::boxed_new("Missing push configuration!")),
|
||||
}
|
||||
}
|
||||
|
||||
fn create_client() -> Res<Client> {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("token", HeaderValue::from_str(&svc_conf()?.control_token.clone())?);
|
||||
Ok(Client::builder().default_headers(headers).build()?)
|
||||
}
|
||||
|
||||
/// Create a new client token
|
||||
pub fn create_token() -> Res<String> {
|
||||
let client = create_client()?
|
||||
.get(&format!("{}{}", svc_conf()?.control_url, "create_client"))
|
||||
.send()?;
|
||||
|
||||
|
||||
let response: CreateTokenResult = client.json()?;
|
||||
|
||||
Ok(response.token)
|
||||
}
|
@ -17,4 +17,5 @@ pub mod notifications_helper;
|
||||
pub mod webapp_helper;
|
||||
pub mod requests_limit_helper;
|
||||
pub mod events_helper;
|
||||
pub mod calls_helper;
|
||||
pub mod calls_helper;
|
||||
pub mod independent_push_notification_service_helper;
|
Reference in New Issue
Block a user