Skip to main content

async_openai/admin/
certificates.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::certificates::{
5        Certificate, DeleteCertificateResponse, ListCertificatesResponse, ModifyCertificateRequest,
6        OrganizationCertificateActivationResponse, OrganizationCertificateDeactivationResponse,
7        ToggleCertificatesRequest, UploadCertificateRequest,
8    },
9    Client, RequestOptions,
10};
11
12/// Certificates enable Mutual TLS (mTLS) authentication for your organization.
13/// Manage certificates at the organization level.
14pub struct Certificates<'c, C: Config> {
15    client: &'c Client<C>,
16    pub(crate) request_options: RequestOptions,
17}
18
19impl<'c, C: Config> Certificates<'c, C> {
20    pub fn new(client: &'c Client<C>) -> Self {
21        Self {
22            client,
23            request_options: RequestOptions::new(),
24        }
25    }
26
27    // Organization-level certificate operations
28
29    /// List all certificates for the organization.
30    #[crate::byot(R = serde::de::DeserializeOwned)]
31    pub async fn list_organization(&self) -> Result<ListCertificatesResponse, OpenAIError> {
32        self.client
33            .get("/organization/certificates", &self.request_options)
34            .await
35    }
36
37    /// Upload a certificate to the organization.
38    /// This does not automatically activate the certificate.
39    pub async fn upload_organization(
40        &self,
41        request: UploadCertificateRequest,
42    ) -> Result<Certificate, OpenAIError> {
43        self.client
44            .post("/organization/certificates", request, &self.request_options)
45            .await
46    }
47
48    /// Activate certificates for the organization.
49    /// You can atomically and idempotently activate up to 10 certificates at a time.
50    pub async fn activate_organization(
51        &self,
52        request: ToggleCertificatesRequest,
53    ) -> Result<OrganizationCertificateActivationResponse, OpenAIError> {
54        self.client
55            .post(
56                "/organization/certificates/activate",
57                request,
58                &self.request_options,
59            )
60            .await
61    }
62
63    /// Deactivate certificates for the organization.
64    /// You can atomically and idempotently deactivate up to 10 certificates at a time.
65    pub async fn deactivate_organization(
66        &self,
67        request: ToggleCertificatesRequest,
68    ) -> Result<OrganizationCertificateDeactivationResponse, OpenAIError> {
69        self.client
70            .post(
71                "/organization/certificates/deactivate",
72                request,
73                &self.request_options,
74            )
75            .await
76    }
77
78    /// Retrieve a single certificate.
79    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
80    pub async fn retrieve(&self, certificate_id: &str) -> Result<Certificate, OpenAIError> {
81        self.client
82            .get(
83                format!("/organization/certificates/{certificate_id}").as_str(),
84                &self.request_options,
85            )
86            .await
87    }
88
89    /// Modify a certificate. Note that only the name can be modified.
90    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
91    pub async fn modify(
92        &self,
93        certificate_id: &str,
94        request: ModifyCertificateRequest,
95    ) -> Result<Certificate, OpenAIError> {
96        self.client
97            .post(
98                format!("/organization/certificates/{certificate_id}").as_str(),
99                request,
100                &self.request_options,
101            )
102            .await
103    }
104
105    /// Delete a certificate from the organization.
106    /// The certificate must be inactive for the organization and all projects.
107    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
108    pub async fn delete(
109        &self,
110        certificate_id: &str,
111    ) -> Result<DeleteCertificateResponse, OpenAIError> {
112        self.client
113            .delete(
114                format!("/organization/certificates/{certificate_id}").as_str(),
115                &self.request_options,
116            )
117            .await
118    }
119}