siera_cloudagent_python/
agent.rs

1use reqwest::Url;
2use siera_agent::error::{Error, Result};
3
4/// Cloudagent Python Agent
5#[derive(Debug)]
6pub struct CloudAgentPython {
7    /// base url of the cloudagent
8    pub endpoint: String,
9
10    /// admin Api key for the cloudagent
11    pub api_key: Option<String>,
12
13    /// Authorization token for a multi tenancy agent
14    pub auth_token: Option<String>,
15
16    /// Agent version
17    pub version: CloudAgentPythonVersion,
18}
19
20/// ACA-Py supported versions
21/// TODO: How do we want to deal with mulitple versions? Architecture wise.
22#[derive(Debug)]
23pub enum CloudAgentPythonVersion {
24    /// ~0.7.3
25    ZeroSevenThree,
26}
27
28impl CloudAgentPython {
29    /// Create a new instance of an aries cloudagent python
30    #[must_use]
31    pub const fn new(
32        endpoint: String,
33        version: CloudAgentPythonVersion,
34        api_key: Option<String>,
35        auth_token: Option<String>,
36    ) -> Self {
37        Self {
38            endpoint,
39            api_key,
40            auth_token,
41            version,
42        }
43    }
44
45    /// Create a url based on the base url and a list of paths
46    ///
47    /// # Errors
48    ///
49    /// When the url could not be constructed
50    pub fn create_url(&self, paths: &[&str]) -> Result<Url> {
51        let mut url = Url::parse(&self.endpoint)
52            .map_err(|_| Box::new(Error::UnreachableUrl) as Box<dyn std::error::Error>)?;
53        url.set_path(&paths.join("/"));
54        Ok(url)
55    }
56}