use std::error::Error;
use std::fmt;
#[allow(warnings)]
use futures::future;
use futures::Future;
use rusoto_core::credential::ProvideAwsCredentials;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoError, RusotoFuture};
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 AssociateAdminAccountRequest {
#[serde(rename = "AdminAccount")]
pub admin_account: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ComplianceViolator {
#[serde(rename = "ResourceId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_id: Option<String>,
#[serde(rename = "ResourceType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_type: Option<String>,
#[serde(rename = "ViolationReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub violation_reason: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteNotificationChannelRequest {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeletePolicyRequest {
#[serde(rename = "DeleteAllPolicyResources")]
#[serde(skip_serializing_if = "Option::is_none")]
pub delete_all_policy_resources: Option<bool>,
#[serde(rename = "PolicyId")]
pub policy_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DisassociateAdminAccountRequest {}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct EvaluationResult {
#[serde(rename = "ComplianceStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub compliance_status: Option<String>,
#[serde(rename = "EvaluationLimitExceeded")]
#[serde(skip_serializing_if = "Option::is_none")]
pub evaluation_limit_exceeded: Option<bool>,
#[serde(rename = "ViolatorCount")]
#[serde(skip_serializing_if = "Option::is_none")]
pub violator_count: Option<i64>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetAdminAccountRequest {}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetAdminAccountResponse {
#[serde(rename = "AdminAccount")]
#[serde(skip_serializing_if = "Option::is_none")]
pub admin_account: Option<String>,
#[serde(rename = "RoleStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub role_status: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetComplianceDetailRequest {
#[serde(rename = "MemberAccount")]
pub member_account: String,
#[serde(rename = "PolicyId")]
pub policy_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetComplianceDetailResponse {
#[serde(rename = "PolicyComplianceDetail")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_compliance_detail: Option<PolicyComplianceDetail>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetNotificationChannelRequest {}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetNotificationChannelResponse {
#[serde(rename = "SnsRoleName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_role_name: Option<String>,
#[serde(rename = "SnsTopicArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sns_topic_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct GetPolicyRequest {
#[serde(rename = "PolicyId")]
pub policy_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct GetPolicyResponse {
#[serde(rename = "Policy")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy: Option<Policy>,
#[serde(rename = "PolicyArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListComplianceStatusRequest {
#[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 = "PolicyId")]
pub policy_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ListComplianceStatusResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "PolicyComplianceStatusList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_compliance_status_list: Option<Vec<PolicyComplianceStatus>>,
}
#[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 ListMemberAccountsResponse {
#[serde(rename = "MemberAccounts")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_accounts: 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 ListPoliciesRequest {
#[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 ListPoliciesResponse {
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "PolicyList")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_list: Option<Vec<PolicySummary>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Policy {
#[serde(rename = "ExcludeMap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude_map: Option<::std::collections::HashMap<String, Vec<String>>>,
#[serde(rename = "ExcludeResourceTags")]
pub exclude_resource_tags: bool,
#[serde(rename = "IncludeMap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub include_map: Option<::std::collections::HashMap<String, Vec<String>>>,
#[serde(rename = "PolicyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_id: Option<String>,
#[serde(rename = "PolicyName")]
pub policy_name: String,
#[serde(rename = "PolicyUpdateToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_update_token: Option<String>,
#[serde(rename = "RemediationEnabled")]
pub remediation_enabled: bool,
#[serde(rename = "ResourceTags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_tags: Option<Vec<ResourceTag>>,
#[serde(rename = "ResourceType")]
pub resource_type: String,
#[serde(rename = "SecurityServicePolicyData")]
pub security_service_policy_data: SecurityServicePolicyData,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PolicyComplianceDetail {
#[serde(rename = "EvaluationLimitExceeded")]
#[serde(skip_serializing_if = "Option::is_none")]
pub evaluation_limit_exceeded: Option<bool>,
#[serde(rename = "ExpiredAt")]
#[serde(skip_serializing_if = "Option::is_none")]
pub expired_at: Option<f64>,
#[serde(rename = "IssueInfoMap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub issue_info_map: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "MemberAccount")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account: Option<String>,
#[serde(rename = "PolicyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_id: Option<String>,
#[serde(rename = "PolicyOwner")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_owner: Option<String>,
#[serde(rename = "Violators")]
#[serde(skip_serializing_if = "Option::is_none")]
pub violators: Option<Vec<ComplianceViolator>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PolicyComplianceStatus {
#[serde(rename = "EvaluationResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub evaluation_results: Option<Vec<EvaluationResult>>,
#[serde(rename = "IssueInfoMap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub issue_info_map: Option<::std::collections::HashMap<String, String>>,
#[serde(rename = "LastUpdated")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated: Option<f64>,
#[serde(rename = "MemberAccount")]
#[serde(skip_serializing_if = "Option::is_none")]
pub member_account: Option<String>,
#[serde(rename = "PolicyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_id: Option<String>,
#[serde(rename = "PolicyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_name: Option<String>,
#[serde(rename = "PolicyOwner")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_owner: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PolicySummary {
#[serde(rename = "PolicyArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_arn: Option<String>,
#[serde(rename = "PolicyId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_id: Option<String>,
#[serde(rename = "PolicyName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_name: Option<String>,
#[serde(rename = "RemediationEnabled")]
#[serde(skip_serializing_if = "Option::is_none")]
pub remediation_enabled: Option<bool>,
#[serde(rename = "ResourceType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_type: Option<String>,
#[serde(rename = "SecurityServiceType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub security_service_type: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct PutNotificationChannelRequest {
#[serde(rename = "SnsRoleName")]
pub sns_role_name: String,
#[serde(rename = "SnsTopicArn")]
pub sns_topic_arn: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct PutPolicyRequest {
#[serde(rename = "Policy")]
pub policy: Policy,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct PutPolicyResponse {
#[serde(rename = "Policy")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy: Option<Policy>,
#[serde(rename = "PolicyArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub policy_arn: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResourceTag {
#[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, Serialize, Deserialize)]
pub struct SecurityServicePolicyData {
#[serde(rename = "ManagedServiceData")]
#[serde(skip_serializing_if = "Option::is_none")]
pub managed_service_data: Option<String>,
#[serde(rename = "Type")]
pub type_: String,
}
#[derive(Debug, PartialEq)]
pub enum AssociateAdminAccountError {
InternalError(String),
InvalidInput(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl AssociateAdminAccountError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<AssociateAdminAccountError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(AssociateAdminAccountError::InternalError(
String::from(error_message),
))
}
"InvalidInputException" => {
return RusotoError::Service(AssociateAdminAccountError::InvalidInput(
String::from(error_message),
))
}
"InvalidOperationException" => {
return RusotoError::Service(AssociateAdminAccountError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(AssociateAdminAccountError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for AssociateAdminAccountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for AssociateAdminAccountError {
fn description(&self) -> &str {
match *self {
AssociateAdminAccountError::InternalError(ref cause) => cause,
AssociateAdminAccountError::InvalidInput(ref cause) => cause,
AssociateAdminAccountError::InvalidOperation(ref cause) => cause,
AssociateAdminAccountError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteNotificationChannelError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl DeleteNotificationChannelError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeleteNotificationChannelError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(DeleteNotificationChannelError::InternalError(
String::from(error_message),
))
}
"InvalidOperationException" => {
return RusotoError::Service(DeleteNotificationChannelError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(DeleteNotificationChannelError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for DeleteNotificationChannelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteNotificationChannelError {
fn description(&self) -> &str {
match *self {
DeleteNotificationChannelError::InternalError(ref cause) => cause,
DeleteNotificationChannelError::InvalidOperation(ref cause) => cause,
DeleteNotificationChannelError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeletePolicyError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl DeletePolicyError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeletePolicyError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(DeletePolicyError::InternalError(String::from(
error_message,
)))
}
"InvalidOperationException" => {
return RusotoError::Service(DeletePolicyError::InvalidOperation(String::from(
error_message,
)))
}
"ResourceNotFoundException" => {
return RusotoError::Service(DeletePolicyError::ResourceNotFound(String::from(
error_message,
)))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for DeletePolicyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeletePolicyError {
fn description(&self) -> &str {
match *self {
DeletePolicyError::InternalError(ref cause) => cause,
DeletePolicyError::InvalidOperation(ref cause) => cause,
DeletePolicyError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum DisassociateAdminAccountError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl DisassociateAdminAccountError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DisassociateAdminAccountError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(DisassociateAdminAccountError::InternalError(
String::from(error_message),
))
}
"InvalidOperationException" => {
return RusotoError::Service(DisassociateAdminAccountError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(DisassociateAdminAccountError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for DisassociateAdminAccountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DisassociateAdminAccountError {
fn description(&self) -> &str {
match *self {
DisassociateAdminAccountError::InternalError(ref cause) => cause,
DisassociateAdminAccountError::InvalidOperation(ref cause) => cause,
DisassociateAdminAccountError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetAdminAccountError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl GetAdminAccountError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetAdminAccountError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(GetAdminAccountError::InternalError(String::from(
error_message,
)))
}
"InvalidOperationException" => {
return RusotoError::Service(GetAdminAccountError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(GetAdminAccountError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetAdminAccountError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetAdminAccountError {
fn description(&self) -> &str {
match *self {
GetAdminAccountError::InternalError(ref cause) => cause,
GetAdminAccountError::InvalidOperation(ref cause) => cause,
GetAdminAccountError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetComplianceDetailError {
InternalError(String),
ResourceNotFound(String),
}
impl GetComplianceDetailError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetComplianceDetailError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(GetComplianceDetailError::InternalError(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(GetComplianceDetailError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetComplianceDetailError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetComplianceDetailError {
fn description(&self) -> &str {
match *self {
GetComplianceDetailError::InternalError(ref cause) => cause,
GetComplianceDetailError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetNotificationChannelError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl GetNotificationChannelError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetNotificationChannelError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(GetNotificationChannelError::InternalError(
String::from(error_message),
))
}
"InvalidOperationException" => {
return RusotoError::Service(GetNotificationChannelError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(GetNotificationChannelError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetNotificationChannelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetNotificationChannelError {
fn description(&self) -> &str {
match *self {
GetNotificationChannelError::InternalError(ref cause) => cause,
GetNotificationChannelError::InvalidOperation(ref cause) => cause,
GetNotificationChannelError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum GetPolicyError {
InternalError(String),
InvalidOperation(String),
InvalidType(String),
ResourceNotFound(String),
}
impl GetPolicyError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetPolicyError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(GetPolicyError::InternalError(String::from(
error_message,
)))
}
"InvalidOperationException" => {
return RusotoError::Service(GetPolicyError::InvalidOperation(String::from(
error_message,
)))
}
"InvalidTypeException" => {
return RusotoError::Service(GetPolicyError::InvalidType(String::from(
error_message,
)))
}
"ResourceNotFoundException" => {
return RusotoError::Service(GetPolicyError::ResourceNotFound(String::from(
error_message,
)))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for GetPolicyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for GetPolicyError {
fn description(&self) -> &str {
match *self {
GetPolicyError::InternalError(ref cause) => cause,
GetPolicyError::InvalidOperation(ref cause) => cause,
GetPolicyError::InvalidType(ref cause) => cause,
GetPolicyError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListComplianceStatusError {
InternalError(String),
ResourceNotFound(String),
}
impl ListComplianceStatusError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListComplianceStatusError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(ListComplianceStatusError::InternalError(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(ListComplianceStatusError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for ListComplianceStatusError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListComplianceStatusError {
fn description(&self) -> &str {
match *self {
ListComplianceStatusError::InternalError(ref cause) => cause,
ListComplianceStatusError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListMemberAccountsError {
InternalError(String),
ResourceNotFound(String),
}
impl ListMemberAccountsError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<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 {
"InternalErrorException" => {
return RusotoError::Service(ListMemberAccountsError::InternalError(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(ListMemberAccountsError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
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::InternalError(ref cause) => cause,
ListMemberAccountsError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListPoliciesError {
InternalError(String),
InvalidOperation(String),
LimitExceeded(String),
ResourceNotFound(String),
}
impl ListPoliciesError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListPoliciesError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(ListPoliciesError::InternalError(String::from(
error_message,
)))
}
"InvalidOperationException" => {
return RusotoError::Service(ListPoliciesError::InvalidOperation(String::from(
error_message,
)))
}
"LimitExceededException" => {
return RusotoError::Service(ListPoliciesError::LimitExceeded(String::from(
error_message,
)))
}
"ResourceNotFoundException" => {
return RusotoError::Service(ListPoliciesError::ResourceNotFound(String::from(
error_message,
)))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for ListPoliciesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListPoliciesError {
fn description(&self) -> &str {
match *self {
ListPoliciesError::InternalError(ref cause) => cause,
ListPoliciesError::InvalidOperation(ref cause) => cause,
ListPoliciesError::LimitExceeded(ref cause) => cause,
ListPoliciesError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum PutNotificationChannelError {
InternalError(String),
InvalidOperation(String),
ResourceNotFound(String),
}
impl PutNotificationChannelError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<PutNotificationChannelError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(PutNotificationChannelError::InternalError(
String::from(error_message),
))
}
"InvalidOperationException" => {
return RusotoError::Service(PutNotificationChannelError::InvalidOperation(
String::from(error_message),
))
}
"ResourceNotFoundException" => {
return RusotoError::Service(PutNotificationChannelError::ResourceNotFound(
String::from(error_message),
))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for PutNotificationChannelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for PutNotificationChannelError {
fn description(&self) -> &str {
match *self {
PutNotificationChannelError::InternalError(ref cause) => cause,
PutNotificationChannelError::InvalidOperation(ref cause) => cause,
PutNotificationChannelError::ResourceNotFound(ref cause) => cause,
}
}
}
#[derive(Debug, PartialEq)]
pub enum PutPolicyError {
InternalError(String),
InvalidInput(String),
InvalidOperation(String),
InvalidType(String),
LimitExceeded(String),
ResourceNotFound(String),
}
impl PutPolicyError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<PutPolicyError> {
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 {
"InternalErrorException" => {
return RusotoError::Service(PutPolicyError::InternalError(String::from(
error_message,
)))
}
"InvalidInputException" => {
return RusotoError::Service(PutPolicyError::InvalidInput(String::from(
error_message,
)))
}
"InvalidOperationException" => {
return RusotoError::Service(PutPolicyError::InvalidOperation(String::from(
error_message,
)))
}
"InvalidTypeException" => {
return RusotoError::Service(PutPolicyError::InvalidType(String::from(
error_message,
)))
}
"LimitExceededException" => {
return RusotoError::Service(PutPolicyError::LimitExceeded(String::from(
error_message,
)))
}
"ResourceNotFoundException" => {
return RusotoError::Service(PutPolicyError::ResourceNotFound(String::from(
error_message,
)))
}
"ValidationException" => return RusotoError::Validation(error_message.to_string()),
_ => {}
}
}
return RusotoError::Unknown(res);
}
}
impl fmt::Display for PutPolicyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for PutPolicyError {
fn description(&self) -> &str {
match *self {
PutPolicyError::InternalError(ref cause) => cause,
PutPolicyError::InvalidInput(ref cause) => cause,
PutPolicyError::InvalidOperation(ref cause) => cause,
PutPolicyError::InvalidType(ref cause) => cause,
PutPolicyError::LimitExceeded(ref cause) => cause,
PutPolicyError::ResourceNotFound(ref cause) => cause,
}
}
}
pub trait Fms {
fn associate_admin_account(
&self,
input: AssociateAdminAccountRequest,
) -> RusotoFuture<(), AssociateAdminAccountError>;
fn delete_notification_channel(&self) -> RusotoFuture<(), DeleteNotificationChannelError>;
fn delete_policy(&self, input: DeletePolicyRequest) -> RusotoFuture<(), DeletePolicyError>;
fn disassociate_admin_account(&self) -> RusotoFuture<(), DisassociateAdminAccountError>;
fn get_admin_account(&self) -> RusotoFuture<GetAdminAccountResponse, GetAdminAccountError>;
fn get_compliance_detail(
&self,
input: GetComplianceDetailRequest,
) -> RusotoFuture<GetComplianceDetailResponse, GetComplianceDetailError>;
fn get_notification_channel(
&self,
) -> RusotoFuture<GetNotificationChannelResponse, GetNotificationChannelError>;
fn get_policy(
&self,
input: GetPolicyRequest,
) -> RusotoFuture<GetPolicyResponse, GetPolicyError>;
fn list_compliance_status(
&self,
input: ListComplianceStatusRequest,
) -> RusotoFuture<ListComplianceStatusResponse, ListComplianceStatusError>;
fn list_member_accounts(
&self,
input: ListMemberAccountsRequest,
) -> RusotoFuture<ListMemberAccountsResponse, ListMemberAccountsError>;
fn list_policies(
&self,
input: ListPoliciesRequest,
) -> RusotoFuture<ListPoliciesResponse, ListPoliciesError>;
fn put_notification_channel(
&self,
input: PutNotificationChannelRequest,
) -> RusotoFuture<(), PutNotificationChannelError>;
fn put_policy(
&self,
input: PutPolicyRequest,
) -> RusotoFuture<PutPolicyResponse, PutPolicyError>;
}
#[derive(Clone)]
pub struct FmsClient {
client: Client,
region: region::Region,
}
impl FmsClient {
pub fn new(region: region::Region) -> FmsClient {
FmsClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> FmsClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
FmsClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl Fms for FmsClient {
fn associate_admin_account(
&self,
input: AssociateAdminAccountRequest,
) -> RusotoFuture<(), AssociateAdminAccountError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.AssociateAdminAccount");
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(AssociateAdminAccountError::from_response(response))
}),
)
}
})
}
fn delete_notification_channel(&self) -> RusotoFuture<(), DeleteNotificationChannelError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.DeleteNotificationChannel");
request.set_payload(Some(b"{}".to_vec()));
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(DeleteNotificationChannelError::from_response(response))
}))
}
})
}
fn delete_policy(&self, input: DeletePolicyRequest) -> RusotoFuture<(), DeletePolicyError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.DeletePolicy");
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(DeletePolicyError::from_response(response))),
)
}
})
}
fn disassociate_admin_account(&self) -> RusotoFuture<(), DisassociateAdminAccountError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.DisassociateAdminAccount");
request.set_payload(Some(b"{}".to_vec()));
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(DisassociateAdminAccountError::from_response(response))
}))
}
})
}
fn get_admin_account(&self) -> RusotoFuture<GetAdminAccountResponse, GetAdminAccountError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.GetAdminAccount");
request.set_payload(Some(b"{}".to_vec()));
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::<GetAdminAccountResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetAdminAccountError::from_response(response))),
)
}
})
}
fn get_compliance_detail(
&self,
input: GetComplianceDetailRequest,
) -> RusotoFuture<GetComplianceDetailResponse, GetComplianceDetailError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.GetComplianceDetail");
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::<GetComplianceDetailResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(GetComplianceDetailError::from_response(response))
}),
)
}
})
}
fn get_notification_channel(
&self,
) -> RusotoFuture<GetNotificationChannelResponse, GetNotificationChannelError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.GetNotificationChannel");
request.set_payload(Some(b"{}".to_vec()));
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::<GetNotificationChannelResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(GetNotificationChannelError::from_response(response))
}),
)
}
})
}
fn get_policy(
&self,
input: GetPolicyRequest,
) -> RusotoFuture<GetPolicyResponse, GetPolicyError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.GetPolicy");
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::<GetPolicyResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(GetPolicyError::from_response(response))),
)
}
})
}
fn list_compliance_status(
&self,
input: ListComplianceStatusRequest,
) -> RusotoFuture<ListComplianceStatusResponse, ListComplianceStatusError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.ListComplianceStatus");
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::<ListComplianceStatusResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(ListComplianceStatusError::from_response(response))
}),
)
}
})
}
fn list_member_accounts(
&self,
input: ListMemberAccountsRequest,
) -> RusotoFuture<ListMemberAccountsResponse, ListMemberAccountsError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.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::<ListMemberAccountsResponse>(
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_policies(
&self,
input: ListPoliciesRequest,
) -> RusotoFuture<ListPoliciesResponse, ListPoliciesError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.ListPolicies");
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::<ListPoliciesResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListPoliciesError::from_response(response))),
)
}
})
}
fn put_notification_channel(
&self,
input: PutNotificationChannelRequest,
) -> RusotoFuture<(), PutNotificationChannelError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.PutNotificationChannel");
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(PutNotificationChannelError::from_response(response))
}),
)
}
})
}
fn put_policy(
&self,
input: PutPolicyRequest,
) -> RusotoFuture<PutPolicyResponse, PutPolicyError> {
let mut request = SignedRequest::new("POST", "fms", &self.region, "/");
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.add_header("x-amz-target", "AWSFMS_20180101.PutPolicy");
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::<PutPolicyResponse>(
String::from_utf8_lossy(body.as_ref()).as_ref(),
)
.unwrap()
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(PutPolicyError::from_response(response))),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}