use crate::endpoints::cfd_tunnel::Tunnel;
use serde::Serialize;
use serde_with::{
base64::{Base64, Standard},
formats::Padded,
serde_as,
};
use crate::framework::endpoint::{EndpointSpec, Method, RequestBody};
use crate::framework::response::ApiSuccess;
#[derive(Debug)]
pub struct UpdateTunnel<'a> {
pub account_identifier: &'a str,
pub tunnel_id: &'a str,
pub params: Params<'a>,
}
impl EndpointSpec for UpdateTunnel<'_> {
type JsonResponse = Tunnel;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::PATCH
}
fn path(&self) -> String {
format!(
"accounts/{}/cfd_tunnel/{}",
self.account_identifier, self.tunnel_id
)
}
#[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>,
}