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, Serialize)]
pub struct AddTagsRequest {
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "TagsList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags_list: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct AddTagsResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateTrailRequest {
#[serde(rename = "CloudWatchLogsLogGroupArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_log_group_arn: Option<String>,
#[serde(rename = "CloudWatchLogsRoleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_role_arn: Option<String>,
#[serde(rename = "EnableLogFileValidation")]
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_log_file_validation: Option<bool>,
#[serde(rename = "IncludeGlobalServiceEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_global_service_events: Option<bool>,
#[serde(rename = "IsMultiRegionTrail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_multi_region_trail: Option<bool>,
#[serde(rename = "KmsKeyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kms_key_id: Option<String>,
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "S3BucketName")]
pub s3_bucket_name: String,
#[serde(rename = "S3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_key_prefix: Option<String>,
#[serde(rename = "SnsTopicName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_name: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateTrailResponse {
#[serde(rename = "CloudWatchLogsLogGroupArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_log_group_arn: Option<String>,
#[serde(rename = "CloudWatchLogsRoleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_role_arn: Option<String>,
#[serde(rename = "IncludeGlobalServiceEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_global_service_events: Option<bool>,
#[serde(rename = "IsMultiRegionTrail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_multi_region_trail: Option<bool>,
#[serde(rename = "KmsKeyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kms_key_id: Option<String>,
#[serde(rename = "LogFileValidationEnabled")]
#[serde(skip_serializing_if = "Option::is_none")]
pub log_file_validation_enabled: Option<bool>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "S3BucketName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_bucket_name: Option<String>,
#[serde(rename = "S3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_key_prefix: Option<String>,
#[serde(rename = "SnsTopicARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
#[serde(rename = "TrailARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DataResource {
#[serde(rename = "Type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<String>,
#[serde(rename = "Values")]
#[serde(skip_serializing_if = "Option::is_none")]
pub values: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteTrailRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteTrailResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeTrailsRequest {
#[serde(rename = "includeShadowTrails")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_shadow_trails: Option<bool>,
#[serde(rename = "trailNameList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_name_list: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeTrailsResponse {
#[serde(rename = "trailList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_list: Option<Vec<Trail>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Event {
#[serde(rename = "CloudTrailEvent")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_trail_event: Option<String>,
#[serde(rename = "EventId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_id: Option<String>,
#[serde(rename = "EventName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_name: Option<String>,
#[serde(rename = "EventSource")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_source: Option<String>,
#[serde(rename = "EventTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_time: Option<f64>,
#[serde(rename = "Resources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resources: Option<Vec<Resource>>,
#[serde(rename = "Username")]
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventSelector {
#[serde(rename = "DataResources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub data_resources: Option<Vec<DataResource>>,
#[serde(rename = "IncludeManagementEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_management_events: Option<bool>,
#[serde(rename = "ReadWriteType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub read_write_type: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetEventSelectorsRequest {
#[serde(rename = "TrailName")]
pub trail_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetEventSelectorsResponse {
#[serde(rename = "EventSelectors")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_selectors: Option<Vec<EventSelector>>,
#[serde(rename = "TrailARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetTrailStatusRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetTrailStatusResponse {
#[serde(rename = "IsLogging")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_logging: Option<bool>,
#[serde(rename = "LatestCloudWatchLogsDeliveryError")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_cloud_watch_logs_delivery_error: Option<String>,
#[serde(rename = "LatestCloudWatchLogsDeliveryTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_cloud_watch_logs_delivery_time: Option<f64>,
#[serde(rename = "LatestDeliveryAttemptSucceeded")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_delivery_attempt_succeeded: Option<String>,
#[serde(rename = "LatestDeliveryAttemptTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_delivery_attempt_time: Option<String>,
#[serde(rename = "LatestDeliveryError")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_delivery_error: Option<String>,
#[serde(rename = "LatestDeliveryTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_delivery_time: Option<f64>,
#[serde(rename = "LatestDigestDeliveryError")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_digest_delivery_error: Option<String>,
#[serde(rename = "LatestDigestDeliveryTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_digest_delivery_time: Option<f64>,
#[serde(rename = "LatestNotificationAttemptSucceeded")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_notification_attempt_succeeded: Option<String>,
#[serde(rename = "LatestNotificationAttemptTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_notification_attempt_time: Option<String>,
#[serde(rename = "LatestNotificationError")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_notification_error: Option<String>,
#[serde(rename = "LatestNotificationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub latest_notification_time: Option<f64>,
#[serde(rename = "StartLoggingTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub start_logging_time: Option<f64>,
#[serde(rename = "StopLoggingTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub stop_logging_time: Option<f64>,
#[serde(rename = "TimeLoggingStarted")]
#[serde(skip_serializing_if = "Option::is_none")]
pub time_logging_started: Option<String>,
#[serde(rename = "TimeLoggingStopped")]
#[serde(skip_serializing_if = "Option::is_none")]
pub time_logging_stopped: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListPublicKeysRequest {
#[serde(rename = "EndTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub end_time: Option<f64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "StartTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub start_time: Option<f64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListPublicKeysResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "PublicKeyList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub public_key_list: Option<Vec<PublicKey>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListTagsRequest {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "ResourceIdList")]
pub resource_id_list: Vec<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 = "ResourceTagList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_tag_list: Option<Vec<ResourceTag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct LookupAttribute {
#[serde(rename = "AttributeKey")]
pub attribute_key: String,
#[serde(rename = "AttributeValue")]
pub attribute_value: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct LookupEventsRequest {
#[serde(rename = "EndTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub end_time: Option<f64>,
#[serde(rename = "LookupAttributes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub lookup_attributes: Option<Vec<LookupAttribute>>,
#[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 = "StartTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub start_time: Option<f64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct LookupEventsResponse {
#[serde(rename = "Events")]
#[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<Event>>,
#[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 PublicKey {
#[serde(rename = "Fingerprint")]
#[serde(skip_serializing_if = "Option::is_none")]
pub fingerprint: Option<String>,
#[serde(rename = "ValidityEndTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub validity_end_time: Option<f64>,
#[serde(rename = "ValidityStartTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub validity_start_time: Option<f64>,
#[serde(rename = "Value")]
#[serde(
deserialize_with = "::rusoto_core::serialization::SerdeBlob::deserialize_blob",
serialize_with = "::rusoto_core::serialization::SerdeBlob::serialize_blob",
default
)]
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<Vec<u8>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct PutEventSelectorsRequest {
#[serde(rename = "EventSelectors")]
pub event_selectors: Vec<EventSelector>,
#[serde(rename = "TrailName")]
pub trail_name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PutEventSelectorsResponse {
#[serde(rename = "EventSelectors")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_selectors: Option<Vec<EventSelector>>,
#[serde(rename = "TrailARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct RemoveTagsRequest {
#[serde(rename = "ResourceId")]
pub resource_id: String,
#[serde(rename = "TagsList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags_list: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct RemoveTagsResponse {}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Resource {
#[serde(rename = "ResourceName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_name: Option<String>,
#[serde(rename = "ResourceType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_type: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ResourceTag {
#[serde(rename = "ResourceId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_id: Option<String>,
#[serde(rename = "TagsList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags_list: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct StartLoggingRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct StartLoggingResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct StopLoggingRequest {
#[serde(rename = "Name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct StopLoggingResponse {}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tag {
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "Value")]
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Trail {
#[serde(rename = "CloudWatchLogsLogGroupArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_log_group_arn: Option<String>,
#[serde(rename = "CloudWatchLogsRoleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_role_arn: Option<String>,
#[serde(rename = "HasCustomEventSelectors")]
#[serde(skip_serializing_if = "Option::is_none")]
pub has_custom_event_selectors: Option<bool>,
#[serde(rename = "HomeRegion")]
#[serde(skip_serializing_if = "Option::is_none")]
pub home_region: Option<String>,
#[serde(rename = "IncludeGlobalServiceEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_global_service_events: Option<bool>,
#[serde(rename = "IsMultiRegionTrail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_multi_region_trail: Option<bool>,
#[serde(rename = "KmsKeyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kms_key_id: Option<String>,
#[serde(rename = "LogFileValidationEnabled")]
#[serde(skip_serializing_if = "Option::is_none")]
pub log_file_validation_enabled: Option<bool>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "S3BucketName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_bucket_name: Option<String>,
#[serde(rename = "S3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_key_prefix: Option<String>,
#[serde(rename = "SnsTopicARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
#[serde(rename = "TrailARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UpdateTrailRequest {
#[serde(rename = "CloudWatchLogsLogGroupArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_log_group_arn: Option<String>,
#[serde(rename = "CloudWatchLogsRoleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_role_arn: Option<String>,
#[serde(rename = "EnableLogFileValidation")]
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_log_file_validation: Option<bool>,
#[serde(rename = "IncludeGlobalServiceEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_global_service_events: Option<bool>,
#[serde(rename = "IsMultiRegionTrail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_multi_region_trail: Option<bool>,
#[serde(rename = "KmsKeyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kms_key_id: Option<String>,
#[serde(rename = "Name")]
pub name: String,
#[serde(rename = "S3BucketName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_bucket_name: Option<String>,
#[serde(rename = "S3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_key_prefix: Option<String>,
#[serde(rename = "SnsTopicName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_name: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateTrailResponse {
#[serde(rename = "CloudWatchLogsLogGroupArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_log_group_arn: Option<String>,
#[serde(rename = "CloudWatchLogsRoleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_watch_logs_role_arn: Option<String>,
#[serde(rename = "IncludeGlobalServiceEvents")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_global_service_events: Option<bool>,
#[serde(rename = "IsMultiRegionTrail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub is_multi_region_trail: Option<bool>,
#[serde(rename = "KmsKeyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kms_key_id: Option<String>,
#[serde(rename = "LogFileValidationEnabled")]
#[serde(skip_serializing_if = "Option::is_none")]
pub log_file_validation_enabled: Option<bool>,
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "S3BucketName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_bucket_name: Option<String>,
#[serde(rename = "S3KeyPrefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s3_key_prefix: Option<String>,
#[serde(rename = "SnsTopicARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
#[serde(rename = "TrailARN")]
#[serde(skip_serializing_if = "Option::is_none")]
pub trail_arn: Option<String>,
}
#[derive(Debug, PartialEq)]
pub enum AddTagsError {
CloudTrailARNInvalid(String),
InvalidTagParameter(String),
InvalidTrailName(String),
OperationNotPermitted(String),
ResourceNotFound(String),
ResourceTypeNotSupported(String),
TagsLimitExceeded(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl AddTagsError {
pub fn from_response(res: BufferedHttpResponse) -> AddTagsError {
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 {
"CloudTrailARNInvalidException" => {
return AddTagsError::CloudTrailARNInvalid(String::from(error_message))
}
"InvalidTagParameterException" => {
return AddTagsError::InvalidTagParameter(String::from(error_message))
}
"InvalidTrailNameException" => {
return AddTagsError::InvalidTrailName(String::from(error_message))
}
"OperationNotPermittedException" => {
return AddTagsError::OperationNotPermitted(String::from(error_message))
}
"ResourceNotFoundException" => {
return AddTagsError::ResourceNotFound(String::from(error_message))
}
"ResourceTypeNotSupportedException" => {
return AddTagsError::ResourceTypeNotSupported(String::from(error_message))
}
"TagsLimitExceededException" => {
return AddTagsError::TagsLimitExceeded(String::from(error_message))
}
"UnsupportedOperationException" => {
return AddTagsError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => return AddTagsError::Validation(error_message.to_string()),
_ => {}
}
}
return AddTagsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for AddTagsError {
fn from(err: serde_json::error::Error) -> AddTagsError {
AddTagsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for AddTagsError {
fn from(err: CredentialsError) -> AddTagsError {
AddTagsError::Credentials(err)
}
}
impl From<HttpDispatchError> for AddTagsError {
fn from(err: HttpDispatchError) -> AddTagsError {
AddTagsError::HttpDispatch(err)
}
}
impl From<io::Error> for AddTagsError {
fn from(err: io::Error) -> AddTagsError {
AddTagsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for AddTagsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for AddTagsError {
fn description(&self) -> &str {
match *self {
AddTagsError::CloudTrailARNInvalid(ref cause) => cause,
AddTagsError::InvalidTagParameter(ref cause) => cause,
AddTagsError::InvalidTrailName(ref cause) => cause,
AddTagsError::OperationNotPermitted(ref cause) => cause,
AddTagsError::ResourceNotFound(ref cause) => cause,
AddTagsError::ResourceTypeNotSupported(ref cause) => cause,
AddTagsError::TagsLimitExceeded(ref cause) => cause,
AddTagsError::UnsupportedOperation(ref cause) => cause,
AddTagsError::Validation(ref cause) => cause,
AddTagsError::Credentials(ref err) => err.description(),
AddTagsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
AddTagsError::ParseError(ref cause) => cause,
AddTagsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum CreateTrailError {
CloudWatchLogsDeliveryUnavailable(String),
InsufficientEncryptionPolicy(String),
InsufficientS3BucketPolicy(String),
InsufficientSnsTopicPolicy(String),
InvalidCloudWatchLogsLogGroupArn(String),
InvalidCloudWatchLogsRoleArn(String),
InvalidKmsKeyId(String),
InvalidParameterCombination(String),
InvalidS3BucketName(String),
InvalidS3Prefix(String),
InvalidSnsTopicName(String),
InvalidTrailName(String),
Kms(String),
KmsKeyDisabled(String),
KmsKeyNotFound(String),
MaximumNumberOfTrailsExceeded(String),
OperationNotPermitted(String),
S3BucketDoesNotExist(String),
TrailAlreadyExists(String),
TrailNotProvided(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateTrailError {
pub fn from_response(res: BufferedHttpResponse) -> CreateTrailError {
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 {
"CloudWatchLogsDeliveryUnavailableException" => {
return CreateTrailError::CloudWatchLogsDeliveryUnavailable(String::from(
error_message,
))
}
"InsufficientEncryptionPolicyException" => {
return CreateTrailError::InsufficientEncryptionPolicy(String::from(
error_message,
))
}
"InsufficientS3BucketPolicyException" => {
return CreateTrailError::InsufficientS3BucketPolicy(String::from(error_message))
}
"InsufficientSnsTopicPolicyException" => {
return CreateTrailError::InsufficientSnsTopicPolicy(String::from(error_message))
}
"InvalidCloudWatchLogsLogGroupArnException" => {
return CreateTrailError::InvalidCloudWatchLogsLogGroupArn(String::from(
error_message,
))
}
"InvalidCloudWatchLogsRoleArnException" => {
return CreateTrailError::InvalidCloudWatchLogsRoleArn(String::from(
error_message,
))
}
"InvalidKmsKeyIdException" => {
return CreateTrailError::InvalidKmsKeyId(String::from(error_message))
}
"InvalidParameterCombinationException" => {
return CreateTrailError::InvalidParameterCombination(String::from(
error_message,
))
}
"InvalidS3BucketNameException" => {
return CreateTrailError::InvalidS3BucketName(String::from(error_message))
}
"InvalidS3PrefixException" => {
return CreateTrailError::InvalidS3Prefix(String::from(error_message))
}
"InvalidSnsTopicNameException" => {
return CreateTrailError::InvalidSnsTopicName(String::from(error_message))
}
"InvalidTrailNameException" => {
return CreateTrailError::InvalidTrailName(String::from(error_message))
}
"KmsException" => return CreateTrailError::Kms(String::from(error_message)),
"KmsKeyDisabledException" => {
return CreateTrailError::KmsKeyDisabled(String::from(error_message))
}
"KmsKeyNotFoundException" => {
return CreateTrailError::KmsKeyNotFound(String::from(error_message))
}
"MaximumNumberOfTrailsExceededException" => {
return CreateTrailError::MaximumNumberOfTrailsExceeded(String::from(
error_message,
))
}
"OperationNotPermittedException" => {
return CreateTrailError::OperationNotPermitted(String::from(error_message))
}
"S3BucketDoesNotExistException" => {
return CreateTrailError::S3BucketDoesNotExist(String::from(error_message))
}
"TrailAlreadyExistsException" => {
return CreateTrailError::TrailAlreadyExists(String::from(error_message))
}
"TrailNotProvidedException" => {
return CreateTrailError::TrailNotProvided(String::from(error_message))
}
"UnsupportedOperationException" => {
return CreateTrailError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return CreateTrailError::Validation(error_message.to_string())
}
_ => {}
}
}
return CreateTrailError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateTrailError {
fn from(err: serde_json::error::Error) -> CreateTrailError {
CreateTrailError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateTrailError {
fn from(err: CredentialsError) -> CreateTrailError {
CreateTrailError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateTrailError {
fn from(err: HttpDispatchError) -> CreateTrailError {
CreateTrailError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateTrailError {
fn from(err: io::Error) -> CreateTrailError {
CreateTrailError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateTrailError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateTrailError {
fn description(&self) -> &str {
match *self {
CreateTrailError::CloudWatchLogsDeliveryUnavailable(ref cause) => cause,
CreateTrailError::InsufficientEncryptionPolicy(ref cause) => cause,
CreateTrailError::InsufficientS3BucketPolicy(ref cause) => cause,
CreateTrailError::InsufficientSnsTopicPolicy(ref cause) => cause,
CreateTrailError::InvalidCloudWatchLogsLogGroupArn(ref cause) => cause,
CreateTrailError::InvalidCloudWatchLogsRoleArn(ref cause) => cause,
CreateTrailError::InvalidKmsKeyId(ref cause) => cause,
CreateTrailError::InvalidParameterCombination(ref cause) => cause,
CreateTrailError::InvalidS3BucketName(ref cause) => cause,
CreateTrailError::InvalidS3Prefix(ref cause) => cause,
CreateTrailError::InvalidSnsTopicName(ref cause) => cause,
CreateTrailError::InvalidTrailName(ref cause) => cause,
CreateTrailError::Kms(ref cause) => cause,
CreateTrailError::KmsKeyDisabled(ref cause) => cause,
CreateTrailError::KmsKeyNotFound(ref cause) => cause,
CreateTrailError::MaximumNumberOfTrailsExceeded(ref cause) => cause,
CreateTrailError::OperationNotPermitted(ref cause) => cause,
CreateTrailError::S3BucketDoesNotExist(ref cause) => cause,
CreateTrailError::TrailAlreadyExists(ref cause) => cause,
CreateTrailError::TrailNotProvided(ref cause) => cause,
CreateTrailError::UnsupportedOperation(ref cause) => cause,
CreateTrailError::Validation(ref cause) => cause,
CreateTrailError::Credentials(ref err) => err.description(),
CreateTrailError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
CreateTrailError::ParseError(ref cause) => cause,
CreateTrailError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteTrailError {
InvalidHomeRegion(String),
InvalidTrailName(String),
TrailNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteTrailError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteTrailError {
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 {
"InvalidHomeRegionException" => {
return DeleteTrailError::InvalidHomeRegion(String::from(error_message))
}
"InvalidTrailNameException" => {
return DeleteTrailError::InvalidTrailName(String::from(error_message))
}
"TrailNotFoundException" => {
return DeleteTrailError::TrailNotFound(String::from(error_message))
}
"ValidationException" => {
return DeleteTrailError::Validation(error_message.to_string())
}
_ => {}
}
}
return DeleteTrailError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteTrailError {
fn from(err: serde_json::error::Error) -> DeleteTrailError {
DeleteTrailError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteTrailError {
fn from(err: CredentialsError) -> DeleteTrailError {
DeleteTrailError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteTrailError {
fn from(err: HttpDispatchError) -> DeleteTrailError {
DeleteTrailError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteTrailError {
fn from(err: io::Error) -> DeleteTrailError {
DeleteTrailError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteTrailError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteTrailError {
fn description(&self) -> &str {
match *self {
DeleteTrailError::InvalidHomeRegion(ref cause) => cause,
DeleteTrailError::InvalidTrailName(ref cause) => cause,
DeleteTrailError::TrailNotFound(ref cause) => cause,
DeleteTrailError::Validation(ref cause) => cause,
DeleteTrailError::Credentials(ref err) => err.description(),
DeleteTrailError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteTrailError::ParseError(ref cause) => cause,
DeleteTrailError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeTrailsError {
OperationNotPermitted(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeTrailsError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeTrailsError {
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 {
"OperationNotPermittedException" => {
return DescribeTrailsError::OperationNotPermitted(String::from(error_message))
}
"UnsupportedOperationException" => {
return DescribeTrailsError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return DescribeTrailsError::Validation(error_message.to_string())
}
_ => {}
}
}
return DescribeTrailsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeTrailsError {
fn from(err: serde_json::error::Error) -> DescribeTrailsError {
DescribeTrailsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeTrailsError {
fn from(err: CredentialsError) -> DescribeTrailsError {
DescribeTrailsError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeTrailsError {
fn from(err: HttpDispatchError) -> DescribeTrailsError {
DescribeTrailsError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeTrailsError {
fn from(err: io::Error) -> DescribeTrailsError {
DescribeTrailsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeTrailsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeTrailsError {
fn description(&self) -> &str {
match *self {
DescribeTrailsError::OperationNotPermitted(ref cause) => cause,
DescribeTrailsError::UnsupportedOperation(ref cause) => cause,
DescribeTrailsError::Validation(ref cause) => cause,
DescribeTrailsError::Credentials(ref err) => err.description(),
DescribeTrailsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeTrailsError::ParseError(ref cause) => cause,
DescribeTrailsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetEventSelectorsError {
InvalidTrailName(String),
OperationNotPermitted(String),
TrailNotFound(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetEventSelectorsError {
pub fn from_response(res: BufferedHttpResponse) -> GetEventSelectorsError {
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 {
"InvalidTrailNameException" => {
return GetEventSelectorsError::InvalidTrailName(String::from(error_message))
}
"OperationNotPermittedException" => {
return GetEventSelectorsError::OperationNotPermitted(String::from(
error_message,
))
}
"TrailNotFoundException" => {
return GetEventSelectorsError::TrailNotFound(String::from(error_message))
}
"UnsupportedOperationException" => {
return GetEventSelectorsError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return GetEventSelectorsError::Validation(error_message.to_string())
}
_ => {}
}
}
return GetEventSelectorsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetEventSelectorsError {
fn from(err: serde_json::error::Error) -> GetEventSelectorsError {
GetEventSelectorsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetEventSelectorsError {
fn from(err: CredentialsError) -> GetEventSelectorsError {
GetEventSelectorsError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetEventSelectorsError {
fn from(err: HttpDispatchError) -> GetEventSelectorsError {
GetEventSelectorsError::HttpDispatch(err)
}
}
impl From<io::Error> for GetEventSelectorsError {
fn from(err: io::Error) -> GetEventSelectorsError {
GetEventSelectorsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetEventSelectorsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetEventSelectorsError {
fn description(&self) -> &str {
match *self {
GetEventSelectorsError::InvalidTrailName(ref cause) => cause,
GetEventSelectorsError::OperationNotPermitted(ref cause) => cause,
GetEventSelectorsError::TrailNotFound(ref cause) => cause,
GetEventSelectorsError::UnsupportedOperation(ref cause) => cause,
GetEventSelectorsError::Validation(ref cause) => cause,
GetEventSelectorsError::Credentials(ref err) => err.description(),
GetEventSelectorsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
GetEventSelectorsError::ParseError(ref cause) => cause,
GetEventSelectorsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetTrailStatusError {
InvalidTrailName(String),
TrailNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl GetTrailStatusError {
pub fn from_response(res: BufferedHttpResponse) -> GetTrailStatusError {
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 {
"InvalidTrailNameException" => {
return GetTrailStatusError::InvalidTrailName(String::from(error_message))
}
"TrailNotFoundException" => {
return GetTrailStatusError::TrailNotFound(String::from(error_message))
}
"ValidationException" => {
return GetTrailStatusError::Validation(error_message.to_string())
}
_ => {}
}
}
return GetTrailStatusError::Unknown(res);
}
}
impl From<serde_json::error::Error> for GetTrailStatusError {
fn from(err: serde_json::error::Error) -> GetTrailStatusError {
GetTrailStatusError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for GetTrailStatusError {
fn from(err: CredentialsError) -> GetTrailStatusError {
GetTrailStatusError::Credentials(err)
}
}
impl From<HttpDispatchError> for GetTrailStatusError {
fn from(err: HttpDispatchError) -> GetTrailStatusError {
GetTrailStatusError::HttpDispatch(err)
}
}
impl From<io::Error> for GetTrailStatusError {
fn from(err: io::Error) -> GetTrailStatusError {
GetTrailStatusError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for GetTrailStatusError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetTrailStatusError {
fn description(&self) -> &str {
match *self {
GetTrailStatusError::InvalidTrailName(ref cause) => cause,
GetTrailStatusError::TrailNotFound(ref cause) => cause,
GetTrailStatusError::Validation(ref cause) => cause,
GetTrailStatusError::Credentials(ref err) => err.description(),
GetTrailStatusError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
GetTrailStatusError::ParseError(ref cause) => cause,
GetTrailStatusError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListPublicKeysError {
InvalidTimeRange(String),
InvalidToken(String),
OperationNotPermitted(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListPublicKeysError {
pub fn from_response(res: BufferedHttpResponse) -> ListPublicKeysError {
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 {
"InvalidTimeRangeException" => {
return ListPublicKeysError::InvalidTimeRange(String::from(error_message))
}
"InvalidTokenException" => {
return ListPublicKeysError::InvalidToken(String::from(error_message))
}
"OperationNotPermittedException" => {
return ListPublicKeysError::OperationNotPermitted(String::from(error_message))
}
"UnsupportedOperationException" => {
return ListPublicKeysError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return ListPublicKeysError::Validation(error_message.to_string())
}
_ => {}
}
}
return ListPublicKeysError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListPublicKeysError {
fn from(err: serde_json::error::Error) -> ListPublicKeysError {
ListPublicKeysError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListPublicKeysError {
fn from(err: CredentialsError) -> ListPublicKeysError {
ListPublicKeysError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListPublicKeysError {
fn from(err: HttpDispatchError) -> ListPublicKeysError {
ListPublicKeysError::HttpDispatch(err)
}
}
impl From<io::Error> for ListPublicKeysError {
fn from(err: io::Error) -> ListPublicKeysError {
ListPublicKeysError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListPublicKeysError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListPublicKeysError {
fn description(&self) -> &str {
match *self {
ListPublicKeysError::InvalidTimeRange(ref cause) => cause,
ListPublicKeysError::InvalidToken(ref cause) => cause,
ListPublicKeysError::OperationNotPermitted(ref cause) => cause,
ListPublicKeysError::UnsupportedOperation(ref cause) => cause,
ListPublicKeysError::Validation(ref cause) => cause,
ListPublicKeysError::Credentials(ref err) => err.description(),
ListPublicKeysError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListPublicKeysError::ParseError(ref cause) => cause,
ListPublicKeysError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListTagsError {
CloudTrailARNInvalid(String),
InvalidToken(String),
InvalidTrailName(String),
OperationNotPermitted(String),
ResourceNotFound(String),
ResourceTypeNotSupported(String),
UnsupportedOperation(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 {
"CloudTrailARNInvalidException" => {
return ListTagsError::CloudTrailARNInvalid(String::from(error_message))
}
"InvalidTokenException" => {
return ListTagsError::InvalidToken(String::from(error_message))
}
"InvalidTrailNameException" => {
return ListTagsError::InvalidTrailName(String::from(error_message))
}
"OperationNotPermittedException" => {
return ListTagsError::OperationNotPermitted(String::from(error_message))
}
"ResourceNotFoundException" => {
return ListTagsError::ResourceNotFound(String::from(error_message))
}
"ResourceTypeNotSupportedException" => {
return ListTagsError::ResourceTypeNotSupported(String::from(error_message))
}
"UnsupportedOperationException" => {
return ListTagsError::UnsupportedOperation(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::CloudTrailARNInvalid(ref cause) => cause,
ListTagsError::InvalidToken(ref cause) => cause,
ListTagsError::InvalidTrailName(ref cause) => cause,
ListTagsError::OperationNotPermitted(ref cause) => cause,
ListTagsError::ResourceNotFound(ref cause) => cause,
ListTagsError::ResourceTypeNotSupported(ref cause) => cause,
ListTagsError::UnsupportedOperation(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 LookupEventsError {
InvalidLookupAttributes(String),
InvalidMaxResults(String),
InvalidNextToken(String),
InvalidTimeRange(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl LookupEventsError {
pub fn from_response(res: BufferedHttpResponse) -> LookupEventsError {
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 {
"InvalidLookupAttributesException" => {
return LookupEventsError::InvalidLookupAttributes(String::from(error_message))
}
"InvalidMaxResultsException" => {
return LookupEventsError::InvalidMaxResults(String::from(error_message))
}
"InvalidNextTokenException" => {
return LookupEventsError::InvalidNextToken(String::from(error_message))
}
"InvalidTimeRangeException" => {
return LookupEventsError::InvalidTimeRange(String::from(error_message))
}
"ValidationException" => {
return LookupEventsError::Validation(error_message.to_string())
}
_ => {}
}
}
return LookupEventsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for LookupEventsError {
fn from(err: serde_json::error::Error) -> LookupEventsError {
LookupEventsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for LookupEventsError {
fn from(err: CredentialsError) -> LookupEventsError {
LookupEventsError::Credentials(err)
}
}
impl From<HttpDispatchError> for LookupEventsError {
fn from(err: HttpDispatchError) -> LookupEventsError {
LookupEventsError::HttpDispatch(err)
}
}
impl From<io::Error> for LookupEventsError {
fn from(err: io::Error) -> LookupEventsError {
LookupEventsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for LookupEventsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for LookupEventsError {
fn description(&self) -> &str {
match *self {
LookupEventsError::InvalidLookupAttributes(ref cause) => cause,
LookupEventsError::InvalidMaxResults(ref cause) => cause,
LookupEventsError::InvalidNextToken(ref cause) => cause,
LookupEventsError::InvalidTimeRange(ref cause) => cause,
LookupEventsError::Validation(ref cause) => cause,
LookupEventsError::Credentials(ref err) => err.description(),
LookupEventsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
LookupEventsError::ParseError(ref cause) => cause,
LookupEventsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum PutEventSelectorsError {
InvalidEventSelectors(String),
InvalidHomeRegion(String),
InvalidTrailName(String),
OperationNotPermitted(String),
TrailNotFound(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl PutEventSelectorsError {
pub fn from_response(res: BufferedHttpResponse) -> PutEventSelectorsError {
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 {
"InvalidEventSelectorsException" => {
return PutEventSelectorsError::InvalidEventSelectors(String::from(
error_message,
))
}
"InvalidHomeRegionException" => {
return PutEventSelectorsError::InvalidHomeRegion(String::from(error_message))
}
"InvalidTrailNameException" => {
return PutEventSelectorsError::InvalidTrailName(String::from(error_message))
}
"OperationNotPermittedException" => {
return PutEventSelectorsError::OperationNotPermitted(String::from(
error_message,
))
}
"TrailNotFoundException" => {
return PutEventSelectorsError::TrailNotFound(String::from(error_message))
}
"UnsupportedOperationException" => {
return PutEventSelectorsError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return PutEventSelectorsError::Validation(error_message.to_string())
}
_ => {}
}
}
return PutEventSelectorsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for PutEventSelectorsError {
fn from(err: serde_json::error::Error) -> PutEventSelectorsError {
PutEventSelectorsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for PutEventSelectorsError {
fn from(err: CredentialsError) -> PutEventSelectorsError {
PutEventSelectorsError::Credentials(err)
}
}
impl From<HttpDispatchError> for PutEventSelectorsError {
fn from(err: HttpDispatchError) -> PutEventSelectorsError {
PutEventSelectorsError::HttpDispatch(err)
}
}
impl From<io::Error> for PutEventSelectorsError {
fn from(err: io::Error) -> PutEventSelectorsError {
PutEventSelectorsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for PutEventSelectorsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for PutEventSelectorsError {
fn description(&self) -> &str {
match *self {
PutEventSelectorsError::InvalidEventSelectors(ref cause) => cause,
PutEventSelectorsError::InvalidHomeRegion(ref cause) => cause,
PutEventSelectorsError::InvalidTrailName(ref cause) => cause,
PutEventSelectorsError::OperationNotPermitted(ref cause) => cause,
PutEventSelectorsError::TrailNotFound(ref cause) => cause,
PutEventSelectorsError::UnsupportedOperation(ref cause) => cause,
PutEventSelectorsError::Validation(ref cause) => cause,
PutEventSelectorsError::Credentials(ref err) => err.description(),
PutEventSelectorsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
PutEventSelectorsError::ParseError(ref cause) => cause,
PutEventSelectorsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum RemoveTagsError {
CloudTrailARNInvalid(String),
InvalidTagParameter(String),
InvalidTrailName(String),
OperationNotPermitted(String),
ResourceNotFound(String),
ResourceTypeNotSupported(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl RemoveTagsError {
pub fn from_response(res: BufferedHttpResponse) -> RemoveTagsError {
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 {
"CloudTrailARNInvalidException" => {
return RemoveTagsError::CloudTrailARNInvalid(String::from(error_message))
}
"InvalidTagParameterException" => {
return RemoveTagsError::InvalidTagParameter(String::from(error_message))
}
"InvalidTrailNameException" => {
return RemoveTagsError::InvalidTrailName(String::from(error_message))
}
"OperationNotPermittedException" => {
return RemoveTagsError::OperationNotPermitted(String::from(error_message))
}
"ResourceNotFoundException" => {
return RemoveTagsError::ResourceNotFound(String::from(error_message))
}
"ResourceTypeNotSupportedException" => {
return RemoveTagsError::ResourceTypeNotSupported(String::from(error_message))
}
"UnsupportedOperationException" => {
return RemoveTagsError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return RemoveTagsError::Validation(error_message.to_string())
}
_ => {}
}
}
return RemoveTagsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for RemoveTagsError {
fn from(err: serde_json::error::Error) -> RemoveTagsError {
RemoveTagsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for RemoveTagsError {
fn from(err: CredentialsError) -> RemoveTagsError {
RemoveTagsError::Credentials(err)
}
}
impl From<HttpDispatchError> for RemoveTagsError {
fn from(err: HttpDispatchError) -> RemoveTagsError {
RemoveTagsError::HttpDispatch(err)
}
}
impl From<io::Error> for RemoveTagsError {
fn from(err: io::Error) -> RemoveTagsError {
RemoveTagsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for RemoveTagsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for RemoveTagsError {
fn description(&self) -> &str {
match *self {
RemoveTagsError::CloudTrailARNInvalid(ref cause) => cause,
RemoveTagsError::InvalidTagParameter(ref cause) => cause,
RemoveTagsError::InvalidTrailName(ref cause) => cause,
RemoveTagsError::OperationNotPermitted(ref cause) => cause,
RemoveTagsError::ResourceNotFound(ref cause) => cause,
RemoveTagsError::ResourceTypeNotSupported(ref cause) => cause,
RemoveTagsError::UnsupportedOperation(ref cause) => cause,
RemoveTagsError::Validation(ref cause) => cause,
RemoveTagsError::Credentials(ref err) => err.description(),
RemoveTagsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
RemoveTagsError::ParseError(ref cause) => cause,
RemoveTagsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum StartLoggingError {
InvalidHomeRegion(String),
InvalidTrailName(String),
TrailNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl StartLoggingError {
pub fn from_response(res: BufferedHttpResponse) -> StartLoggingError {
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 {
"InvalidHomeRegionException" => {
return StartLoggingError::InvalidHomeRegion(String::from(error_message))
}
"InvalidTrailNameException" => {
return StartLoggingError::InvalidTrailName(String::from(error_message))
}
"TrailNotFoundException" => {
return StartLoggingError::TrailNotFound(String::from(error_message))
}
"ValidationException" => {
return StartLoggingError::Validation(error_message.to_string())
}
_ => {}
}
}
return StartLoggingError::Unknown(res);
}
}
impl From<serde_json::error::Error> for StartLoggingError {
fn from(err: serde_json::error::Error) -> StartLoggingError {
StartLoggingError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for StartLoggingError {
fn from(err: CredentialsError) -> StartLoggingError {
StartLoggingError::Credentials(err)
}
}
impl From<HttpDispatchError> for StartLoggingError {
fn from(err: HttpDispatchError) -> StartLoggingError {
StartLoggingError::HttpDispatch(err)
}
}
impl From<io::Error> for StartLoggingError {
fn from(err: io::Error) -> StartLoggingError {
StartLoggingError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for StartLoggingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for StartLoggingError {
fn description(&self) -> &str {
match *self {
StartLoggingError::InvalidHomeRegion(ref cause) => cause,
StartLoggingError::InvalidTrailName(ref cause) => cause,
StartLoggingError::TrailNotFound(ref cause) => cause,
StartLoggingError::Validation(ref cause) => cause,
StartLoggingError::Credentials(ref err) => err.description(),
StartLoggingError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
StartLoggingError::ParseError(ref cause) => cause,
StartLoggingError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum StopLoggingError {
InvalidHomeRegion(String),
InvalidTrailName(String),
TrailNotFound(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl StopLoggingError {
pub fn from_response(res: BufferedHttpResponse) -> StopLoggingError {
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 {
"InvalidHomeRegionException" => {
return StopLoggingError::InvalidHomeRegion(String::from(error_message))
}
"InvalidTrailNameException" => {
return StopLoggingError::InvalidTrailName(String::from(error_message))
}
"TrailNotFoundException" => {
return StopLoggingError::TrailNotFound(String::from(error_message))
}
"ValidationException" => {
return StopLoggingError::Validation(error_message.to_string())
}
_ => {}
}
}
return StopLoggingError::Unknown(res);
}
}
impl From<serde_json::error::Error> for StopLoggingError {
fn from(err: serde_json::error::Error) -> StopLoggingError {
StopLoggingError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for StopLoggingError {
fn from(err: CredentialsError) -> StopLoggingError {
StopLoggingError::Credentials(err)
}
}
impl From<HttpDispatchError> for StopLoggingError {
fn from(err: HttpDispatchError) -> StopLoggingError {
StopLoggingError::HttpDispatch(err)
}
}
impl From<io::Error> for StopLoggingError {
fn from(err: io::Error) -> StopLoggingError {
StopLoggingError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for StopLoggingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for StopLoggingError {
fn description(&self) -> &str {
match *self {
StopLoggingError::InvalidHomeRegion(ref cause) => cause,
StopLoggingError::InvalidTrailName(ref cause) => cause,
StopLoggingError::TrailNotFound(ref cause) => cause,
StopLoggingError::Validation(ref cause) => cause,
StopLoggingError::Credentials(ref err) => err.description(),
StopLoggingError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
StopLoggingError::ParseError(ref cause) => cause,
StopLoggingError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UpdateTrailError {
CloudWatchLogsDeliveryUnavailable(String),
InsufficientEncryptionPolicy(String),
InsufficientS3BucketPolicy(String),
InsufficientSnsTopicPolicy(String),
InvalidCloudWatchLogsLogGroupArn(String),
InvalidCloudWatchLogsRoleArn(String),
InvalidHomeRegion(String),
InvalidKmsKeyId(String),
InvalidParameterCombination(String),
InvalidS3BucketName(String),
InvalidS3Prefix(String),
InvalidSnsTopicName(String),
InvalidTrailName(String),
Kms(String),
KmsKeyDisabled(String),
KmsKeyNotFound(String),
OperationNotPermitted(String),
S3BucketDoesNotExist(String),
TrailNotFound(String),
TrailNotProvided(String),
UnsupportedOperation(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UpdateTrailError {
pub fn from_response(res: BufferedHttpResponse) -> UpdateTrailError {
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 {
"CloudWatchLogsDeliveryUnavailableException" => {
return UpdateTrailError::CloudWatchLogsDeliveryUnavailable(String::from(
error_message,
))
}
"InsufficientEncryptionPolicyException" => {
return UpdateTrailError::InsufficientEncryptionPolicy(String::from(
error_message,
))
}
"InsufficientS3BucketPolicyException" => {
return UpdateTrailError::InsufficientS3BucketPolicy(String::from(error_message))
}
"InsufficientSnsTopicPolicyException" => {
return UpdateTrailError::InsufficientSnsTopicPolicy(String::from(error_message))
}
"InvalidCloudWatchLogsLogGroupArnException" => {
return UpdateTrailError::InvalidCloudWatchLogsLogGroupArn(String::from(
error_message,
))
}
"InvalidCloudWatchLogsRoleArnException" => {
return UpdateTrailError::InvalidCloudWatchLogsRoleArn(String::from(
error_message,
))
}
"InvalidHomeRegionException" => {
return UpdateTrailError::InvalidHomeRegion(String::from(error_message))
}
"InvalidKmsKeyIdException" => {
return UpdateTrailError::InvalidKmsKeyId(String::from(error_message))
}
"InvalidParameterCombinationException" => {
return UpdateTrailError::InvalidParameterCombination(String::from(
error_message,
))
}
"InvalidS3BucketNameException" => {
return UpdateTrailError::InvalidS3BucketName(String::from(error_message))
}
"InvalidS3PrefixException" => {
return UpdateTrailError::InvalidS3Prefix(String::from(error_message))
}
"InvalidSnsTopicNameException" => {
return UpdateTrailError::InvalidSnsTopicName(String::from(error_message))
}
"InvalidTrailNameException" => {
return UpdateTrailError::InvalidTrailName(String::from(error_message))
}
"KmsException" => return UpdateTrailError::Kms(String::from(error_message)),
"KmsKeyDisabledException" => {
return UpdateTrailError::KmsKeyDisabled(String::from(error_message))
}
"KmsKeyNotFoundException" => {
return UpdateTrailError::KmsKeyNotFound(String::from(error_message))
}
"OperationNotPermittedException" => {
return UpdateTrailError::OperationNotPermitted(String::from(error_message))
}
"S3BucketDoesNotExistException" => {
return UpdateTrailError::S3BucketDoesNotExist(String::from(error_message))
}
"TrailNotFoundException" => {
return UpdateTrailError::TrailNotFound(String::from(error_message))
}
"TrailNotProvidedException" => {
return UpdateTrailError::TrailNotProvided(String::from(error_message))
}
"UnsupportedOperationException" => {
return UpdateTrailError::UnsupportedOperation(String::from(error_message))
}
"ValidationException" => {
return UpdateTrailError::Validation(error_message.to_string())
}
_ => {}
}
}
return UpdateTrailError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UpdateTrailError {
fn from(err: serde_json::error::Error) -> UpdateTrailError {
UpdateTrailError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UpdateTrailError {
fn from(err: CredentialsError) -> UpdateTrailError {
UpdateTrailError::Credentials(err)
}
}
impl From<HttpDispatchError> for UpdateTrailError {
fn from(err: HttpDispatchError) -> UpdateTrailError {
UpdateTrailError::HttpDispatch(err)
}
}
impl From<io::Error> for UpdateTrailError {
fn from(err: io::Error) -> UpdateTrailError {
UpdateTrailError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UpdateTrailError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UpdateTrailError {
fn description(&self) -> &str {
match *self {
UpdateTrailError::CloudWatchLogsDeliveryUnavailable(ref cause) => cause,
UpdateTrailError::InsufficientEncryptionPolicy(ref cause) => cause,
UpdateTrailError::InsufficientS3BucketPolicy(ref cause) => cause,
UpdateTrailError::InsufficientSnsTopicPolicy(ref cause) => cause,
UpdateTrailError::InvalidCloudWatchLogsLogGroupArn(ref cause) => cause,
UpdateTrailError::InvalidCloudWatchLogsRoleArn(ref cause) => cause,
UpdateTrailError::InvalidHomeRegion(ref cause) => cause,
UpdateTrailError::InvalidKmsKeyId(ref cause) => cause,
UpdateTrailError::InvalidParameterCombination(ref cause) => cause,
UpdateTrailError::InvalidS3BucketName(ref cause) => cause,
UpdateTrailError::InvalidS3Prefix(ref cause) => cause,
UpdateTrailError::InvalidSnsTopicName(ref cause) => cause,
UpdateTrailError::InvalidTrailName(ref cause) => cause,
UpdateTrailError::Kms(ref cause) => cause,
UpdateTrailError::KmsKeyDisabled(ref cause) => cause,
UpdateTrailError::KmsKeyNotFound(ref cause) => cause,
UpdateTrailError::OperationNotPermitted(ref cause) => cause,
UpdateTrailError::S3BucketDoesNotExist(ref cause) => cause,
UpdateTrailError::TrailNotFound(ref cause) => cause,
UpdateTrailError::TrailNotProvided(ref cause) => cause,
UpdateTrailError::UnsupportedOperation(ref cause) => cause,
UpdateTrailError::Validation(ref cause) => cause,
UpdateTrailError::Credentials(ref err) => err.description(),
UpdateTrailError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
UpdateTrailError::ParseError(ref cause) => cause,
UpdateTrailError::Unknown(_) => "unknown error",
}
}
}
pub trait CloudTrail {
fn add_tags(&self, input: AddTagsRequest) -> RusotoFuture<AddTagsResponse, AddTagsError>;
fn create_trail(
&self,
input: CreateTrailRequest,
) -> RusotoFuture<CreateTrailResponse, CreateTrailError>;
fn delete_trail(
&self,
input: DeleteTrailRequest,
) -> RusotoFuture<DeleteTrailResponse, DeleteTrailError>;
fn describe_trails(
&self,
input: DescribeTrailsRequest,
) -> RusotoFuture<DescribeTrailsResponse, DescribeTrailsError>;
fn get_event_selectors(
&self,
input: GetEventSelectorsRequest,
) -> RusotoFuture<GetEventSelectorsResponse, GetEventSelectorsError>;
fn get_trail_status(
&self,
input: GetTrailStatusRequest,
) -> RusotoFuture<GetTrailStatusResponse, GetTrailStatusError>;
fn list_public_keys(
&self,
input: ListPublicKeysRequest,
) -> RusotoFuture<ListPublicKeysResponse, ListPublicKeysError>;
fn list_tags(&self, input: ListTagsRequest) -> RusotoFuture<ListTagsResponse, ListTagsError>;
fn lookup_events(
&self,
input: LookupEventsRequest,
) -> RusotoFuture<LookupEventsResponse, LookupEventsError>;
fn put_event_selectors(
&self,
input: PutEventSelectorsRequest,
) -> RusotoFuture<PutEventSelectorsResponse, PutEventSelectorsError>;
fn remove_tags(
&self,
input: RemoveTagsRequest,
) -> RusotoFuture<RemoveTagsResponse, RemoveTagsError>;
fn start_logging(
&self,
input: StartLoggingRequest,
) -> RusotoFuture<StartLoggingResponse, StartLoggingError>;
fn stop_logging(
&self,
input: StopLoggingRequest,
) -> RusotoFuture<StopLoggingResponse, StopLoggingError>;
fn update_trail(
&self,
input: UpdateTrailRequest,
) -> RusotoFuture<UpdateTrailResponse, UpdateTrailError>;
}
pub struct CloudTrailClient {
client: Client,
region: region::Region,
}
impl CloudTrailClient {
pub fn new(region: region::Region) -> CloudTrailClient {
CloudTrailClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> CloudTrailClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
CloudTrailClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl CloudTrail for CloudTrailClient {
fn add_tags(&self, input: AddTagsRequest) -> RusotoFuture<AddTagsResponse, AddTagsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.AddTags",
);
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::<AddTagsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(AddTagsError::from_response(response))),
)
}
})
}
fn create_trail(
&self,
input: CreateTrailRequest,
) -> RusotoFuture<CreateTrailResponse, CreateTrailError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.CreateTrail",
);
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::<CreateTrailResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateTrailError::from_response(response))),
)
}
})
}
fn delete_trail(
&self,
input: DeleteTrailRequest,
) -> RusotoFuture<DeleteTrailResponse, DeleteTrailError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.DeleteTrail",
);
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::<DeleteTrailResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteTrailError::from_response(response))),
)
}
})
}
fn describe_trails(
&self,
input: DescribeTrailsRequest,
) -> RusotoFuture<DescribeTrailsResponse, DescribeTrailsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.DescribeTrails",
);
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::<DescribeTrailsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeTrailsError::from_response(response))),
)
}
})
}
fn get_event_selectors(
&self,
input: GetEventSelectorsRequest,
) -> RusotoFuture<GetEventSelectorsResponse, GetEventSelectorsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.GetEventSelectors",
);
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::<GetEventSelectorsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetEventSelectorsError::from_response(response))),
)
}
})
}
fn get_trail_status(
&self,
input: GetTrailStatusRequest,
) -> RusotoFuture<GetTrailStatusResponse, GetTrailStatusError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.GetTrailStatus",
);
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::<GetTrailStatusResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetTrailStatusError::from_response(response))),
)
}
})
}
fn list_public_keys(
&self,
input: ListPublicKeysRequest,
) -> RusotoFuture<ListPublicKeysResponse, ListPublicKeysError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.ListPublicKeys",
);
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::<ListPublicKeysResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListPublicKeysError::from_response(response))),
)
}
})
}
fn list_tags(&self, input: ListTagsRequest) -> RusotoFuture<ListTagsResponse, ListTagsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.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 lookup_events(
&self,
input: LookupEventsRequest,
) -> RusotoFuture<LookupEventsResponse, LookupEventsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.LookupEvents",
);
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::<LookupEventsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(LookupEventsError::from_response(response))),
)
}
})
}
fn put_event_selectors(
&self,
input: PutEventSelectorsRequest,
) -> RusotoFuture<PutEventSelectorsResponse, PutEventSelectorsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.PutEventSelectors",
);
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::<PutEventSelectorsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(PutEventSelectorsError::from_response(response))),
)
}
})
}
fn remove_tags(
&self,
input: RemoveTagsRequest,
) -> RusotoFuture<RemoveTagsResponse, RemoveTagsError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.RemoveTags",
);
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::<RemoveTagsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(RemoveTagsError::from_response(response))),
)
}
})
}
fn start_logging(
&self,
input: StartLoggingRequest,
) -> RusotoFuture<StartLoggingResponse, StartLoggingError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.StartLogging",
);
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::<StartLoggingResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(StartLoggingError::from_response(response))),
)
}
})
}
fn stop_logging(
&self,
input: StopLoggingRequest,
) -> RusotoFuture<StopLoggingResponse, StopLoggingError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.StopLogging",
);
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::<StopLoggingResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(StopLoggingError::from_response(response))),
)
}
})
}
fn update_trail(
&self,
input: UpdateTrailRequest,
) -> RusotoFuture<UpdateTrailResponse, UpdateTrailError> {
let mut request = SignedRequest::new("POST", "cloudtrail", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.UpdateTrail",
);
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::<UpdateTrailResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UpdateTrailError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}