livepeer_rs/accesscontrol/
api.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::errors;
use async_std;
use serde_json;

#[derive(Debug, Clone)]
pub struct AccessControlApi {
    pub client: crate::LivepeerClient,
    pub urls: crate::api::urls::LivepeerUrls,
}

impl crate::accesscontrol::AccessControl for AccessControlApi {
    fn list_signing_keys(&self) -> Result<serde_json::Value, errors::Error> {
        self._get_signing_keys()
    }
    fn create_signing_key(&self, name: String) -> Result<serde_json::Value, errors::Error> {
        self._create_signing_key(name)
    }
    fn delete_signing_key(&self, id: String) -> Result<serde_json::Value, errors::Error> {
        self._delete_signing_key(id)
    }
}

impl AccessControlApi {
    pub fn new(client: &crate::LivepeerClient) -> Self {
        AccessControlApi {
            client: client.clone(),
            urls: crate::api::urls::LivepeerUrls::new(),
        }
    }

    /// List all Signing keys
    ///
    pub fn _get_signing_keys(&self) -> Result<serde_json::Value, errors::Error> {
        crate::utils::SurfRequest::get(
            format!(
                "{}{}",
                self.client.config.host, self.urls.access_control.signing_key
            ),
            self.client.clone(),
        )
    }

    pub fn _create_signing_key(
        &self,
        name: String,
    ) -> Result<serde_json::Value, errors::Error> {
        crate::utils::SurfRequest::post(
            format!(
                "{}{}",
                self.client.config.host, self.urls.access_control.signing_key
            ),
            serde_json::json!({ "name": name }).to_string(),
            self.client.clone(),
        )
    }

    pub fn _delete_signing_key(&self, id: String) -> Result<serde_json::Value, errors::Error> {
        crate::utils::SurfRequest::delete(
            format!(
                "{}{}/{}",
                self.client.config.host, self.urls.access_control.signing_key, id
            ),
            self.client.clone(),
        )
    }
}