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
119
120
121
122
123
//! Approval-delegation methods for [`IronflowClient`].
use uuid::Uuid;
use ironflow_types::ApiResponse;
use crate::client::{IronflowClient, ListApprovalDelegationsFilter};
use crate::error::Error;
use crate::types;
impl IronflowClient {
/// List the first page of the active approval delegations visible to the
/// caller.
///
/// # Errors
///
/// Returns an error if the HTTP request fails or the response cannot be deserialized.
///
/// # Examples
///
/// ```no_run
/// use ironflow_sdk::IronflowClient;
///
/// # async fn example() -> Result<(), ironflow_sdk::Error> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// let delegations = client.list_approval_delegations().await?;
/// # Ok(())
/// # }
/// ```
pub async fn list_approval_delegations(
&self,
) -> Result<ApiResponse<Vec<types::ApprovalDelegationResponse>>, Error> {
self.list_approval_delegations_filtered(&ListApprovalDelegationsFilter::default())
.await
}
/// List the active approval delegations visible to the caller, with
/// filters and pagination.
///
/// # Errors
///
/// Returns an error if the HTTP request fails or the response cannot be deserialized.
///
/// # Examples
///
/// ```no_run
/// use ironflow_sdk::IronflowClient;
/// use ironflow_sdk::client::ListApprovalDelegationsFilter;
///
/// # async fn example() -> Result<(), ironflow_sdk::Error> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// let filter = ListApprovalDelegationsFilter {
/// page: Some(2),
/// ..Default::default()
/// };
/// let delegations = client.list_approval_delegations_filtered(&filter).await?;
/// # Ok(())
/// # }
/// ```
pub async fn list_approval_delegations_filtered(
&self,
filter: &ListApprovalDelegationsFilter,
) -> Result<ApiResponse<Vec<types::ApprovalDelegationResponse>>, Error> {
self.send_envelope(self.get("/api/v1/approval-delegations").query(filter))
.await
}
/// Delegate the caller's approval power to another user.
///
/// # Errors
///
/// Returns an error if the HTTP request fails or the response cannot be deserialized.
///
/// # Examples
///
/// ```no_run
/// use chrono::{TimeDelta, Utc};
/// use ironflow_sdk::IronflowClient;
/// use ironflow_sdk::types::CreateApprovalDelegationRequest;
/// use uuid::Uuid;
///
/// # async fn example(bob: Uuid) -> Result<(), ironflow_sdk::Error> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// let delegation = client.create_approval_delegation(&CreateApprovalDelegationRequest {
/// to_user_id: bob,
/// valid_from: None,
/// valid_until: Utc::now() + TimeDelta::days(7),
/// workflow_filter: Some("deploy-*".to_string()),
/// }).await?;
/// # Ok(())
/// # }
/// ```
pub async fn create_approval_delegation(
&self,
request: &types::CreateApprovalDelegationRequest,
) -> Result<ApiResponse<types::ApprovalDelegationResponse>, Error> {
self.send_envelope(self.post("/api/v1/approval-delegations").json(request))
.await
}
/// Revoke an approval delegation by ID.
///
/// # Errors
///
/// Returns an error if the HTTP request fails.
///
/// # Examples
///
/// ```no_run
/// use ironflow_sdk::IronflowClient;
/// use uuid::Uuid;
///
/// # async fn example() -> Result<(), ironflow_sdk::Error> {
/// let client = IronflowClient::new("https://ironflow.example.com", "key");
/// client.delete_approval_delegation(Uuid::nil()).await?;
/// # Ok(())
/// # }
/// ```
pub async fn delete_approval_delegation(&self, id: Uuid) -> Result<(), Error> {
self.send_no_content(self.delete(&format!("/api/v1/approval-delegations/{id}")))
.await
}
}