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 AssociateMemberAccountRequest {
#[serde(rename = "memberAccountId")]
pub member_account_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct AssociateS3ResourcesRequest {
#[serde(rename = "memberAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account_id: Option<String>,
#[serde(rename = "s3Resources")]
pub s_3_resources: Vec<S3ResourceClassification>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct AssociateS3ResourcesResult {
#[serde(rename = "failedS3Resources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_s3_resources: Option<Vec<FailedS3Resource>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ClassificationType {
#[serde(rename = "continuous")]
pub continuous: String,
#[serde(rename = "oneTime")]
pub one_time: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ClassificationTypeUpdate {
#[serde(rename = "continuous")]
#[serde(skip_serializing_if = "Option::is_none")]
pub continuous: Option<String>,
#[serde(rename = "oneTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub one_time: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DisassociateMemberAccountRequest {
#[serde(rename = "memberAccountId")]
pub member_account_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DisassociateS3ResourcesRequest {
#[serde(rename = "associatedS3Resources")]
pub associated_s3_resources: Vec<S3Resource>,
#[serde(rename = "memberAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DisassociateS3ResourcesResult {
#[serde(rename = "failedS3Resources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_s3_resources: Option<Vec<FailedS3Resource>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct FailedS3Resource {
#[serde(rename = "errorCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(rename = "errorMessage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
#[serde(rename = "failedItem")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_item: Option<S3Resource>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListMemberAccountsRequest {
#[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 ListMemberAccountsResult {
#[serde(rename = "memberAccounts")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_accounts: Option<Vec<MemberAccount>>,
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListS3ResourcesRequest {
#[serde(rename = "maxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "memberAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account_id: Option<String>,
#[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 ListS3ResourcesResult {
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "s3Resources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub s_3_resources: Option<Vec<S3ResourceClassification>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct MemberAccount {
#[serde(rename = "accountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub account_id: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct S3Resource {
#[serde(rename = "bucketName")]
pub bucket_name: String,
#[serde(rename = "prefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct S3ResourceClassification {
#[serde(rename = "bucketName")]
pub bucket_name: String,
#[serde(rename = "classificationType")]
pub classification_type: ClassificationType,
#[serde(rename = "prefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct S3ResourceClassificationUpdate {
#[serde(rename = "bucketName")]
pub bucket_name: String,
#[serde(rename = "classificationTypeUpdate")]
pub classification_type_update: ClassificationTypeUpdate,
#[serde(rename = "prefix")]
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UpdateS3ResourcesRequest {
#[serde(rename = "memberAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account_id: Option<String>,
#[serde(rename = "s3ResourcesUpdate")]
pub s_3_resources_update: Vec<S3ResourceClassificationUpdate>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateS3ResourcesResult {
#[serde(rename = "failedS3Resources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_s3_resources: Option<Vec<FailedS3Resource>>,
}
#[derive(Debug, PartialEq)]
pub enum AssociateMemberAccountError {
Internal(String),
InvalidInput(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl AssociateMemberAccountError {
pub fn from_response(res: BufferedHttpResponse) -> AssociateMemberAccountError {
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 {
"InternalException" => {
return AssociateMemberAccountError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return AssociateMemberAccountError::InvalidInput(String::from(error_message));
}
"LimitExceededException" => {
return AssociateMemberAccountError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return AssociateMemberAccountError::Validation(error_message.to_string());
}
_ => {}
}
}
return AssociateMemberAccountError::Unknown(res);
}
}
impl From<serde_json::error::Error> for AssociateMemberAccountError {
fn from(err: serde_json::error::Error) -> AssociateMemberAccountError {
AssociateMemberAccountError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for AssociateMemberAccountError {
fn from(err: CredentialsError) -> AssociateMemberAccountError {
AssociateMemberAccountError::Credentials(err)
}
}
impl From<HttpDispatchError> for AssociateMemberAccountError {
fn from(err: HttpDispatchError) -> AssociateMemberAccountError {
AssociateMemberAccountError::HttpDispatch(err)
}
}
impl From<io::Error> for AssociateMemberAccountError {
fn from(err: io::Error) -> AssociateMemberAccountError {
AssociateMemberAccountError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for AssociateMemberAccountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for AssociateMemberAccountError {
fn description(&self) -> &str {
match *self {
AssociateMemberAccountError::Internal(ref cause) => cause,
AssociateMemberAccountError::InvalidInput(ref cause) => cause,
AssociateMemberAccountError::LimitExceeded(ref cause) => cause,
AssociateMemberAccountError::Validation(ref cause) => cause,
AssociateMemberAccountError::Credentials(ref err) => err.description(),
AssociateMemberAccountError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
AssociateMemberAccountError::ParseError(ref cause) => cause,
AssociateMemberAccountError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum AssociateS3ResourcesError {
AccessDenied(String),
Internal(String),
InvalidInput(String),
LimitExceeded(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl AssociateS3ResourcesError {
pub fn from_response(res: BufferedHttpResponse) -> AssociateS3ResourcesError {
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 {
"AccessDeniedException" => {
return AssociateS3ResourcesError::AccessDenied(String::from(error_message));
}
"InternalException" => {
return AssociateS3ResourcesError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return AssociateS3ResourcesError::InvalidInput(String::from(error_message));
}
"LimitExceededException" => {
return AssociateS3ResourcesError::LimitExceeded(String::from(error_message));
}
"ValidationException" => {
return AssociateS3ResourcesError::Validation(error_message.to_string());
}
_ => {}
}
}
return AssociateS3ResourcesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for AssociateS3ResourcesError {
fn from(err: serde_json::error::Error) -> AssociateS3ResourcesError {
AssociateS3ResourcesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for AssociateS3ResourcesError {
fn from(err: CredentialsError) -> AssociateS3ResourcesError {
AssociateS3ResourcesError::Credentials(err)
}
}
impl From<HttpDispatchError> for AssociateS3ResourcesError {
fn from(err: HttpDispatchError) -> AssociateS3ResourcesError {
AssociateS3ResourcesError::HttpDispatch(err)
}
}
impl From<io::Error> for AssociateS3ResourcesError {
fn from(err: io::Error) -> AssociateS3ResourcesError {
AssociateS3ResourcesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for AssociateS3ResourcesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for AssociateS3ResourcesError {
fn description(&self) -> &str {
match *self {
AssociateS3ResourcesError::AccessDenied(ref cause) => cause,
AssociateS3ResourcesError::Internal(ref cause) => cause,
AssociateS3ResourcesError::InvalidInput(ref cause) => cause,
AssociateS3ResourcesError::LimitExceeded(ref cause) => cause,
AssociateS3ResourcesError::Validation(ref cause) => cause,
AssociateS3ResourcesError::Credentials(ref err) => err.description(),
AssociateS3ResourcesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
AssociateS3ResourcesError::ParseError(ref cause) => cause,
AssociateS3ResourcesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DisassociateMemberAccountError {
Internal(String),
InvalidInput(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DisassociateMemberAccountError {
pub fn from_response(res: BufferedHttpResponse) -> DisassociateMemberAccountError {
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 {
"InternalException" => {
return DisassociateMemberAccountError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return DisassociateMemberAccountError::InvalidInput(String::from(error_message));
}
"ValidationException" => {
return DisassociateMemberAccountError::Validation(error_message.to_string());
}
_ => {}
}
}
return DisassociateMemberAccountError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DisassociateMemberAccountError {
fn from(err: serde_json::error::Error) -> DisassociateMemberAccountError {
DisassociateMemberAccountError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DisassociateMemberAccountError {
fn from(err: CredentialsError) -> DisassociateMemberAccountError {
DisassociateMemberAccountError::Credentials(err)
}
}
impl From<HttpDispatchError> for DisassociateMemberAccountError {
fn from(err: HttpDispatchError) -> DisassociateMemberAccountError {
DisassociateMemberAccountError::HttpDispatch(err)
}
}
impl From<io::Error> for DisassociateMemberAccountError {
fn from(err: io::Error) -> DisassociateMemberAccountError {
DisassociateMemberAccountError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DisassociateMemberAccountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DisassociateMemberAccountError {
fn description(&self) -> &str {
match *self {
DisassociateMemberAccountError::Internal(ref cause) => cause,
DisassociateMemberAccountError::InvalidInput(ref cause) => cause,
DisassociateMemberAccountError::Validation(ref cause) => cause,
DisassociateMemberAccountError::Credentials(ref err) => err.description(),
DisassociateMemberAccountError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DisassociateMemberAccountError::ParseError(ref cause) => cause,
DisassociateMemberAccountError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DisassociateS3ResourcesError {
AccessDenied(String),
Internal(String),
InvalidInput(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DisassociateS3ResourcesError {
pub fn from_response(res: BufferedHttpResponse) -> DisassociateS3ResourcesError {
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 {
"AccessDeniedException" => {
return DisassociateS3ResourcesError::AccessDenied(String::from(error_message));
}
"InternalException" => {
return DisassociateS3ResourcesError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return DisassociateS3ResourcesError::InvalidInput(String::from(error_message));
}
"ValidationException" => {
return DisassociateS3ResourcesError::Validation(error_message.to_string());
}
_ => {}
}
}
return DisassociateS3ResourcesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DisassociateS3ResourcesError {
fn from(err: serde_json::error::Error) -> DisassociateS3ResourcesError {
DisassociateS3ResourcesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DisassociateS3ResourcesError {
fn from(err: CredentialsError) -> DisassociateS3ResourcesError {
DisassociateS3ResourcesError::Credentials(err)
}
}
impl From<HttpDispatchError> for DisassociateS3ResourcesError {
fn from(err: HttpDispatchError) -> DisassociateS3ResourcesError {
DisassociateS3ResourcesError::HttpDispatch(err)
}
}
impl From<io::Error> for DisassociateS3ResourcesError {
fn from(err: io::Error) -> DisassociateS3ResourcesError {
DisassociateS3ResourcesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DisassociateS3ResourcesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DisassociateS3ResourcesError {
fn description(&self) -> &str {
match *self {
DisassociateS3ResourcesError::AccessDenied(ref cause) => cause,
DisassociateS3ResourcesError::Internal(ref cause) => cause,
DisassociateS3ResourcesError::InvalidInput(ref cause) => cause,
DisassociateS3ResourcesError::Validation(ref cause) => cause,
DisassociateS3ResourcesError::Credentials(ref err) => err.description(),
DisassociateS3ResourcesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
DisassociateS3ResourcesError::ParseError(ref cause) => cause,
DisassociateS3ResourcesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListMemberAccountsError {
Internal(String),
InvalidInput(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListMemberAccountsError {
pub fn from_response(res: BufferedHttpResponse) -> ListMemberAccountsError {
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 {
"InternalException" => {
return ListMemberAccountsError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return ListMemberAccountsError::InvalidInput(String::from(error_message));
}
"ValidationException" => {
return ListMemberAccountsError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListMemberAccountsError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListMemberAccountsError {
fn from(err: serde_json::error::Error) -> ListMemberAccountsError {
ListMemberAccountsError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListMemberAccountsError {
fn from(err: CredentialsError) -> ListMemberAccountsError {
ListMemberAccountsError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListMemberAccountsError {
fn from(err: HttpDispatchError) -> ListMemberAccountsError {
ListMemberAccountsError::HttpDispatch(err)
}
}
impl From<io::Error> for ListMemberAccountsError {
fn from(err: io::Error) -> ListMemberAccountsError {
ListMemberAccountsError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListMemberAccountsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListMemberAccountsError {
fn description(&self) -> &str {
match *self {
ListMemberAccountsError::Internal(ref cause) => cause,
ListMemberAccountsError::InvalidInput(ref cause) => cause,
ListMemberAccountsError::Validation(ref cause) => cause,
ListMemberAccountsError::Credentials(ref err) => err.description(),
ListMemberAccountsError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
ListMemberAccountsError::ParseError(ref cause) => cause,
ListMemberAccountsError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListS3ResourcesError {
AccessDenied(String),
Internal(String),
InvalidInput(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListS3ResourcesError {
pub fn from_response(res: BufferedHttpResponse) -> ListS3ResourcesError {
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 {
"AccessDeniedException" => {
return ListS3ResourcesError::AccessDenied(String::from(error_message));
}
"InternalException" => {
return ListS3ResourcesError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return ListS3ResourcesError::InvalidInput(String::from(error_message));
}
"ValidationException" => {
return ListS3ResourcesError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListS3ResourcesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListS3ResourcesError {
fn from(err: serde_json::error::Error) -> ListS3ResourcesError {
ListS3ResourcesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListS3ResourcesError {
fn from(err: CredentialsError) -> ListS3ResourcesError {
ListS3ResourcesError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListS3ResourcesError {
fn from(err: HttpDispatchError) -> ListS3ResourcesError {
ListS3ResourcesError::HttpDispatch(err)
}
}
impl From<io::Error> for ListS3ResourcesError {
fn from(err: io::Error) -> ListS3ResourcesError {
ListS3ResourcesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListS3ResourcesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListS3ResourcesError {
fn description(&self) -> &str {
match *self {
ListS3ResourcesError::AccessDenied(ref cause) => cause,
ListS3ResourcesError::Internal(ref cause) => cause,
ListS3ResourcesError::InvalidInput(ref cause) => cause,
ListS3ResourcesError::Validation(ref cause) => cause,
ListS3ResourcesError::Credentials(ref err) => err.description(),
ListS3ResourcesError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListS3ResourcesError::ParseError(ref cause) => cause,
ListS3ResourcesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UpdateS3ResourcesError {
AccessDenied(String),
Internal(String),
InvalidInput(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UpdateS3ResourcesError {
pub fn from_response(res: BufferedHttpResponse) -> UpdateS3ResourcesError {
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 {
"AccessDeniedException" => {
return UpdateS3ResourcesError::AccessDenied(String::from(error_message));
}
"InternalException" => {
return UpdateS3ResourcesError::Internal(String::from(error_message));
}
"InvalidInputException" => {
return UpdateS3ResourcesError::InvalidInput(String::from(error_message));
}
"ValidationException" => {
return UpdateS3ResourcesError::Validation(error_message.to_string());
}
_ => {}
}
}
return UpdateS3ResourcesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UpdateS3ResourcesError {
fn from(err: serde_json::error::Error) -> UpdateS3ResourcesError {
UpdateS3ResourcesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UpdateS3ResourcesError {
fn from(err: CredentialsError) -> UpdateS3ResourcesError {
UpdateS3ResourcesError::Credentials(err)
}
}
impl From<HttpDispatchError> for UpdateS3ResourcesError {
fn from(err: HttpDispatchError) -> UpdateS3ResourcesError {
UpdateS3ResourcesError::HttpDispatch(err)
}
}
impl From<io::Error> for UpdateS3ResourcesError {
fn from(err: io::Error) -> UpdateS3ResourcesError {
UpdateS3ResourcesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UpdateS3ResourcesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UpdateS3ResourcesError {
fn description(&self) -> &str {
match *self {
UpdateS3ResourcesError::AccessDenied(ref cause) => cause,
UpdateS3ResourcesError::Internal(ref cause) => cause,
UpdateS3ResourcesError::InvalidInput(ref cause) => cause,
UpdateS3ResourcesError::Validation(ref cause) => cause,
UpdateS3ResourcesError::Credentials(ref err) => err.description(),
UpdateS3ResourcesError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
UpdateS3ResourcesError::ParseError(ref cause) => cause,
UpdateS3ResourcesError::Unknown(_) => "unknown error",
}
}
}
pub trait Macie {
fn associate_member_account(
&self,
input: AssociateMemberAccountRequest,
) -> RusotoFuture<(), AssociateMemberAccountError>;
fn associate_s3_resources(
&self,
input: AssociateS3ResourcesRequest,
) -> RusotoFuture<AssociateS3ResourcesResult, AssociateS3ResourcesError>;
fn disassociate_member_account(
&self,
input: DisassociateMemberAccountRequest,
) -> RusotoFuture<(), DisassociateMemberAccountError>;
fn disassociate_s3_resources(
&self,
input: DisassociateS3ResourcesRequest,
) -> RusotoFuture<DisassociateS3ResourcesResult, DisassociateS3ResourcesError>;
fn list_member_accounts(
&self,
input: ListMemberAccountsRequest,
) -> RusotoFuture<ListMemberAccountsResult, ListMemberAccountsError>;
fn list_s3_resources(
&self,
input: ListS3ResourcesRequest,
) -> RusotoFuture<ListS3ResourcesResult, ListS3ResourcesError>;
fn update_s3_resources(
&self,
input: UpdateS3ResourcesRequest,
) -> RusotoFuture<UpdateS3ResourcesResult, UpdateS3ResourcesError>;
}
#[derive(Clone)]
pub struct MacieClient {
client: Client,
region: region::Region,
}
impl MacieClient {
pub fn new(region: region::Region) -> MacieClient {
MacieClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> MacieClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
MacieClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl Macie for MacieClient {
fn associate_member_account(
&self,
input: AssociateMemberAccountRequest,
) -> RusotoFuture<(), AssociateMemberAccountError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.AssociateMemberAccount");
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(future::ok(::std::mem::drop(response)))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(AssociateMemberAccountError::from_response(response))
}),
)
}
})
}
fn associate_s3_resources(
&self,
input: AssociateS3ResourcesRequest,
) -> RusotoFuture<AssociateS3ResourcesResult, AssociateS3ResourcesError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.AssociateS3Resources");
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::<AssociateS3ResourcesResult>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(AssociateS3ResourcesError::from_response(response))
}),
)
}
})
}
fn disassociate_member_account(
&self,
input: DisassociateMemberAccountRequest,
) -> RusotoFuture<(), DisassociateMemberAccountError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.DisassociateMemberAccount");
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(future::ok(::std::mem::drop(response)))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DisassociateMemberAccountError::from_response(response))
}))
}
})
}
fn disassociate_s3_resources(
&self,
input: DisassociateS3ResourcesRequest,
) -> RusotoFuture<DisassociateS3ResourcesResult, DisassociateS3ResourcesError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.DisassociateS3Resources");
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::<DisassociateS3ResourcesResult>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(response.buffer().from_err().and_then(|response| {
Err(DisassociateS3ResourcesError::from_response(response))
}))
}
})
}
fn list_member_accounts(
&self,
input: ListMemberAccountsRequest,
) -> RusotoFuture<ListMemberAccountsResult, ListMemberAccountsError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.ListMemberAccounts");
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::<ListMemberAccountsResult>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListMemberAccountsError::from_response(response))),
)
}
})
}
fn list_s3_resources(
&self,
input: ListS3ResourcesRequest,
) -> RusotoFuture<ListS3ResourcesResult, ListS3ResourcesError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.ListS3Resources");
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::<ListS3ResourcesResult>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListS3ResourcesError::from_response(response))),
)
}
})
}
fn update_s3_resources(
&self,
input: UpdateS3ResourcesRequest,
) -> RusotoFuture<UpdateS3ResourcesResult, UpdateS3ResourcesError> {
let mut request = SignedRequest::new("POST", "macie", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "MacieService.UpdateS3Resources");
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::<UpdateS3ResourcesResult>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(UpdateS3ResourcesError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}