covert_sdk/
psql.rs

1use std::{sync::Arc, time::Duration};
2
3use covert_types::methods::psql::CreateRoleCredsParams;
4pub use covert_types::methods::psql::{
5    CreateRoleCredsResponse, CreateRoleParams, CreateRoleResponse, ReadConnectionResponse,
6    SetConnectionParams, SetConnectionResponse,
7};
8
9use crate::{base::BaseClient, utils::get_mount_path};
10
11pub struct Client {
12    client: Arc<BaseClient>,
13}
14
15impl Client {
16    pub(crate) fn new(client: Arc<BaseClient>) -> Self {
17        Self { client }
18    }
19
20    pub async fn set_connection(
21        &self,
22        mount: &str,
23        params: &SetConnectionParams,
24    ) -> Result<SetConnectionResponse, String> {
25        let path = get_mount_path(mount, "config/connection");
26        self.client.post(path, params).await
27    }
28
29    pub async fn read_connection(&self, mount: &str) -> Result<ReadConnectionResponse, String> {
30        let path = get_mount_path(mount, "config/connection");
31        self.client.get(path).await
32    }
33
34    pub async fn create_credentials(
35        &self,
36        mount: &str,
37        name: &str,
38        ttl: Option<Duration>,
39    ) -> Result<CreateRoleCredsResponse, String> {
40        let path = get_mount_path(mount, &format!("creds/{name}"));
41        self.client.put(path, &CreateRoleCredsParams { ttl }).await
42    }
43
44    pub async fn create_role(
45        &self,
46        mount: &str,
47        name: &str,
48        params: &CreateRoleParams,
49    ) -> Result<CreateRoleResponse, String> {
50        let path = get_mount_path(mount, &format!("roles/{name}"));
51        self.client.post(path, params).await
52    }
53}