use serde::Serialize;
use serde_with::{
base64::{Base64, Standard},
formats::Padded,
serde_as,
};
use super::Tunnel;
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
#[derive(Debug)]
pub struct CreateTunnel<'a> {
pub account_identifier: &'a str,
pub params: Params<'a>,
}
impl EndpointSpec for CreateTunnel<'_> {
type JsonResponse = Tunnel;
type ResponseType = ApiSuccess<Tunnel>;
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
format!("accounts/{}/tunnels", self.account_identifier)
}
#[inline]
fn body(&self) -> Option<RequestBody> {
let body = serde_json::to_string(&self.params).unwrap();
Some(RequestBody::Json(body))
}
}
#[serde_as]
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug)]
pub struct Params<'a> {
pub name: &'a str,
#[serde_as(as = "Base64<Standard, Padded>")]
pub tunnel_secret: &'a Vec<u8>,
pub metadata: Option<serde_json::Value>,
}