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 AffectedEntity {
#[serde(rename = "awsAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub aws_account_id: Option<String>,
#[serde(rename = "entityArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_arn: Option<String>,
#[serde(rename = "entityUrl")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_url: Option<String>,
#[serde(rename = "entityValue")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_value: Option<String>,
#[serde(rename = "eventArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_arn: Option<String>,
#[serde(rename = "lastUpdatedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated_time: Option<f64>,
#[serde(rename = "statusCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status_code: Option<String>,
#[serde(rename = "tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<::std::collections::HashMap<String, String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DateTimeRange {
#[serde(rename = "from")]
#[serde(skip_serializing_if = "Option::is_none")]
pub from: Option<f64>,
#[serde(rename = "to")]
#[serde(skip_serializing_if = "Option::is_none")]
pub to: Option<f64>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeAffectedEntitiesRequest {
#[serde(rename = "filter")]
pub filter: EntityFilter,
#[serde(rename = "locale")]
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<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 DescribeAffectedEntitiesResponse {
#[serde(rename = "entities")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entities: Option<Vec<AffectedEntity>>,
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeEntityAggregatesRequest {
#[serde(rename = "eventArns")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_arns: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeEntityAggregatesResponse {
#[serde(rename = "entityAggregates")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_aggregates: Option<Vec<EntityAggregate>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeEventAggregatesRequest {
#[serde(rename = "aggregateField")]
pub aggregate_field: String,
#[serde(rename = "filter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<EventFilter>,
#[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 DescribeEventAggregatesResponse {
#[serde(rename = "eventAggregates")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_aggregates: Option<Vec<EventAggregate>>,
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeEventDetailsRequest {
#[serde(rename = "eventArns")]
pub event_arns: Vec<String>,
#[serde(rename = "locale")]
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeEventDetailsResponse {
#[serde(rename = "failedSet")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_set: Option<Vec<EventDetailsErrorItem>>,
#[serde(rename = "successfulSet")]
#[serde(skip_serializing_if = "Option::is_none")]
pub successful_set: Option<Vec<EventDetails>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeEventTypesRequest {
#[serde(rename = "filter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<EventTypeFilter>,
#[serde(rename = "locale")]
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<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 DescribeEventTypesResponse {
#[serde(rename = "eventTypes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_types: Option<Vec<String>>,
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeEventsRequest {
#[serde(rename = "filter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<EventFilter>,
#[serde(rename = "locale")]
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<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 DescribeEventsResponse {
#[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 EntityAggregate {
#[serde(rename = "count")]
#[serde(skip_serializing_if = "Option::is_none")]
pub count: Option<i64>,
#[serde(rename = "eventArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct EntityFilter {
#[serde(rename = "entityArns")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_arns: Option<Vec<String>>,
#[serde(rename = "entityValues")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_values: Option<Vec<String>>,
#[serde(rename = "eventArns")]
pub event_arns: Vec<String>,
#[serde(rename = "lastUpdatedTimes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated_times: Option<Vec<DateTimeRange>>,
#[serde(rename = "statusCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status_codes: Option<Vec<String>>,
#[serde(rename = "tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<::std::collections::HashMap<String, String>>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Event {
#[serde(rename = "arn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub arn: Option<String>,
#[serde(rename = "availabilityZone")]
#[serde(skip_serializing_if = "Option::is_none")]
pub availability_zone: Option<String>,
#[serde(rename = "endTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub end_time: Option<f64>,
#[serde(rename = "eventTypeCategory")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_category: Option<String>,
#[serde(rename = "eventTypeCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_code: Option<String>,
#[serde(rename = "lastUpdatedTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated_time: Option<f64>,
#[serde(rename = "region")]
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
#[serde(rename = "service")]
#[serde(skip_serializing_if = "Option::is_none")]
pub service: Option<String>,
#[serde(rename = "startTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub start_time: Option<f64>,
#[serde(rename = "statusCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status_code: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct EventAggregate {
#[serde(rename = "aggregateValue")]
#[serde(skip_serializing_if = "Option::is_none")]
pub aggregate_value: Option<String>,
#[serde(rename = "count")]
#[serde(skip_serializing_if = "Option::is_none")]
pub count: Option<i64>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct EventDetails {
#[serde(rename = "event")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event: Option<Event>,
#[serde(rename = "eventDescription")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_description: Option<String>,
#[serde(rename = "eventMetadata")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_metadata: Option<::std::collections::HashMap<String, String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct EventDetailsErrorItem {
#[serde(rename = "errorMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
#[serde(rename = "errorName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub error_name: Option<String>,
#[serde(rename = "eventArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct EventFilter {
#[serde(rename = "availabilityZones")]
#[serde(skip_serializing_if = "Option::is_none")]
pub availability_zones: Option<Vec<String>>,
#[serde(rename = "endTimes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub end_times: Option<Vec<DateTimeRange>>,
#[serde(rename = "entityArns")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_arns: Option<Vec<String>>,
#[serde(rename = "entityValues")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_values: Option<Vec<String>>,
#[serde(rename = "eventArns")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_arns: Option<Vec<String>>,
#[serde(rename = "eventStatusCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_status_codes: Option<Vec<String>>,
#[serde(rename = "eventTypeCategories")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_categories: Option<Vec<String>>,
#[serde(rename = "eventTypeCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_codes: Option<Vec<String>>,
#[serde(rename = "lastUpdatedTimes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated_times: Option<Vec<DateTimeRange>>,
#[serde(rename = "regions")]
#[serde(skip_serializing_if = "Option::is_none")]
pub regions: Option<Vec<String>>,
#[serde(rename = "services")]
#[serde(skip_serializing_if = "Option::is_none")]
pub services: Option<Vec<String>>,
#[serde(rename = "startTimes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub start_times: Option<Vec<DateTimeRange>>,
#[serde(rename = "tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<::std::collections::HashMap<String, String>>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct EventTypeFilter {
#[serde(rename = "eventTypeCategories")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_categories: Option<Vec<String>>,
#[serde(rename = "eventTypeCodes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type_codes: Option<Vec<String>>,
#[serde(rename = "services")]
#[serde(skip_serializing_if = "Option::is_none")]
pub services: Option<Vec<String>>,
}
#[derive(Debug, PartialEq)]
pub enum DescribeAffectedEntitiesError {
InvalidPaginationToken(String),
UnsupportedLocale(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeAffectedEntitiesError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeAffectedEntitiesError {
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 {
"InvalidPaginationToken" => {
return DescribeAffectedEntitiesError::InvalidPaginationToken(String::from(
error_message,
));
}
"UnsupportedLocale" => {
return DescribeAffectedEntitiesError::UnsupportedLocale(String::from(
error_message,
));
}
"ValidationException" => {
return DescribeAffectedEntitiesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeAffectedEntitiesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeAffectedEntitiesError {
fn from(err: serde_json::error::Error) -> DescribeAffectedEntitiesError {
DescribeAffectedEntitiesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeAffectedEntitiesError {
fn from(err: CredentialsError) -> DescribeAffectedEntitiesError {
DescribeAffectedEntitiesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeAffectedEntitiesError {
fn from(err: HttpDispatchError) -> DescribeAffectedEntitiesError {
DescribeAffectedEntitiesError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeAffectedEntitiesError {
fn from(err: io::Error) -> DescribeAffectedEntitiesError {
DescribeAffectedEntitiesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeAffectedEntitiesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeAffectedEntitiesError {
fn description(&self) -> &str {
match *self {
DescribeAffectedEntitiesError::InvalidPaginationToken(ref cause) => cause,
DescribeAffectedEntitiesError::UnsupportedLocale(ref cause) => cause,
DescribeAffectedEntitiesError::Validation(ref cause) => cause,
DescribeAffectedEntitiesError::Credentials(ref err) => err.description(),
DescribeAffectedEntitiesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeAffectedEntitiesError::ParseError(ref cause) => cause,
DescribeAffectedEntitiesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeEntityAggregatesError {
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeEntityAggregatesError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeEntityAggregatesError {
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 {
"ValidationException" => {
return DescribeEntityAggregatesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeEntityAggregatesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeEntityAggregatesError {
fn from(err: serde_json::error::Error) -> DescribeEntityAggregatesError {
DescribeEntityAggregatesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeEntityAggregatesError {
fn from(err: CredentialsError) -> DescribeEntityAggregatesError {
DescribeEntityAggregatesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeEntityAggregatesError {
fn from(err: HttpDispatchError) -> DescribeEntityAggregatesError {
DescribeEntityAggregatesError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeEntityAggregatesError {
fn from(err: io::Error) -> DescribeEntityAggregatesError {
DescribeEntityAggregatesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeEntityAggregatesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeEntityAggregatesError {
fn description(&self) -> &str {
match *self {
DescribeEntityAggregatesError::Validation(ref cause) => cause,
DescribeEntityAggregatesError::Credentials(ref err) => err.description(),
DescribeEntityAggregatesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeEntityAggregatesError::ParseError(ref cause) => cause,
DescribeEntityAggregatesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeEventAggregatesError {
InvalidPaginationToken(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeEventAggregatesError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeEventAggregatesError {
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 {
"InvalidPaginationToken" => {
return DescribeEventAggregatesError::InvalidPaginationToken(String::from(
error_message,
));
}
"ValidationException" => {
return DescribeEventAggregatesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeEventAggregatesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeEventAggregatesError {
fn from(err: serde_json::error::Error) -> DescribeEventAggregatesError {
DescribeEventAggregatesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeEventAggregatesError {
fn from(err: CredentialsError) -> DescribeEventAggregatesError {
DescribeEventAggregatesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeEventAggregatesError {
fn from(err: HttpDispatchError) -> DescribeEventAggregatesError {
DescribeEventAggregatesError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeEventAggregatesError {
fn from(err: io::Error) -> DescribeEventAggregatesError {
DescribeEventAggregatesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeEventAggregatesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeEventAggregatesError {
fn description(&self) -> &str {
match *self {
DescribeEventAggregatesError::InvalidPaginationToken(ref cause) => cause,
DescribeEventAggregatesError::Validation(ref cause) => cause,
DescribeEventAggregatesError::Credentials(ref err) => err.description(),
DescribeEventAggregatesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeEventAggregatesError::ParseError(ref cause) => cause,
DescribeEventAggregatesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeEventDetailsError {
UnsupportedLocale(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeEventDetailsError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeEventDetailsError {
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 {
"UnsupportedLocale" => {
return DescribeEventDetailsError::UnsupportedLocale(String::from(error_message));
}
"ValidationException" => {
return DescribeEventDetailsError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeEventDetailsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeEventDetailsError {
fn from(err: serde_json::error::Error) -> DescribeEventDetailsError {
DescribeEventDetailsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeEventDetailsError {
fn from(err: CredentialsError) -> DescribeEventDetailsError {
DescribeEventDetailsError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeEventDetailsError {
fn from(err: HttpDispatchError) -> DescribeEventDetailsError {
DescribeEventDetailsError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeEventDetailsError {
fn from(err: io::Error) -> DescribeEventDetailsError {
DescribeEventDetailsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeEventDetailsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeEventDetailsError {
fn description(&self) -> &str {
match *self {
DescribeEventDetailsError::UnsupportedLocale(ref cause) => cause,
DescribeEventDetailsError::Validation(ref cause) => cause,
DescribeEventDetailsError::Credentials(ref err) => err.description(),
DescribeEventDetailsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeEventDetailsError::ParseError(ref cause) => cause,
DescribeEventDetailsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeEventTypesError {
InvalidPaginationToken(String),
UnsupportedLocale(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeEventTypesError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeEventTypesError {
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 {
"InvalidPaginationToken" => {
return DescribeEventTypesError::InvalidPaginationToken(String::from(
error_message,
));
}
"UnsupportedLocale" => {
return DescribeEventTypesError::UnsupportedLocale(String::from(error_message));
}
"ValidationException" => {
return DescribeEventTypesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeEventTypesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeEventTypesError {
fn from(err: serde_json::error::Error) -> DescribeEventTypesError {
DescribeEventTypesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeEventTypesError {
fn from(err: CredentialsError) -> DescribeEventTypesError {
DescribeEventTypesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeEventTypesError {
fn from(err: HttpDispatchError) -> DescribeEventTypesError {
DescribeEventTypesError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeEventTypesError {
fn from(err: io::Error) -> DescribeEventTypesError {
DescribeEventTypesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeEventTypesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeEventTypesError {
fn description(&self) -> &str {
match *self {
DescribeEventTypesError::InvalidPaginationToken(ref cause) => cause,
DescribeEventTypesError::UnsupportedLocale(ref cause) => cause,
DescribeEventTypesError::Validation(ref cause) => cause,
DescribeEventTypesError::Credentials(ref err) => err.description(),
DescribeEventTypesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DescribeEventTypesError::ParseError(ref cause) => cause,
DescribeEventTypesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeEventsError {
InvalidPaginationToken(String),
UnsupportedLocale(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeEventsError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeEventsError {
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 {
"InvalidPaginationToken" => {
return DescribeEventsError::InvalidPaginationToken(String::from(error_message));
}
"UnsupportedLocale" => {
return DescribeEventsError::UnsupportedLocale(String::from(error_message));
}
"ValidationException" => {
return DescribeEventsError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeEventsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeEventsError {
fn from(err: serde_json::error::Error) -> DescribeEventsError {
DescribeEventsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeEventsError {
fn from(err: CredentialsError) -> DescribeEventsError {
DescribeEventsError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeEventsError {
fn from(err: HttpDispatchError) -> DescribeEventsError {
DescribeEventsError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeEventsError {
fn from(err: io::Error) -> DescribeEventsError {
DescribeEventsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeEventsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeEventsError {
fn description(&self) -> &str {
match *self {
DescribeEventsError::InvalidPaginationToken(ref cause) => cause,
DescribeEventsError::UnsupportedLocale(ref cause) => cause,
DescribeEventsError::Validation(ref cause) => cause,
DescribeEventsError::Credentials(ref err) => err.description(),
DescribeEventsError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeEventsError::ParseError(ref cause) => cause,
DescribeEventsError::Unknown(_) => "unknown error",
}
}
}
pub trait AWSHealth {
fn describe_affected_entities(
&self,
input: DescribeAffectedEntitiesRequest,
) -> RusotoFuture<DescribeAffectedEntitiesResponse, DescribeAffectedEntitiesError>;
fn describe_entity_aggregates(
&self,
input: DescribeEntityAggregatesRequest,
) -> RusotoFuture<DescribeEntityAggregatesResponse, DescribeEntityAggregatesError>;
fn describe_event_aggregates(
&self,
input: DescribeEventAggregatesRequest,
) -> RusotoFuture<DescribeEventAggregatesResponse, DescribeEventAggregatesError>;
fn describe_event_details(
&self,
input: DescribeEventDetailsRequest,
) -> RusotoFuture<DescribeEventDetailsResponse, DescribeEventDetailsError>;
fn describe_event_types(
&self,
input: DescribeEventTypesRequest,
) -> RusotoFuture<DescribeEventTypesResponse, DescribeEventTypesError>;
fn describe_events(
&self,
input: DescribeEventsRequest,
) -> RusotoFuture<DescribeEventsResponse, DescribeEventsError>;
}
#[derive(Clone)]
pub struct AWSHealthClient {
client: Client,
region: region::Region,
}
impl AWSHealthClient {
pub fn new(region: region::Region) -> AWSHealthClient {
AWSHealthClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> AWSHealthClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
AWSHealthClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl AWSHealth for AWSHealthClient {
fn describe_affected_entities(
&self,
input: DescribeAffectedEntitiesRequest,
) -> RusotoFuture<DescribeAffectedEntitiesResponse, DescribeAffectedEntitiesError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AWSHealth_20160804.DescribeAffectedEntities",
);
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::<DescribeAffectedEntitiesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DescribeAffectedEntitiesError::from_response(response))
}))
}
})
}
fn describe_entity_aggregates(
&self,
input: DescribeEntityAggregatesRequest,
) -> RusotoFuture<DescribeEntityAggregatesResponse, DescribeEntityAggregatesError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header(
"x-amz-target",
"AWSHealth_20160804.DescribeEntityAggregates",
);
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::<DescribeEntityAggregatesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DescribeEntityAggregatesError::from_response(response))
}))
}
})
}
fn describe_event_aggregates(
&self,
input: DescribeEventAggregatesRequest,
) -> RusotoFuture<DescribeEventAggregatesResponse, DescribeEventAggregatesError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSHealth_20160804.DescribeEventAggregates");
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::<DescribeEventAggregatesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DescribeEventAggregatesError::from_response(response))
}))
}
})
}
fn describe_event_details(
&self,
input: DescribeEventDetailsRequest,
) -> RusotoFuture<DescribeEventDetailsResponse, DescribeEventDetailsError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSHealth_20160804.DescribeEventDetails");
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::<DescribeEventDetailsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(DescribeEventDetailsError::from_response(response))
}),
)
}
})
}
fn describe_event_types(
&self,
input: DescribeEventTypesRequest,
) -> RusotoFuture<DescribeEventTypesResponse, DescribeEventTypesError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSHealth_20160804.DescribeEventTypes");
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::<DescribeEventTypesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeEventTypesError::from_response(response))),
)
}
})
}
fn describe_events(
&self,
input: DescribeEventsRequest,
) -> RusotoFuture<DescribeEventsResponse, DescribeEventsError> {
let mut request = SignedRequest::new("POST", "health", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSHealth_20160804.DescribeEvents");
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::<DescribeEventsResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeEventsError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}