async_openai/admin/
project_group_roles.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::admin::{
5 groups::{GroupRoleAssignment, PublicAssignOrganizationGroupRoleBody},
6 roles::{AssignedRoleDetails, DeletedRoleAssignmentResource, RoleListResource},
7 },
8 Client, RequestOptions,
9};
10
11pub struct ProjectGroupRoles<'c, C: Config> {
13 client: &'c Client<C>,
14 pub project_id: String,
15 pub group_id: String,
16 pub(crate) request_options: RequestOptions,
17}
18
19impl<'c, C: Config> ProjectGroupRoles<'c, C> {
20 pub fn new(client: &'c Client<C>, project_id: &str, group_id: &str) -> Self {
21 Self {
22 client,
23 project_id: project_id.into(),
24 group_id: group_id.into(),
25 request_options: RequestOptions::new(),
26 }
27 }
28
29 #[crate::byot(R = serde::de::DeserializeOwned)]
31 pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
32 self.client
33 .get(
34 format!(
35 "/projects/{}/groups/{}/roles",
36 self.project_id, self.group_id
37 )
38 .as_str(),
39 &self.request_options,
40 )
41 .await
42 }
43
44 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
46 pub async fn assign(
47 &self,
48 request: PublicAssignOrganizationGroupRoleBody,
49 ) -> Result<GroupRoleAssignment, OpenAIError> {
50 self.client
51 .post(
52 format!(
53 "/projects/{}/groups/{}/roles",
54 self.project_id, self.group_id
55 )
56 .as_str(),
57 request,
58 &self.request_options,
59 )
60 .await
61 }
62
63 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
65 pub async fn unassign(
66 &self,
67 role_id: &str,
68 ) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
69 self.client
70 .delete(
71 format!(
72 "/projects/{}/groups/{}/roles/{}",
73 self.project_id, self.group_id, role_id
74 )
75 .as_str(),
76 &self.request_options,
77 )
78 .await
79 }
80
81 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
83 pub async fn retrieve(&self, role_id: &str) -> Result<AssignedRoleDetails, OpenAIError> {
84 self.client
85 .get(
86 &format!(
87 "/projects/{project_id}/groups/{group_id}/roles/{role_id}",
88 project_id = self.project_id,
89 group_id = self.group_id
90 ),
91 &self.request_options,
92 )
93 .await
94 }
95}