async_openai/
certificates.rs

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