pub mod cert {
use crate::api;
use crate::api::pki::requests::{
GenerateCertificateRequest, GenerateCertificateRequestBuilder, ListCertificatesRequest,
ReadCertificateRequest, RevokeCertificateRequest, TidyRequest,
};
use crate::api::pki::responses::{
GenerateCertificateResponse, ReadCertificateResponse, RevokeCertificateResponse,
};
use crate::client::Client;
use crate::error::ClientError;
pub async fn generate(
client: &impl Client,
mount: &str,
role: &str,
opts: Option<&mut GenerateCertificateRequestBuilder>,
) -> Result<GenerateCertificateResponse, ClientError> {
let mut t = GenerateCertificateRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.role(role)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn list(client: &impl Client, mount: &str) -> Result<Vec<String>, ClientError> {
let endpoint = ListCertificatesRequest::builder()
.mount(mount)
.build()
.unwrap();
Ok(api::exec_with_result(client, endpoint).await?.keys)
}
pub async fn read(
client: &impl Client,
mount: &str,
serial: &str,
) -> Result<ReadCertificateResponse, ClientError> {
let endpoint = ReadCertificateRequest::builder()
.mount(mount)
.serial(serial)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn revoke(
client: &impl Client,
mount: &str,
serial: &str,
) -> Result<RevokeCertificateResponse, ClientError> {
let endpoint = RevokeCertificateRequest::builder()
.mount(mount)
.serial_number(serial)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn tidy(client: &impl Client, mount: &str) -> Result<(), ClientError> {
let endpoint = TidyRequest::builder().mount(mount).build().unwrap();
api::exec_with_empty_result(client, endpoint).await
}
pub mod ca {
use crate::api;
use crate::api::pki::responses::SignSelfIssuedResponse;
use crate::{
api::pki::{
requests::{
DeleteRootRequest, GenerateRootRequest, GenerateRootRequestBuilder,
SignCertificateRequest, SignCertificateRequestBuilder, SignIntermediateRequest,
SignIntermediateRequestBuilder, SignSelfIssuedRequest, SubmitCARequest,
},
responses::{
GenerateRootResponse, SignCertificateResponse, SignIntermediateResponse,
},
},
client::Client,
error::ClientError,
};
pub async fn delete(client: &impl Client, mount: &str) -> Result<(), ClientError> {
let endpoint = DeleteRootRequest::builder().mount(mount).build().unwrap();
api::exec_with_empty(client, endpoint).await
}
pub async fn generate(
client: &impl Client,
mount: &str,
cert_type: &str,
opts: Option<&mut GenerateRootRequestBuilder>,
) -> Result<Option<GenerateRootResponse>, ClientError> {
let mut t = GenerateRootRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.cert_type(cert_type)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn sign(
client: &impl Client,
mount: &str,
role: &str,
csr: &str,
common_name: &str,
opts: Option<&mut SignCertificateRequestBuilder>,
) -> Result<SignCertificateResponse, ClientError> {
let mut t = SignCertificateRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.role(role)
.csr(csr)
.common_name(common_name)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn sign_intermediate(
client: &impl Client,
mount: &str,
csr: &str,
common_name: &str,
opts: Option<&mut SignIntermediateRequestBuilder>,
) -> Result<SignIntermediateResponse, ClientError> {
let mut t = SignIntermediateRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.csr(csr)
.common_name(common_name)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn sign_self_issued(
client: &impl Client,
mount: &str,
certificate: &str,
) -> Result<SignSelfIssuedResponse, ClientError> {
let endpoint = SignSelfIssuedRequest::builder()
.mount(mount)
.certificate(certificate)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn submit(
client: &impl Client,
mount: &str,
pem_bundle: &str,
) -> Result<(), ClientError> {
let endpoint = SubmitCARequest::builder()
.mount(mount)
.pem_bundle(pem_bundle)
.build()
.unwrap();
api::exec_with_empty(client, endpoint).await
}
pub mod int {
use crate::api;
use crate::{
api::pki::{
requests::{
GenerateIntermediateRequest, GenerateIntermediateRequestBuilder,
SetSignedIntermediateRequest,
},
responses::GenerateIntermediateResponse,
},
client::Client,
error::ClientError,
};
pub async fn generate(
client: &impl Client,
mount: &str,
cert_type: &str,
common_name: &str,
opts: Option<&mut GenerateIntermediateRequestBuilder>,
) -> Result<GenerateIntermediateResponse, ClientError> {
let mut t = GenerateIntermediateRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.cert_type(cert_type)
.common_name(common_name)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn set_signed(
client: &impl Client,
mount: &str,
certificate: &str,
) -> Result<(), ClientError> {
let endpoint = SetSignedIntermediateRequest::builder()
.mount(mount)
.certificate(certificate)
.build()
.unwrap();
api::exec_with_empty(client, endpoint).await
}
}
}
pub mod crl {
use crate::api::pki::{
requests::{
ReadCRLConfigRequest, RotateCRLsRequest, SetCRLConfigRequest,
SetCRLConfigRequestBuilder,
},
responses::{ReadCRLConfigResponse, RotateCRLsResponse},
};
use crate::api::{self, exec_with_empty};
use crate::client::Client;
use crate::error::ClientError;
pub async fn rotate(
client: &impl Client,
mount: &str,
) -> Result<RotateCRLsResponse, ClientError> {
let endpoint = RotateCRLsRequest::builder().mount(mount).build().unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn read_config(
client: &impl Client,
mount: &str,
) -> Result<ReadCRLConfigResponse, ClientError> {
let endpoint = ReadCRLConfigRequest::builder()
.mount(mount)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn set_config(
client: &impl Client,
mount: &str,
opts: Option<&mut SetCRLConfigRequestBuilder>,
) -> Result<(), ClientError> {
let mut t = SetCRLConfigRequest::builder();
let endpoint = opts.unwrap_or(&mut t).mount(mount).build().unwrap();
exec_with_empty(client, endpoint).await
}
}
pub mod urls {
use crate::api;
use crate::api::pki::{
requests::{ReadURLsRequest, SetURLsRequest, SetURLsRequestBuilder},
responses::ReadURLsResponse,
};
use crate::client::Client;
use crate::error::ClientError;
pub async fn read(
client: &impl Client,
mount: &str,
) -> Result<ReadURLsResponse, ClientError> {
let endpoint = ReadURLsRequest::builder().mount(mount).build().unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn set(
client: &impl Client,
mount: &str,
opts: Option<&mut SetURLsRequestBuilder>,
) -> Result<(), ClientError> {
let mut t = SetURLsRequest::builder();
let endpoint = opts.unwrap_or(&mut t).mount(mount).build().unwrap();
api::exec_with_empty(client, endpoint).await
}
}
}
pub mod role {
use crate::api;
use crate::api::pki::{
requests::{
DeleteRoleRequest, ListRolesRequest, ReadRoleRequest, SetRoleRequest,
SetRoleRequestBuilder,
},
responses::{ListRolesResponse, ReadRoleResponse},
};
use crate::client::Client;
use crate::error::ClientError;
pub async fn delete(client: &impl Client, mount: &str, name: &str) -> Result<(), ClientError> {
let endpoint = DeleteRoleRequest::builder()
.mount(mount)
.name(name)
.build()
.unwrap();
api::exec_with_empty(client, endpoint).await
}
pub async fn list(client: &impl Client, mount: &str) -> Result<ListRolesResponse, ClientError> {
let endpoint = ListRolesRequest::builder().mount(mount).build().unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn read(
client: &impl Client,
mount: &str,
name: &str,
) -> Result<ReadRoleResponse, ClientError> {
let endpoint = ReadRoleRequest::builder()
.mount(mount)
.name(name)
.build()
.unwrap();
api::exec_with_result(client, endpoint).await
}
pub async fn set(
client: &impl Client,
mount: &str,
name: &str,
opts: Option<&mut SetRoleRequestBuilder>,
) -> Result<(), ClientError> {
let mut t = SetRoleRequest::builder();
let endpoint = opts
.unwrap_or(&mut t)
.mount(mount)
.name(name)
.build()
.unwrap();
api::exec_with_empty(client, endpoint).await
}
}