Skip to content

Commit dc5d67a

Browse files
committed
add group and role management apis
1 parent 6013669 commit dc5d67a

File tree

18 files changed

+1146
-3
lines changed

18 files changed

+1146
-3
lines changed

async-openai/src/admin.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::{
22
admin_api_keys::AdminAPIKeys, audit_logs::AuditLogs, certificates::Certificates,
3-
config::Config, invites::Invites, projects::Projects, users::Users, Client,
3+
config::Config, groups::Groups, invites::Invites, projects::Projects, roles::Roles,
4+
users::Users, Client,
45
};
56

67
/// Admin group for all administration APIs.
7-
/// This groups together admin API keys, invites, users, projects, audit logs, and certificates.
8+
/// This groups together admin API keys, invites, users, projects, audit logs, certificates, roles, and groups.
89
pub struct Admin<'c, C: Config> {
910
client: &'c Client<C>,
1011
}
@@ -43,4 +44,14 @@ impl<'c, C: Config> Admin<'c, C> {
4344
pub fn certificates(&self) -> Certificates<'_, C> {
4445
Certificates::new(self.client)
4546
}
47+
48+
/// To call [Roles] group related APIs using this client.
49+
pub fn roles(&self) -> Roles<'_, C> {
50+
Roles::new(self.client)
51+
}
52+
53+
/// To call [Groups] group related APIs using this client.
54+
pub fn groups(&self) -> Groups<'_, C> {
55+
Groups::new(self.client)
56+
}
4657
}

async-openai/src/group_roles.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::{
2+
config::Config,
3+
error::OpenAIError,
4+
types::admin::groups::{
5+
GroupRoleAssignment, PublicAssignOrganizationGroupRoleBody,
6+
},
7+
types::admin::roles::{DeletedRoleAssignmentResource, RoleListResource},
8+
Client, RequestOptions,
9+
};
10+
11+
/// Manage role assignments for groups in the organization.
12+
pub struct GroupRoles<'c, C: Config> {
13+
client: &'c Client<C>,
14+
pub group_id: String,
15+
pub(crate) request_options: RequestOptions,
16+
}
17+
18+
impl<'c, C: Config> GroupRoles<'c, C> {
19+
pub fn new(client: &'c Client<C>, group_id: &str) -> Self {
20+
Self {
21+
client,
22+
group_id: group_id.into(),
23+
request_options: RequestOptions::new(),
24+
}
25+
}
26+
27+
/// Lists all role assignments for a group.
28+
#[crate::byot(R = serde::de::DeserializeOwned)]
29+
pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
30+
self.client
31+
.get(
32+
format!("/organization/groups/{}/roles", self.group_id).as_str(),
33+
&self.request_options,
34+
)
35+
.await
36+
}
37+
38+
/// Assigns a role to a group.
39+
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
40+
pub async fn assign(
41+
&self,
42+
request: PublicAssignOrganizationGroupRoleBody,
43+
) -> Result<GroupRoleAssignment, OpenAIError> {
44+
self.client
45+
.post(
46+
format!("/organization/groups/{}/roles", self.group_id).as_str(),
47+
request,
48+
&self.request_options,
49+
)
50+
.await
51+
}
52+
53+
/// Unassigns a role from a group.
54+
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
55+
pub async fn unassign(&self, role_id: &str) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
56+
self.client
57+
.delete(
58+
format!("/organization/groups/{}/roles/{}", self.group_id, role_id).as_str(),
59+
&self.request_options,
60+
)
61+
.await
62+
}
63+
}
64+

async-openai/src/group_users.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use crate::{
2+
config::Config,
3+
error::OpenAIError,
4+
types::admin::groups::{
5+
CreateGroupUserBody, GroupUserAssignment, GroupUserDeletedResource, UserListResource,
6+
},
7+
Client, RequestOptions,
8+
};
9+
10+
/// Manage users within a group, including adding and removing users.
11+
pub struct GroupUsers<'c, C: Config> {
12+
client: &'c Client<C>,
13+
pub group_id: String,
14+
pub(crate) request_options: RequestOptions,
15+
}
16+
17+
impl<'c, C: Config> GroupUsers<'c, C> {
18+
pub fn new(client: &'c Client<C>, group_id: &str) -> Self {
19+
Self {
20+
client,
21+
group_id: group_id.into(),
22+
request_options: RequestOptions::new(),
23+
}
24+
}
25+
26+
/// Lists all users in a group.
27+
#[crate::byot(R = serde::de::DeserializeOwned)]
28+
pub async fn list(&self) -> Result<UserListResource, OpenAIError> {
29+
self.client
30+
.get(
31+
format!("/organization/groups/{}/users", self.group_id).as_str(),
32+
&self.request_options,
33+
)
34+
.await
35+
}
36+
37+
/// Adds a user to a group.
38+
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
39+
pub async fn add(
40+
&self,
41+
request: CreateGroupUserBody,
42+
) -> Result<GroupUserAssignment, OpenAIError> {
43+
self.client
44+
.post(
45+
format!("/organization/groups/{}/users", self.group_id).as_str(),
46+
request,
47+
&self.request_options,
48+
)
49+
.await
50+
}
51+
52+
/// Removes a user from a group.
53+
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
54+
pub async fn remove(&self, user_id: &str) -> Result<GroupUserDeletedResource, OpenAIError> {
55+
self.client
56+
.delete(
57+
format!("/organization/groups/{}/users/{user_id}", self.group_id).as_str(),
58+
&self.request_options,
59+
)
60+
.await
61+
}
62+
}

async-openai/src/groups.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use crate::{
2+
config::Config,
3+
error::OpenAIError,
4+
group_roles::GroupRoles,
5+
group_users::GroupUsers,
6+
types::admin::groups::{
7+
CreateGroupBody, GroupDeletedResource, GroupListResource, GroupResourceWithSuccess,
8+
GroupResponse,
9+
},
10+
Client, RequestOptions,
11+
};
12+
13+
/// Manage reusable collections of users for organization-wide access control and maintain their membership.
14+
pub struct Groups<'c, C: Config> {
15+
client: &'c Client<C>,
16+
pub(crate) request_options: RequestOptions,
17+
}
18+
19+
impl<'c, C: Config> Groups<'c, C> {
20+
pub fn new(client: &'c Client<C>) -> Self {
21+
Self {
22+
client,
23+
request_options: RequestOptions::new(),
24+
}
25+
}
26+
27+
/// To call [GroupUsers] group related APIs using this client.
28+
pub fn users(&self, group_id: &str) -> GroupUsers<'_, C> {
29+
GroupUsers::new(self.client, group_id)
30+
}
31+
32+
/// To call [GroupRoles] group related APIs using this client.
33+
pub fn roles(&self, group_id: &str) -> GroupRoles<'_, C> {
34+
GroupRoles::new(self.client, group_id)
35+
}
36+
37+
/// Lists all groups in the organization.
38+
#[crate::byot(R = serde::de::DeserializeOwned)]
39+
pub async fn list(&self) -> Result<GroupListResource, OpenAIError> {
40+
self.client
41+
.get("/organization/groups", &self.request_options)
42+
.await
43+
}
44+
45+
/// Creates a new group in the organization.
46+
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
47+
pub async fn create(&self, request: CreateGroupBody) -> Result<GroupResponse, OpenAIError> {
48+
self.client
49+
.post("/organization/groups", request, &self.request_options)
50+
.await
51+
}
52+
53+
/// Updates a group's information.
54+
#[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
55+
pub async fn update(
56+
&self,
57+
group_id: &str,
58+
request: crate::types::admin::groups::UpdateGroupBody,
59+
) -> Result<GroupResourceWithSuccess, OpenAIError> {
60+
self.client
61+
.post(
62+
format!("/organization/groups/{group_id}").as_str(),
63+
request,
64+
&self.request_options,
65+
)
66+
.await
67+
}
68+
69+
/// Deletes a group from the organization.
70+
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
71+
pub async fn delete(&self, group_id: &str) -> Result<GroupDeletedResource, OpenAIError> {
72+
self.client
73+
.delete(
74+
format!("/organization/groups/{group_id}").as_str(),
75+
&self.request_options,
76+
)
77+
.await
78+
}
79+
}

async-openai/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,29 @@ mod eval_runs;
164164
mod evals;
165165
mod file;
166166
mod fine_tuning;
167+
mod group_roles;
168+
mod group_users;
169+
mod groups;
167170
mod image;
168171
mod invites;
169172
mod messages;
170173
mod model;
171174
mod moderation;
172175
mod project_api_keys;
173176
mod project_certificates;
177+
mod project_group_roles;
178+
mod project_groups;
174179
mod project_rate_limits;
180+
mod project_roles;
175181
mod project_service_accounts;
182+
mod project_user_roles;
176183
mod project_users;
177184
mod projects;
178185
#[cfg(feature = "realtime")]
179186
mod realtime;
180187
mod request_options;
181188
mod responses;
189+
mod roles;
182190
mod runs;
183191
mod speech;
184192
mod steps;
@@ -189,6 +197,7 @@ mod translations;
189197
pub mod types;
190198
mod uploads;
191199
mod usage;
200+
mod user_roles;
192201
mod users;
193202
mod util;
194203
mod vector_store_file_batches;
@@ -219,21 +228,29 @@ pub use eval_runs::EvalRuns;
219228
pub use evals::Evals;
220229
pub use file::Files;
221230
pub use fine_tuning::FineTuning;
231+
pub use group_roles::GroupRoles;
232+
pub use group_users::GroupUsers;
233+
pub use groups::Groups;
222234
pub use image::Images;
223235
pub use invites::Invites;
224236
pub use messages::Messages;
225237
pub use model::Models;
226238
pub use moderation::Moderations;
227239
pub use project_api_keys::ProjectAPIKeys;
228240
pub use project_certificates::ProjectCertificates;
241+
pub use project_group_roles::ProjectGroupRoles;
242+
pub use project_groups::ProjectGroups;
229243
pub use project_rate_limits::ProjectRateLimits;
244+
pub use project_roles::ProjectRoles;
230245
pub use project_service_accounts::ProjectServiceAccounts;
246+
pub use project_user_roles::ProjectUserRoles;
231247
pub use project_users::ProjectUsers;
232248
pub use projects::Projects;
233249
#[cfg(feature = "realtime")]
234250
pub use realtime::Realtime;
235251
pub use request_options::RequestOptions;
236252
pub use responses::Responses;
253+
pub use roles::Roles;
237254
pub use runs::Runs;
238255
pub use speech::Speech;
239256
pub use steps::Steps;
@@ -242,6 +259,7 @@ pub use transcriptions::Transcriptions;
242259
pub use translations::Translations;
243260
pub use uploads::Uploads;
244261
pub use usage::Usage;
262+
pub use user_roles::UserRoles;
245263
pub use users::Users;
246264
pub use vector_store_file_batches::VectorStoreFileBatches;
247265
pub use vector_store_files::VectorStoreFiles;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
use crate::{
2+
config::Config,
3+
error::OpenAIError,
4+
types::admin::groups::{GroupRoleAssignment, PublicAssignOrganizationGroupRoleBody},
5+
types::admin::roles::{DeletedRoleAssignmentResource, RoleListResource},
6+
Client, RequestOptions,
7+
};
8+
9+
/// Manage role assignments for groups in a project.
10+
pub struct ProjectGroupRoles<'c, C: Config> {
11+
client: &'c Client<C>,
12+
pub project_id: String,
13+
pub group_id: String,
14+
pub(crate) request_options: RequestOptions,
15+
}
16+
17+
impl<'c, C: Config> ProjectGroupRoles<'c, C> {
18+
pub fn new(client: &'c Client<C>, project_id: &str, group_id: &str) -> Self {
19+
Self {
20+
client,
21+
project_id: project_id.into(),
22+
group_id: group_id.into(),
23+
request_options: RequestOptions::new(),
24+
}
25+
}
26+
27+
/// Lists all role assignments for a group in the project.
28+
#[crate::byot(R = serde::de::DeserializeOwned)]
29+
pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
30+
self.client
31+
.get(
32+
format!(
33+
"/projects/{}/groups/{}/roles",
34+
self.project_id, self.group_id
35+
)
36+
.as_str(),
37+
&self.request_options,
38+
)
39+
.await
40+
}
41+
42+
/// Assigns a role to a group in the project.
43+
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
44+
pub async fn assign(
45+
&self,
46+
request: PublicAssignOrganizationGroupRoleBody,
47+
) -> Result<GroupRoleAssignment, OpenAIError> {
48+
self.client
49+
.post(
50+
format!(
51+
"/projects/{}/groups/{}/roles",
52+
self.project_id, self.group_id
53+
)
54+
.as_str(),
55+
request,
56+
&self.request_options,
57+
)
58+
.await
59+
}
60+
61+
/// Unassigns a role from a group in the project.
62+
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
63+
pub async fn unassign(
64+
&self,
65+
role_id: &str,
66+
) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
67+
self.client
68+
.delete(
69+
format!(
70+
"/projects/{}/groups/{}/roles/{}",
71+
self.project_id, self.group_id, role_id
72+
)
73+
.as_str(),
74+
&self.request_options,
75+
)
76+
.await
77+
}
78+
}

0 commit comments

Comments
 (0)