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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::authentication_api::{self as api};
use antimatter_api::models::{
CapabilityDefinition, CapabilityDefinitionList, NewCapabilityDefinition,
};
impl Session {
/// Lists the capabilities for the session's domain.
///
/// # Returns
///
/// A `Result` vector of `CapabilityDefinitionList` containing the list of
/// capabilities.
pub fn list_capabilities(&mut self) -> Result<CapabilityDefinitionList, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_capabilities(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Get details about a specific capability in this session's domain.
///
/// # Arguments
///
/// * `name` - A &str containing the capability name to get.
///
/// # Returns
///
/// A `Result` containing the result `CapabilityDefinition` detailing the
/// capability.
pub fn get_capability(&mut self, name: &str) -> Result<CapabilityDefinition, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_get_capability(
&conf,
self.get_domain_id().as_str(),
name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Puts a capability for the session's domain.
///
/// # Arguments
///
/// * `name` - A &str containing the capability name to put.
/// * `summary` - A String containing the capability's summary.
/// * `description` - An Option<String> containing the capability's description.
/// * `unary` - A bool indicating whether the capability is unary.
/// * `create_only` - An Option<bool> indicating whether this request should be created only.
pub fn put_capability(
&mut self,
name: &str,
summary: String,
description: Option<String>,
unary: bool,
create_only: Option<bool>,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_put_capability(
&conf,
self.get_domain_id().as_str(),
name,
NewCapabilityDefinition {
unary,
summary,
description: description.unwrap_or_default(),
},
create_only,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Deletes a capability in the session's domain.
///
/// # Arguments
///
/// * `name` - A &str containing the capability name to delete.
pub fn delete_capability(&mut self, name: &str) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_capability(
&conf,
self.get_domain_id().as_str(),
name,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
}