freedom_api/
gateway_licenses.rs

1use freedom_models::gateway_licenses;
2
3use crate::{Api, error::Error};
4
5/// Extension API for interacting with the Freedom Gateway licensing architecture
6pub trait GatewayApi: Api {
7    fn get_all_gateway_licenses(
8        &self,
9    ) -> impl Future<Output = Result<gateway_licenses::View, Error>> + Send + Sync {
10        async move {
11            let uri = self.path_to_url("gateway-licenses")?;
12            self.get_json_map(uri).await
13        }
14    }
15
16    fn get_all_gateway_license(
17        &self,
18        id: u32,
19    ) -> impl Future<Output = Result<gateway_licenses::ViewOne, Error>> + Send + Sync {
20        async move {
21            let uri = self.path_to_url(format!("gateway-licenses/{id}"))?;
22            self.get_json_map(uri).await
23        }
24    }
25
26    fn verify_gateway_license(
27        &self,
28        request: gateway_licenses::Verify,
29    ) -> impl Future<Output = Result<gateway_licenses::VerifyResponse, Error>> + Send + Sync {
30        async move {
31            let uri = self.path_to_url("gateway-licenses/verify")?;
32            self.post_deserialize(uri, request).await
33        }
34    }
35
36    fn regenerate_gateway_license(
37        &self,
38        id: u32,
39    ) -> impl Future<Output = Result<gateway_licenses::RegenerateResponse, Error>> + Send + Sync
40    {
41        async move {
42            let uri = self.path_to_url(format!("gateway-licenses/{id}/regenerate"))?;
43            self.post_deserialize(uri, serde_json::json!({})).await
44        }
45    }
46}
47
48impl<T> GatewayApi for T where T: Api {}