async_openai/admin/
project_certificates.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::certificates::{ListCertificatesResponse, ToggleCertificatesRequest},
5    Client, RequestOptions,
6};
7
8/// Manage certificates for a given project. Supports listing, activating, and deactivating certificates.
9pub struct ProjectCertificates<'c, C: Config> {
10    client: &'c Client<C>,
11    pub project_id: String,
12    pub(crate) request_options: RequestOptions,
13}
14
15impl<'c, C: Config> ProjectCertificates<'c, C> {
16    pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
17        Self {
18            client,
19            project_id: project_id.into(),
20            request_options: RequestOptions::new(),
21        }
22    }
23
24    /// List all certificates for this project.
25    pub async fn list(&self) -> Result<ListCertificatesResponse, OpenAIError> {
26        self.client
27            .get(
28                format!("/organization/projects/{}/certificates", self.project_id).as_str(),
29                &self.request_options,
30            )
31            .await
32    }
33
34    /// Activate certificates for this project.
35    /// You can atomically and idempotently activate up to 10 certificates at a time.
36    pub async fn activate(
37        &self,
38        request: ToggleCertificatesRequest,
39    ) -> Result<ListCertificatesResponse, OpenAIError> {
40        self.client
41            .post(
42                format!(
43                    "/organization/projects/{}/certificates/activate",
44                    self.project_id
45                )
46                .as_str(),
47                request,
48                &self.request_options,
49            )
50            .await
51    }
52
53    /// Deactivate certificates for this project.
54    /// You can atomically and idempotently deactivate up to 10 certificates at a time.
55    pub async fn deactivate(
56        &self,
57        request: ToggleCertificatesRequest,
58    ) -> Result<ListCertificatesResponse, OpenAIError> {
59        self.client
60            .post(
61                format!(
62                    "/organization/projects/{}/certificates/deactivate",
63                    self.project_id
64                )
65                .as_str(),
66                request,
67                &self.request_options,
68            )
69            .await
70    }
71}