async_openai/admin/
certificates.rs

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