privy_rs/subclients/
policies.rs1use super::ResponseValue;
2use crate::{
3 AuthorizationContext, PrivySignedApiError, generate_authorization_signatures,
4 generated::types::{Policy, UpdatePolicyBody, UpdatePolicyPolicyId},
5 subclients::PoliciesClient,
6};
7
8impl PoliciesClient {
9 pub async fn update<'a>(
17 &'a self,
18 policy_id: &'a UpdatePolicyPolicyId,
19 ctx: &'a AuthorizationContext,
20 body: &'a UpdatePolicyBody,
21 ) -> Result<ResponseValue<Policy>, PrivySignedApiError> {
22 let sig = generate_authorization_signatures(
23 ctx,
24 &self.app_id,
25 crate::Method::PATCH,
26 format!("{}/v1/policies/{}", self.base_url, policy_id.as_str()),
27 body,
28 None,
29 )
30 .await?;
31
32 Ok(self._update(policy_id, Some(&sig), body).await?)
33 }
34
35 pub async fn delete<'a>(
43 &'a self,
44 policy_id: &'a crate::generated::types::DeletePolicyPolicyId,
45 ctx: &'a AuthorizationContext,
46 ) -> Result<ResponseValue<crate::generated::types::DeletePolicyResponse>, PrivySignedApiError>
47 {
48 let sig = generate_authorization_signatures(
49 ctx,
50 &self.app_id,
51 crate::Method::DELETE,
52 format!("{}/v1/policies/{}", self.base_url, policy_id.as_str()),
53 &serde_json::json!({}),
54 None,
55 )
56 .await?;
57
58 Ok(self._delete(policy_id, Some(&sig)).await?)
59 }
60
61 pub async fn create_rule<'a>(
69 &'a self,
70 policy_id: &'a crate::generated::types::CreateRulePolicyId,
71 ctx: &'a AuthorizationContext,
72 body: &'a crate::generated::types::PolicyRuleRequestBody,
73 ) -> Result<ResponseValue<crate::generated::types::PolicyRuleResponse>, PrivySignedApiError>
74 {
75 let sig = generate_authorization_signatures(
76 ctx,
77 &self.app_id,
78 crate::Method::POST,
79 format!("{}/v1/policies/{}/rules", self.base_url, policy_id.as_str()),
80 body,
81 None,
82 )
83 .await?;
84
85 Ok(self._create_rule(policy_id, Some(&sig), body).await?)
86 }
87
88 pub async fn update_rule<'a>(
96 &'a self,
97 policy_id: &'a crate::generated::types::UpdateRulePolicyId,
98 rule_id: &'a crate::generated::types::UpdateRuleRuleId,
99 ctx: &'a AuthorizationContext,
100 body: &'a crate::generated::types::PolicyRuleRequestBody,
101 ) -> Result<ResponseValue<crate::generated::types::UpdateRuleResponse>, PrivySignedApiError>
102 {
103 let sig = generate_authorization_signatures(
104 ctx,
105 &self.app_id,
106 crate::Method::PATCH,
107 format!(
108 "{}/v1/policies/{}/rules/{}",
109 self.base_url,
110 policy_id.as_str(),
111 rule_id.as_str()
112 ),
113 body,
114 None,
115 )
116 .await?;
117
118 Ok(self
119 ._update_rule(policy_id, rule_id, Some(&sig), body)
120 .await?)
121 }
122
123 pub async fn delete_rule<'a>(
131 &'a self,
132 policy_id: &'a crate::generated::types::DeleteRulePolicyId,
133 rule_id: &'a crate::generated::types::DeleteRuleRuleId,
134 ctx: &'a AuthorizationContext,
135 ) -> Result<ResponseValue<crate::generated::types::DeleteRuleResponse>, PrivySignedApiError>
136 {
137 let sig = generate_authorization_signatures(
138 ctx,
139 &self.app_id,
140 crate::Method::DELETE,
141 format!(
142 "{}/v1/policies/{}/rules/{}",
143 self.base_url,
144 policy_id.as_str(),
145 rule_id.as_str()
146 ),
147 &serde_json::json!({}),
148 None,
149 )
150 .await?;
151
152 Ok(self._delete_rule(policy_id, rule_id, Some(&sig)).await?)
153 }
154}