use std::error::Error;
use std::fmt;
use std::io;
#[allow(warnings)]
use futures::future;
use futures::Future;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoFuture};
use rusoto_core::credential::{CredentialsError, ProvideAwsCredentials};
use rusoto_core::request::HttpDispatchError;
use rusoto_core::signature::SignedRequest;
use serde_json;
use serde_json::from_slice;
use serde_json::Value as SerdeJsonValue;
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Backup {
#[serde(rename = "BackupId")]
pub backup_id: String,
#[serde(rename = "BackupState")]
#[serde(skip_serializing_if = "Option::is_none")]
pub backup_state: Option<String>,
#[serde(rename = "ClusterId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_id: Option<String>,
#[serde(rename = "CopyTimestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub copy_timestamp: Option<f64>,
#[serde(rename = "CreateTimestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub create_timestamp: Option<f64>,
#[serde(rename = "DeleteTimestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub delete_timestamp: Option<f64>,
#[serde(rename = "SourceBackup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_backup: Option<String>,
#[serde(rename = "SourceCluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_cluster: Option<String>,
#[serde(rename = "SourceRegion")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_region: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Certificates {
#[serde(rename = "AwsHardwareCertificate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub aws_hardware_certificate: Option<String>,
#[serde(rename = "ClusterCertificate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_certificate: Option<String>,
#[serde(rename = "ClusterCsr")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_csr: Option<String>,
#[serde(rename = "HsmCertificate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsm_certificate: Option<String>,
#[serde(rename = "ManufacturerHardwareCertificate")]
#[serde(skip_serializing_if = "Option::is_none")]
pub manufacturer_hardware_certificate: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Cluster {
#[serde(rename = "BackupPolicy")]
#[serde(skip_serializing_if = "Option::is_none")]
pub backup_policy: Option<String>,
#[serde(rename = "Certificates")]
#[serde(skip_serializing_if = "Option::is_none")]
pub certificates: Option<Certificates>,
#[serde(rename = "ClusterId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_id: Option<String>,
#[serde(rename = "CreateTimestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub create_timestamp: Option<f64>,
#[serde(rename = "HsmType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsm_type: Option<String>,
#[serde(rename = "Hsms")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsms: Option<Vec<Hsm>>,
#[serde(rename = "PreCoPassword")]
#[serde(skip_serializing_if = "Option::is_none")]
pub pre_co_password: Option<String>,
#[serde(rename = "SecurityGroup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub security_group: Option<String>,
#[serde(rename = "SourceBackupId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_backup_id: Option<String>,
#[serde(rename = "State")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
#[serde(rename = "StateMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state_message: Option<String>,
#[serde(rename = "SubnetMapping")]
#[serde(skip_serializing_if = "Option::is_none")]
pub subnet_mapping: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "VpcId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vpc_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CopyBackupToRegionRequest {
#[serde(rename = "BackupId")]
pub backup_id: String,
#[serde(rename = "DestinationRegion")]
pub destination_region: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CopyBackupToRegionResponse {
#[serde(rename = "DestinationBackup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub destination_backup: Option<DestinationBackup>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateClusterRequest {
#[serde(rename = "HsmType")]
pub hsm_type: String,
#[serde(rename = "SourceBackupId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_backup_id: Option<String>,
#[serde(rename = "SubnetIds")]
pub subnet_ids: Vec<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateClusterResponse {
#[serde(rename = "Cluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster: Option<Cluster>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateHsmRequest {
#[serde(rename = "AvailabilityZone")]
pub availability_zone: String,
#[serde(rename = "ClusterId")]
pub cluster_id: String,
#[serde(rename = "IpAddress")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateHsmResponse {
#[serde(rename = "Hsm")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsm: Option<Hsm>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteBackupRequest {
#[serde(rename = "BackupId")]
pub backup_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteBackupResponse {
#[serde(rename = "Backup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub backup: Option<Backup>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteClusterRequest {
#[serde(rename = "ClusterId")]
pub cluster_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteClusterResponse {
#[serde(rename = "Cluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster: Option<Cluster>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteHsmRequest {
#[serde(rename = "ClusterId")]
pub cluster_id: String,
#[serde(rename = "EniId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub eni_id: Option<String>,
#[serde(rename = "EniIp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub eni_ip: Option<String>,
#[serde(rename = "HsmId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsm_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteHsmResponse {
#[serde(rename = "HsmId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hsm_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeBackupsRequest {
#[serde(rename = "Filters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<::std::collections::HashMap<String, Vec<String>>>,
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "SortAscending")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sort_ascending: Option<bool>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeBackupsResponse {
#[serde(rename = "Backups")]
#[serde(skip_serializing_if = "Option::is_none")]
pub backups: Option<Vec<Backup>>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeClustersRequest {
#[serde(rename = "Filters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<::std::collections::HashMap<String, Vec<String>>>,
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeClustersResponse {
#[serde(rename = "Clusters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub clusters: Option<Vec<Cluster>>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DestinationBackup {
#[serde(rename = "CreateTimestamp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub create_timestamp: Option<f64>,
#[serde(rename = "SourceBackup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_backup: Option<String>,
#[serde(rename = "SourceCluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_cluster: Option<String>,
#[serde(rename = "SourceRegion")]
#[serde(skip_serializing_if = "Option::is_none")]
pub source_region: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Hsm {
#[serde(rename = "AvailabilityZone")]
#[serde(skip_serializing_if = "Option::is_none")]
pub availability_zone: Option<String>,
#[serde(rename = "ClusterId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_id: Option<String>,
#[serde(rename = "EniId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub eni_id: Option<String>,
#[serde(rename = "EniIp")]
#[serde(skip_serializing_if = "Option::is_none")]
pub eni_ip: Option<String>,
#[serde(rename = "HsmId")]
pub hsm_id: String,
#[serde(rename = "State")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
#[serde(rename = "StateMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state_message: Option<String>,
#[serde(rename = "SubnetId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub subnet_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct InitializeClusterRequest {
#[serde(rename = "ClusterId")]
pub cluster_id: String,
#[serde(rename = "SignedCert")]
pub signed_cert: String,
#[serde(rename = "TrustAnchor")]
pub trust_anchor: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct InitializeClusterResponse {
#[serde(rename = "State")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<String>,
#[serde(rename = "StateMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub state_message: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListTagsRequest {
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ResourceId")]
pub resource_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListTagsResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "TagList")]
pub tag_list: Vec<Tag>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct RestoreBackupRequest {
#[serde(rename = "BackupId")]
pub backup_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct RestoreBackupResponse {
#[serde(rename = "Backup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub backup: Option<Backup>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tag {
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "Value")]
pub value: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct TagResourceRequest {
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "TagList")]
pub tag_list: Vec<Tag>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct TagResourceResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UntagResourceRequest {
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "TagKeyList")]
pub tag_key_list: Vec<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UntagResourceResponse {}
#[derive(Debug, PartialEq)]
pub enum CopyBackupToRegionError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CopyBackupToRegionError {
pub fn from_response(res: BufferedHttpResponse) -> CopyBackupToRegionError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return CopyBackupToRegionError::CloudHsmAccessDenied(String::from(
error_message,
));
}
"CloudHsmInternalFailureException" => {
return CopyBackupToRegionError::CloudHsmInternalFailure(String::from(
error_message,
));
}
"CloudHsmInvalidRequestException" => {
return CopyBackupToRegionError::CloudHsmInvalidRequest(String::from(
error_message,
));
}
"CloudHsmResourceNotFoundException" => {
return CopyBackupToRegionError::CloudHsmResourceNotFound(String::from(
error_message,
));
}
"CloudHsmServiceException" => {
return CopyBackupToRegionError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return CopyBackupToRegionError::Validation(error_message.to_string());
}
_ => {}
}
}
return CopyBackupToRegionError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CopyBackupToRegionError {
fn from(err: serde_json::error::Error) -> CopyBackupToRegionError {
CopyBackupToRegionError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CopyBackupToRegionError {
fn from(err: CredentialsError) -> CopyBackupToRegionError {
CopyBackupToRegionError::Credentials(err)
}
}
impl From<HttpDispatchError> for CopyBackupToRegionError {
fn from(err: HttpDispatchError) -> CopyBackupToRegionError {
CopyBackupToRegionError::HttpDispatch(err)
}
}
impl From<io::Error> for CopyBackupToRegionError {
fn from(err: io::Error) -> CopyBackupToRegionError {
CopyBackupToRegionError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CopyBackupToRegionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CopyBackupToRegionError {
fn description(&self) -> &str {
match *self {
CopyBackupToRegionError::CloudHsmAccessDenied(ref cause) => cause,
CopyBackupToRegionError::CloudHsmInternalFailure(ref cause) => cause,
CopyBackupToRegionError::CloudHsmInvalidRequest(ref cause) => cause,
CopyBackupToRegionError::CloudHsmResourceNotFound(ref cause) => cause,
CopyBackupToRegionError::CloudHsmService(ref cause) => cause,
CopyBackupToRegionError::Validation(ref cause) => cause,
CopyBackupToRegionError::Credentials(ref err) => err.description(),
CopyBackupToRegionError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
CopyBackupToRegionError::ParseError(ref cause) => cause,
CopyBackupToRegionError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum CreateClusterError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateClusterError {
pub fn from_response(res: BufferedHttpResponse) -> CreateClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return CreateClusterError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return CreateClusterError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return CreateClusterError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return CreateClusterError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return CreateClusterError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return CreateClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return CreateClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateClusterError {
fn from(err: serde_json::error::Error) -> CreateClusterError {
CreateClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateClusterError {
fn from(err: CredentialsError) -> CreateClusterError {
CreateClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateClusterError {
fn from(err: HttpDispatchError) -> CreateClusterError {
CreateClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateClusterError {
fn from(err: io::Error) -> CreateClusterError {
CreateClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateClusterError {
fn description(&self) -> &str {
match *self {
CreateClusterError::CloudHsmAccessDenied(ref cause) => cause,
CreateClusterError::CloudHsmInternalFailure(ref cause) => cause,
CreateClusterError::CloudHsmInvalidRequest(ref cause) => cause,
CreateClusterError::CloudHsmResourceNotFound(ref cause) => cause,
CreateClusterError::CloudHsmService(ref cause) => cause,
CreateClusterError::Validation(ref cause) => cause,
CreateClusterError::Credentials(ref err) => err.description(),
CreateClusterError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
CreateClusterError::ParseError(ref cause) => cause,
CreateClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum CreateHsmError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateHsmError {
pub fn from_response(res: BufferedHttpResponse) -> CreateHsmError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return CreateHsmError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return CreateHsmError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return CreateHsmError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return CreateHsmError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return CreateHsmError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return CreateHsmError::Validation(error_message.to_string());
}
_ => {}
}
}
return CreateHsmError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateHsmError {
fn from(err: serde_json::error::Error) -> CreateHsmError {
CreateHsmError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateHsmError {
fn from(err: CredentialsError) -> CreateHsmError {
CreateHsmError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateHsmError {
fn from(err: HttpDispatchError) -> CreateHsmError {
CreateHsmError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateHsmError {
fn from(err: io::Error) -> CreateHsmError {
CreateHsmError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateHsmError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateHsmError {
fn description(&self) -> &str {
match *self {
CreateHsmError::CloudHsmAccessDenied(ref cause) => cause,
CreateHsmError::CloudHsmInternalFailure(ref cause) => cause,
CreateHsmError::CloudHsmInvalidRequest(ref cause) => cause,
CreateHsmError::CloudHsmResourceNotFound(ref cause) => cause,
CreateHsmError::CloudHsmService(ref cause) => cause,
CreateHsmError::Validation(ref cause) => cause,
CreateHsmError::Credentials(ref err) => err.description(),
CreateHsmError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
CreateHsmError::ParseError(ref cause) => cause,
CreateHsmError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteBackupError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteBackupError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteBackupError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return DeleteBackupError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return DeleteBackupError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return DeleteBackupError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return DeleteBackupError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return DeleteBackupError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return DeleteBackupError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteBackupError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteBackupError {
fn from(err: serde_json::error::Error) -> DeleteBackupError {
DeleteBackupError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteBackupError {
fn from(err: CredentialsError) -> DeleteBackupError {
DeleteBackupError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteBackupError {
fn from(err: HttpDispatchError) -> DeleteBackupError {
DeleteBackupError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteBackupError {
fn from(err: io::Error) -> DeleteBackupError {
DeleteBackupError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteBackupError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteBackupError {
fn description(&self) -> &str {
match *self {
DeleteBackupError::CloudHsmAccessDenied(ref cause) => cause,
DeleteBackupError::CloudHsmInternalFailure(ref cause) => cause,
DeleteBackupError::CloudHsmInvalidRequest(ref cause) => cause,
DeleteBackupError::CloudHsmResourceNotFound(ref cause) => cause,
DeleteBackupError::CloudHsmService(ref cause) => cause,
DeleteBackupError::Validation(ref cause) => cause,
DeleteBackupError::Credentials(ref err) => err.description(),
DeleteBackupError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteBackupError::ParseError(ref cause) => cause,
DeleteBackupError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteClusterError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteClusterError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return DeleteClusterError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return DeleteClusterError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return DeleteClusterError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return DeleteClusterError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return DeleteClusterError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return DeleteClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteClusterError {
fn from(err: serde_json::error::Error) -> DeleteClusterError {
DeleteClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteClusterError {
fn from(err: CredentialsError) -> DeleteClusterError {
DeleteClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteClusterError {
fn from(err: HttpDispatchError) -> DeleteClusterError {
DeleteClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteClusterError {
fn from(err: io::Error) -> DeleteClusterError {
DeleteClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteClusterError {
fn description(&self) -> &str {
match *self {
DeleteClusterError::CloudHsmAccessDenied(ref cause) => cause,
DeleteClusterError::CloudHsmInternalFailure(ref cause) => cause,
DeleteClusterError::CloudHsmInvalidRequest(ref cause) => cause,
DeleteClusterError::CloudHsmResourceNotFound(ref cause) => cause,
DeleteClusterError::CloudHsmService(ref cause) => cause,
DeleteClusterError::Validation(ref cause) => cause,
DeleteClusterError::Credentials(ref err) => err.description(),
DeleteClusterError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteClusterError::ParseError(ref cause) => cause,
DeleteClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteHsmError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteHsmError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteHsmError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return DeleteHsmError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return DeleteHsmError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return DeleteHsmError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return DeleteHsmError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return DeleteHsmError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return DeleteHsmError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteHsmError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteHsmError {
fn from(err: serde_json::error::Error) -> DeleteHsmError {
DeleteHsmError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteHsmError {
fn from(err: CredentialsError) -> DeleteHsmError {
DeleteHsmError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteHsmError {
fn from(err: HttpDispatchError) -> DeleteHsmError {
DeleteHsmError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteHsmError {
fn from(err: io::Error) -> DeleteHsmError {
DeleteHsmError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteHsmError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteHsmError {
fn description(&self) -> &str {
match *self {
DeleteHsmError::CloudHsmAccessDenied(ref cause) => cause,
DeleteHsmError::CloudHsmInternalFailure(ref cause) => cause,
DeleteHsmError::CloudHsmInvalidRequest(ref cause) => cause,
DeleteHsmError::CloudHsmResourceNotFound(ref cause) => cause,
DeleteHsmError::CloudHsmService(ref cause) => cause,
DeleteHsmError::Validation(ref cause) => cause,
DeleteHsmError::Credentials(ref err) => err.description(),
DeleteHsmError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteHsmError::ParseError(ref cause) => cause,
DeleteHsmError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeBackupsError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeBackupsError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeBackupsError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return DescribeBackupsError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return DescribeBackupsError::CloudHsmInternalFailure(String::from(
error_message,
));
}
"CloudHsmInvalidRequestException" => {
return DescribeBackupsError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return DescribeBackupsError::CloudHsmResourceNotFound(String::from(
error_message,
));
}
"CloudHsmServiceException" => {
return DescribeBackupsError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return DescribeBackupsError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeBackupsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeBackupsError {
fn from(err: serde_json::error::Error) -> DescribeBackupsError {
DescribeBackupsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeBackupsError {
fn from(err: CredentialsError) -> DescribeBackupsError {
DescribeBackupsError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeBackupsError {
fn from(err: HttpDispatchError) -> DescribeBackupsError {
DescribeBackupsError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeBackupsError {
fn from(err: io::Error) -> DescribeBackupsError {
DescribeBackupsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeBackupsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeBackupsError {
fn description(&self) -> &str {
match *self {
DescribeBackupsError::CloudHsmAccessDenied(ref cause) => cause,
DescribeBackupsError::CloudHsmInternalFailure(ref cause) => cause,
DescribeBackupsError::CloudHsmInvalidRequest(ref cause) => cause,
DescribeBackupsError::CloudHsmResourceNotFound(ref cause) => cause,
DescribeBackupsError::CloudHsmService(ref cause) => cause,
DescribeBackupsError::Validation(ref cause) => cause,
DescribeBackupsError::Credentials(ref err) => err.description(),
DescribeBackupsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeBackupsError::ParseError(ref cause) => cause,
DescribeBackupsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeClustersError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeClustersError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeClustersError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return DescribeClustersError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return DescribeClustersError::CloudHsmInternalFailure(String::from(
error_message,
));
}
"CloudHsmInvalidRequestException" => {
return DescribeClustersError::CloudHsmInvalidRequest(String::from(
error_message,
));
}
"CloudHsmServiceException" => {
return DescribeClustersError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return DescribeClustersError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeClustersError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeClustersError {
fn from(err: serde_json::error::Error) -> DescribeClustersError {
DescribeClustersError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeClustersError {
fn from(err: CredentialsError) -> DescribeClustersError {
DescribeClustersError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeClustersError {
fn from(err: HttpDispatchError) -> DescribeClustersError {
DescribeClustersError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeClustersError {
fn from(err: io::Error) -> DescribeClustersError {
DescribeClustersError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeClustersError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeClustersError {
fn description(&self) -> &str {
match *self {
DescribeClustersError::CloudHsmAccessDenied(ref cause) => cause,
DescribeClustersError::CloudHsmInternalFailure(ref cause) => cause,
DescribeClustersError::CloudHsmInvalidRequest(ref cause) => cause,
DescribeClustersError::CloudHsmService(ref cause) => cause,
DescribeClustersError::Validation(ref cause) => cause,
DescribeClustersError::Credentials(ref err) => err.description(),
DescribeClustersError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeClustersError::ParseError(ref cause) => cause,
DescribeClustersError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum InitializeClusterError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl InitializeClusterError {
pub fn from_response(res: BufferedHttpResponse) -> InitializeClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return InitializeClusterError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return InitializeClusterError::CloudHsmInternalFailure(String::from(
error_message,
));
}
"CloudHsmInvalidRequestException" => {
return InitializeClusterError::CloudHsmInvalidRequest(String::from(
error_message,
));
}
"CloudHsmResourceNotFoundException" => {
return InitializeClusterError::CloudHsmResourceNotFound(String::from(
error_message,
));
}
"CloudHsmServiceException" => {
return InitializeClusterError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return InitializeClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return InitializeClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for InitializeClusterError {
fn from(err: serde_json::error::Error) -> InitializeClusterError {
InitializeClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for InitializeClusterError {
fn from(err: CredentialsError) -> InitializeClusterError {
InitializeClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for InitializeClusterError {
fn from(err: HttpDispatchError) -> InitializeClusterError {
InitializeClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for InitializeClusterError {
fn from(err: io::Error) -> InitializeClusterError {
InitializeClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for InitializeClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for InitializeClusterError {
fn description(&self) -> &str {
match *self {
InitializeClusterError::CloudHsmAccessDenied(ref cause) => cause,
InitializeClusterError::CloudHsmInternalFailure(ref cause) => cause,
InitializeClusterError::CloudHsmInvalidRequest(ref cause) => cause,
InitializeClusterError::CloudHsmResourceNotFound(ref cause) => cause,
InitializeClusterError::CloudHsmService(ref cause) => cause,
InitializeClusterError::Validation(ref cause) => cause,
InitializeClusterError::Credentials(ref err) => err.description(),
InitializeClusterError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
InitializeClusterError::ParseError(ref cause) => cause,
InitializeClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListTagsError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListTagsError {
pub fn from_response(res: BufferedHttpResponse) -> ListTagsError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return ListTagsError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return ListTagsError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return ListTagsError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return ListTagsError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return ListTagsError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return ListTagsError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListTagsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListTagsError {
fn from(err: serde_json::error::Error) -> ListTagsError {
ListTagsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListTagsError {
fn from(err: CredentialsError) -> ListTagsError {
ListTagsError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListTagsError {
fn from(err: HttpDispatchError) -> ListTagsError {
ListTagsError::HttpDispatch(err)
}
}
impl From<io::Error> for ListTagsError {
fn from(err: io::Error) -> ListTagsError {
ListTagsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListTagsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListTagsError {
fn description(&self) -> &str {
match *self {
ListTagsError::CloudHsmAccessDenied(ref cause) => cause,
ListTagsError::CloudHsmInternalFailure(ref cause) => cause,
ListTagsError::CloudHsmInvalidRequest(ref cause) => cause,
ListTagsError::CloudHsmResourceNotFound(ref cause) => cause,
ListTagsError::CloudHsmService(ref cause) => cause,
ListTagsError::Validation(ref cause) => cause,
ListTagsError::Credentials(ref err) => err.description(),
ListTagsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListTagsError::ParseError(ref cause) => cause,
ListTagsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum RestoreBackupError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl RestoreBackupError {
pub fn from_response(res: BufferedHttpResponse) -> RestoreBackupError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return RestoreBackupError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return RestoreBackupError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return RestoreBackupError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return RestoreBackupError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return RestoreBackupError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return RestoreBackupError::Validation(error_message.to_string());
}
_ => {}
}
}
return RestoreBackupError::Unknown(res);
}
}
impl From<serde_json::error::Error> for RestoreBackupError {
fn from(err: serde_json::error::Error) -> RestoreBackupError {
RestoreBackupError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for RestoreBackupError {
fn from(err: CredentialsError) -> RestoreBackupError {
RestoreBackupError::Credentials(err)
}
}
impl From<HttpDispatchError> for RestoreBackupError {
fn from(err: HttpDispatchError) -> RestoreBackupError {
RestoreBackupError::HttpDispatch(err)
}
}
impl From<io::Error> for RestoreBackupError {
fn from(err: io::Error) -> RestoreBackupError {
RestoreBackupError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for RestoreBackupError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for RestoreBackupError {
fn description(&self) -> &str {
match *self {
RestoreBackupError::CloudHsmAccessDenied(ref cause) => cause,
RestoreBackupError::CloudHsmInternalFailure(ref cause) => cause,
RestoreBackupError::CloudHsmInvalidRequest(ref cause) => cause,
RestoreBackupError::CloudHsmResourceNotFound(ref cause) => cause,
RestoreBackupError::CloudHsmService(ref cause) => cause,
RestoreBackupError::Validation(ref cause) => cause,
RestoreBackupError::Credentials(ref err) => err.description(),
RestoreBackupError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
RestoreBackupError::ParseError(ref cause) => cause,
RestoreBackupError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum TagResourceError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl TagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> TagResourceError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return TagResourceError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return TagResourceError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return TagResourceError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return TagResourceError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return TagResourceError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return TagResourceError::Validation(error_message.to_string());
}
_ => {}
}
}
return TagResourceError::Unknown(res);
}
}
impl From<serde_json::error::Error> for TagResourceError {
fn from(err: serde_json::error::Error) -> TagResourceError {
TagResourceError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for TagResourceError {
fn from(err: CredentialsError) -> TagResourceError {
TagResourceError::Credentials(err)
}
}
impl From<HttpDispatchError> for TagResourceError {
fn from(err: HttpDispatchError) -> TagResourceError {
TagResourceError::HttpDispatch(err)
}
}
impl From<io::Error> for TagResourceError {
fn from(err: io::Error) -> TagResourceError {
TagResourceError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for TagResourceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for TagResourceError {
fn description(&self) -> &str {
match *self {
TagResourceError::CloudHsmAccessDenied(ref cause) => cause,
TagResourceError::CloudHsmInternalFailure(ref cause) => cause,
TagResourceError::CloudHsmInvalidRequest(ref cause) => cause,
TagResourceError::CloudHsmResourceNotFound(ref cause) => cause,
TagResourceError::CloudHsmService(ref cause) => cause,
TagResourceError::Validation(ref cause) => cause,
TagResourceError::Credentials(ref err) => err.description(),
TagResourceError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
TagResourceError::ParseError(ref cause) => cause,
TagResourceError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UntagResourceError {
CloudHsmAccessDenied(String),
CloudHsmInternalFailure(String),
CloudHsmInvalidRequest(String),
CloudHsmResourceNotFound(String),
CloudHsmService(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UntagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> UntagResourceError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let raw_error_type = json
.get("__type")
.and_then(|e| e.as_str())
.unwrap_or("Unknown");
let error_message = json.get("message").and_then(|m| m.as_str()).unwrap_or("");
let pieces: Vec<&str> = raw_error_type.split("#").collect();
let error_type = pieces.last().expect("Expected error type");
match *error_type {
"CloudHsmAccessDeniedException" => {
return UntagResourceError::CloudHsmAccessDenied(String::from(error_message));
}
"CloudHsmInternalFailureException" => {
return UntagResourceError::CloudHsmInternalFailure(String::from(error_message));
}
"CloudHsmInvalidRequestException" => {
return UntagResourceError::CloudHsmInvalidRequest(String::from(error_message));
}
"CloudHsmResourceNotFoundException" => {
return UntagResourceError::CloudHsmResourceNotFound(String::from(error_message));
}
"CloudHsmServiceException" => {
return UntagResourceError::CloudHsmService(String::from(error_message));
}
"ValidationException" => {
return UntagResourceError::Validation(error_message.to_string());
}
_ => {}
}
}
return UntagResourceError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UntagResourceError {
fn from(err: serde_json::error::Error) -> UntagResourceError {
UntagResourceError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UntagResourceError {
fn from(err: CredentialsError) -> UntagResourceError {
UntagResourceError::Credentials(err)
}
}
impl From<HttpDispatchError> for UntagResourceError {
fn from(err: HttpDispatchError) -> UntagResourceError {
UntagResourceError::HttpDispatch(err)
}
}
impl From<io::Error> for UntagResourceError {
fn from(err: io::Error) -> UntagResourceError {
UntagResourceError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UntagResourceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UntagResourceError {
fn description(&self) -> &str {
match *self {
UntagResourceError::CloudHsmAccessDenied(ref cause) => cause,
UntagResourceError::CloudHsmInternalFailure(ref cause) => cause,
UntagResourceError::CloudHsmInvalidRequest(ref cause) => cause,
UntagResourceError::CloudHsmResourceNotFound(ref cause) => cause,
UntagResourceError::CloudHsmService(ref cause) => cause,
UntagResourceError::Validation(ref cause) => cause,
UntagResourceError::Credentials(ref err) => err.description(),
UntagResourceError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
UntagResourceError::ParseError(ref cause) => cause,
UntagResourceError::Unknown(_) => "unknown error",
}
}
}
pub trait CloudHsmv2 {
fn copy_backup_to_region(
&self,
input: CopyBackupToRegionRequest,
) -> RusotoFuture<CopyBackupToRegionResponse, CopyBackupToRegionError>;
fn create_cluster(
&self,
input: CreateClusterRequest,
) -> RusotoFuture<CreateClusterResponse, CreateClusterError>;
fn create_hsm(
&self,
input: CreateHsmRequest,
) -> RusotoFuture<CreateHsmResponse, CreateHsmError>;
fn delete_backup(
&self,
input: DeleteBackupRequest,
) -> RusotoFuture<DeleteBackupResponse, DeleteBackupError>;
fn delete_cluster(
&self,
input: DeleteClusterRequest,
) -> RusotoFuture<DeleteClusterResponse, DeleteClusterError>;
fn delete_hsm(
&self,
input: DeleteHsmRequest,
) -> RusotoFuture<DeleteHsmResponse, DeleteHsmError>;
fn describe_backups(
&self,
input: DescribeBackupsRequest,
) -> RusotoFuture<DescribeBackupsResponse, DescribeBackupsError>;
fn describe_clusters(
&self,
input: DescribeClustersRequest,
) -> RusotoFuture<DescribeClustersResponse, DescribeClustersError>;
fn initialize_cluster(
&self,
input: InitializeClusterRequest,
) -> RusotoFuture<InitializeClusterResponse, InitializeClusterError>;
fn list_tags(&self, input: ListTagsRequest) -> RusotoFuture<ListTagsResponse, ListTagsError>;
fn restore_backup(
&self,
input: RestoreBackupRequest,
) -> RusotoFuture<RestoreBackupResponse, RestoreBackupError>;
fn tag_resource(
&self,
input: TagResourceRequest,
) -> RusotoFuture<TagResourceResponse, TagResourceError>;
fn untag_resource(
&self,
input: UntagResourceRequest,
) -> RusotoFuture<UntagResourceResponse, UntagResourceError>;
}
#[derive(Clone)]
pub struct CloudHsmv2Client {
client: Client,
region: region::Region,
}
impl CloudHsmv2Client {
pub fn new(region: region::Region) -> CloudHsmv2Client {
CloudHsmv2Client {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> CloudHsmv2Client
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
CloudHsmv2Client {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl CloudHsmv2 for CloudHsmv2Client {
fn copy_backup_to_region(
&self,
input: CopyBackupToRegionRequest,
) -> RusotoFuture<CopyBackupToRegionResponse, CopyBackupToRegionError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.CopyBackupToRegion");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<CopyBackupToRegionResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CopyBackupToRegionError::from_response(response))),
)
}
})
}
fn create_cluster(
&self,
input: CreateClusterRequest,
) -> RusotoFuture<CreateClusterResponse, CreateClusterError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.CreateCluster");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<CreateClusterResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateClusterError::from_response(response))),
)
}
})
}
fn create_hsm(
&self,
input: CreateHsmRequest,
) -> RusotoFuture<CreateHsmResponse, CreateHsmError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.CreateHsm");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<CreateHsmResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateHsmError::from_response(response))),
)
}
})
}
fn delete_backup(
&self,
input: DeleteBackupRequest,
) -> RusotoFuture<DeleteBackupResponse, DeleteBackupError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.DeleteBackup");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DeleteBackupResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteBackupError::from_response(response))),
)
}
})
}
fn delete_cluster(
&self,
input: DeleteClusterRequest,
) -> RusotoFuture<DeleteClusterResponse, DeleteClusterError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.DeleteCluster");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DeleteClusterResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteClusterError::from_response(response))),
)
}
})
}
fn delete_hsm(
&self,
input: DeleteHsmRequest,
) -> RusotoFuture<DeleteHsmResponse, DeleteHsmError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.DeleteHsm");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DeleteHsmResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteHsmError::from_response(response))),
)
}
})
}
fn describe_backups(
&self,
input: DescribeBackupsRequest,
) -> RusotoFuture<DescribeBackupsResponse, DescribeBackupsError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.DescribeBackups");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DescribeBackupsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeBackupsError::from_response(response))),
)
}
})
}
fn describe_clusters(
&self,
input: DescribeClustersRequest,
) -> RusotoFuture<DescribeClustersResponse, DescribeClustersError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.DescribeClusters");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<DescribeClustersResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeClustersError::from_response(response))),
)
}
})
}
fn initialize_cluster(
&self,
input: InitializeClusterRequest,
) -> RusotoFuture<InitializeClusterResponse, InitializeClusterError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.InitializeCluster");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<InitializeClusterResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(InitializeClusterError::from_response(response))),
)
}
})
}
fn list_tags(&self, input: ListTagsRequest) -> RusotoFuture<ListTagsResponse, ListTagsError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.ListTags");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<ListTagsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListTagsError::from_response(response))),
)
}
})
}
fn restore_backup(
&self,
input: RestoreBackupRequest,
) -> RusotoFuture<RestoreBackupResponse, RestoreBackupError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.RestoreBackup");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<RestoreBackupResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(RestoreBackupError::from_response(response))),
)
}
})
}
fn tag_resource(
&self,
input: TagResourceRequest,
) -> RusotoFuture<TagResourceResponse, TagResourceError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.TagResource");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<TagResourceResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(TagResourceError::from_response(response))),
)
}
})
}
fn untag_resource(
&self,
input: UntagResourceRequest,
) -> RusotoFuture<UntagResourceResponse, UntagResourceError> {
let mut request = SignedRequest::new("POST", "cloudhsm", &self.region, "/");
request.set_endpoint_prefix("cloudhsmv2".to_string());
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "BaldrApiService.UntagResource");
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded.into_bytes()));
self.client.sign_and_dispatch(request, |response| {
if response.status.is_success() {
Box::new(response.buffer().from_err().map(|response| {
let mut body = response.body;
if body.is_empty() || body == b"null" {
body = b"{}".to_vec();
}
serde_json::from_str::<UntagResourceResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UntagResourceError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}