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
108
109
110
111
112
113
114
115
116
117
118
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::policy_api::{self as api};
use antimatter_api::models::{DomainPolicy, DomainPolicyRule, NewDomainPolicyRule};
use serde_json::Value;
impl Session {
/// Creates a new policy rule for the session's domain.
///
/// Arguments:
///
/// * `domain_policy_rule` - A NewDomainPolicyRule containing the policy
/// rule's configuration.
///
/// Returns:
///
/// A `Result` containing a `DomainPolicyRule` with the information
/// confirming creation of the policy rule.
pub fn create_policy_rule(
&mut self,
domain_policy_rule: NewDomainPolicyRule,
) -> Result<DomainPolicyRule, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_create_policy_rule(
&conf,
self.get_domain_id().as_str(),
domain_policy_rule,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Delete a policy rule from the session's domain.
///
/// Arguments:
///
/// * `rule_id` - A &str containing the policy rule's ID.
pub fn delete_policy_rule(&mut self, rule_id: &str) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_delete_policy_rule(
&conf,
self.get_domain_id().as_str(),
rule_id,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Fetches a list of policy rules for the session's domain.
///
/// Returns:
///
/// A `Result` containing a `DomainPolicy` with a vector of policy rules.
pub fn list_policy_rules(&mut self) -> Result<DomainPolicy, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_list_policy_rules(
&conf,
self.get_domain_id().as_str(),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
/// Update a policy rule in the session's domain.
///
/// Arguments:
///
/// * `rule_id` - A &str containing the policy rule's ID.
/// * `domain_policy_rule` - A NewDomainPolicyRule containing the policy
/// rule's configuration.
pub fn update_policy_rule(
&mut self,
rule_id: &str,
domain_policy_rule: NewDomainPolicyRule,
) -> Result<(), SessionError> {
let conf = self.get_configuration()?;
RUNTIME
.block_on(api::domain_update_policy_rule(
&conf,
self.get_domain_id().as_str(),
rule_id,
domain_policy_rule,
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(())
}
/// Renumbers all policy rules in the session's domain.
///
/// Returns:
///
/// A `Result` containing a `DomainPolicy` with a vector of policy rules.
pub fn renumber_policy_rules(&mut self) -> Result<DomainPolicy, SessionError> {
let conf = self.get_configuration()?;
let res = RUNTIME
.block_on(api::domain_renumber_policy_rules(
&conf,
self.get_domain_id().as_str(),
Some(Value::Object(Default::default())),
))
.map_err(|e| SessionError::APIError(format!("{}", e)))?;
Ok(res)
}
}