use crate::cfs::{self, configuration::error::Error};
use super::r#struct::{
cfs_configuration_request::v2::CfsConfigurationRequest,
cfs_configuration_response::v2::CfsConfigurationResponse,
};
pub async fn get(
shasta_token: &str,
shasta_base_url: &str,
shasta_root_cert: &[u8],
configuration_name_opt: Option<&str>,
) -> Result<Vec<CfsConfigurationResponse>, Error> {
cfs::configuration::shasta::http_client::v2::get(
shasta_token,
shasta_base_url,
shasta_root_cert,
configuration_name_opt,
)
.await
}
pub async fn put(
shasta_token: &str,
shasta_base_url: &str,
shasta_root_cert: &[u8],
configuration: &CfsConfigurationRequest,
configuration_name: &str,
) -> Result<CfsConfigurationResponse, Error> {
log::info!("Check CFS configuration '{}' exists", configuration_name);
let cfs_configuration_rslt = get(
shasta_token,
shasta_base_url,
shasta_root_cert,
Some(configuration_name),
)
.await;
if cfs_configuration_rslt.is_ok_and(|cfs_configuration_vec| !cfs_configuration_vec.is_empty()) {
return Err(Error::ConfigurationAlreadyExistsError(
configuration_name.to_string(),
));
}
log::info!(
"CFS configuration '{}' does not exists, creating new CFS configuration",
configuration_name
);
cfs::configuration::shasta::http_client::v2::put(
shasta_token,
shasta_base_url,
shasta_root_cert,
configuration,
configuration_name,
)
.await
}