1use crate::{
2 config::Config,
3 error::OpenAIError,
4 project_api_keys::ProjectAPIKeys,
5 project_certificates::ProjectCertificates,
6 project_group_roles::ProjectGroupRoles,
7 project_groups::ProjectGroups,
8 project_rate_limits::ProjectRateLimits,
9 project_roles::ProjectRoles,
10 project_user_roles::ProjectUserRoles,
11 types::admin::projects::{
12 Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest,
13 },
14 Client, ProjectServiceAccounts, ProjectUsers, RequestOptions,
15};
16
17pub struct Projects<'c, C: Config> {
20 client: &'c Client<C>,
21 pub(crate) request_options: RequestOptions,
22}
23
24impl<'c, C: Config> Projects<'c, C> {
25 pub fn new(client: &'c Client<C>) -> Self {
26 Self {
27 client,
28 request_options: RequestOptions::new(),
29 }
30 }
31
32 pub fn users(&self, project_id: &str) -> ProjectUsers<'_, C> {
34 ProjectUsers::new(self.client, project_id)
35 }
36
37 pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<'_, C> {
39 ProjectServiceAccounts::new(self.client, project_id)
40 }
41
42 pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<'_, C> {
44 ProjectAPIKeys::new(self.client, project_id)
45 }
46
47 pub fn rate_limits(&self, project_id: &str) -> ProjectRateLimits<'_, C> {
49 ProjectRateLimits::new(self.client, project_id)
50 }
51
52 pub fn certificates(&self, project_id: &str) -> ProjectCertificates<'_, C> {
54 ProjectCertificates::new(self.client, project_id)
55 }
56
57 pub fn groups(&self, project_id: &str) -> ProjectGroups<'_, C> {
59 ProjectGroups::new(self.client, project_id)
60 }
61
62 pub fn roles(&self, project_id: &str) -> ProjectRoles<'_, C> {
64 ProjectRoles::new(self.client, project_id)
65 }
66
67 pub fn user_roles(&self, project_id: &str, user_id: &str) -> ProjectUserRoles<'_, C> {
69 ProjectUserRoles::new(self.client, project_id, user_id)
70 }
71
72 pub fn group_roles(&self, project_id: &str, group_id: &str) -> ProjectGroupRoles<'_, C> {
74 ProjectGroupRoles::new(self.client, project_id, group_id)
75 }
76
77 #[crate::byot(R = serde::de::DeserializeOwned)]
79 pub async fn list(&self) -> Result<ProjectListResponse, OpenAIError> {
80 self.client
81 .get("/organization/projects", &self.request_options)
82 .await
83 }
84
85 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
87 pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
88 self.client
89 .post("/organization/projects", request, &self.request_options)
90 .await
91 }
92
93 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
95 pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
96 self.client
97 .get(
98 format!("/organization/projects/{project_id}").as_str(),
99 &self.request_options,
100 )
101 .await
102 }
103
104 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
106 pub async fn modify(
107 &self,
108 project_id: String,
109 request: ProjectUpdateRequest,
110 ) -> Result<Project, OpenAIError> {
111 self.client
112 .post(
113 format!("/organization/projects/{project_id}").as_str(),
114 request,
115 &self.request_options,
116 )
117 .await
118 }
119
120 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
122 pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
123 self.client
124 .post(
125 format!("/organization/projects/{project_id}/archive").as_str(),
126 (),
127 &self.request_options,
128 )
129 .await
130 }
131}