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        license_key: &str,
29    ) -> impl Future<Output = Result<gateway_licenses::VerifyResponse, Error>> + Send + Sync {
30        async move {
31            let request = gateway_licenses::Verify {
32                license_key: license_key.to_string(),
33            };
34            let uri = self.path_to_url("gateway-licenses/verify")?;
35            self.post_deserialize(uri, request).await
36        }
37    }
38
39    fn regenerate_gateway_license(
40        &self,
41        id: u32,
42    ) -> impl Future<Output = Result<gateway_licenses::RegenerateResponse, Error>> + Send + Sync
43    {
44        async move {
45            let uri = self.path_to_url(format!("gateway-licenses/{id}/regenerate"))?;
46            self.post_deserialize(uri, serde_json::json!({})).await
47        }
48    }
49}
50
51impl<T> GatewayApi for T where T: Api {}