covert_sdk/
entity.rs

1use std::sync::Arc;
2
3pub use covert_types::entity::EntityAlias;
4use covert_types::methods::system::ListEntitiesResponse;
5pub use covert_types::methods::system::{
6    AttachEntityAliasParams, AttachEntityAliasResponse, AttachEntityPolicyParams,
7    AttachEntityPolicyResponse, CreateEntityParams, CreateEntityResponse, RemoveEntityAliasParams,
8    RemoveEntityAliasResponse, RemoveEntityPolicyParams, RemoveEntityPolicyResponse,
9};
10
11use crate::base::BaseClient;
12
13pub struct Client {
14    client: Arc<BaseClient>,
15}
16
17impl Client {
18    pub(crate) fn new(client: Arc<BaseClient>) -> Self {
19        Self { client }
20    }
21
22    pub async fn create(
23        &self,
24        params: &CreateEntityParams,
25    ) -> Result<CreateEntityResponse, String> {
26        self.client.post("/sys/entity".into(), params).await
27    }
28
29    pub async fn attach_policies(
30        &self,
31        params: &AttachEntityPolicyParams,
32    ) -> Result<AttachEntityPolicyResponse, String> {
33        self.client.put("/sys/entity/policy".into(), params).await
34    }
35
36    pub async fn remove_policy(
37        &self,
38        name: &str,
39        params: &RemoveEntityPolicyParams,
40    ) -> Result<RemoveEntityPolicyResponse, String> {
41        self.client
42            .put(format!("/sys/entity/policy/{name}"), params)
43            .await
44    }
45
46    pub async fn attach_alias(
47        &self,
48        params: &AttachEntityAliasParams,
49    ) -> Result<AttachEntityAliasResponse, String> {
50        self.client.put("/sys/entity/alias".into(), params).await
51    }
52
53    pub async fn remove_alias(
54        &self,
55        name: &str,
56        params: &RemoveEntityAliasParams,
57    ) -> Result<RemoveEntityAliasResponse, String> {
58        self.client
59            .put(format!("/sys/entity/alias/{name}"), params)
60            .await
61    }
62
63    pub async fn list(&self) -> Result<ListEntitiesResponse, String> {
64        self.client.get("/sys/entity".into()).await
65    }
66}