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::param::{Params, ServiceParams};
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 Certificate {
#[serde(rename = "data")]
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Cluster {
#[serde(rename = "arn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub arn: Option<String>,
#[serde(rename = "certificateAuthority")]
#[serde(skip_serializing_if = "Option::is_none")]
pub certificate_authority: Option<Certificate>,
#[serde(rename = "clientRequestToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub client_request_token: Option<String>,
#[serde(rename = "createdAt")]
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<f64>,
#[serde(rename = "endpoint")]
#[serde(skip_serializing_if = "Option::is_none")]
pub endpoint: Option<String>,
#[serde(rename = "name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "platformVersion")]
#[serde(skip_serializing_if = "Option::is_none")]
pub platform_version: Option<String>,
#[serde(rename = "resourcesVpcConfig")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resources_vpc_config: Option<VpcConfigResponse>,
#[serde(rename = "roleArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub role_arn: Option<String>,
#[serde(rename = "status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(rename = "version")]
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct CreateClusterRequest {
#[serde(rename = "clientRequestToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub client_request_token: Option<String>,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "resourcesVpcConfig")]
pub resources_vpc_config: VpcConfigRequest,
#[serde(rename = "roleArn")]
pub role_arn: String,
#[serde(rename = "version")]
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct CreateClusterResponse {
#[serde(rename = "cluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster: Option<Cluster>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DeleteClusterRequest {
#[serde(rename = "name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DeleteClusterResponse {
#[serde(rename = "cluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster: Option<Cluster>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeClusterRequest {
#[serde(rename = "name")]
pub name: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeClusterResponse {
#[serde(rename = "cluster")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster: Option<Cluster>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct DescribeUpdateRequest {
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "updateId")]
pub update_id: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct DescribeUpdateResponse {
#[serde(rename = "update")]
#[serde(skip_serializing_if = "Option::is_none")]
pub update: Option<Update>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct ErrorDetail {
#[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 = "resourceIds")]
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_ids: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct ListClustersRequest {
#[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 ListClustersResponse {
#[serde(rename = "clusters")]
#[serde(skip_serializing_if = "Option::is_none")]
pub clusters: 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 ListUpdatesRequest {
#[serde(rename = "maxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "name")]
pub name: 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 ListUpdatesResponse {
#[serde(rename = "nextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "updateIds")]
#[serde(skip_serializing_if = "Option::is_none")]
pub update_ids: Option<Vec<String>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct Update {
#[serde(rename = "createdAt")]
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<f64>,
#[serde(rename = "errors")]
#[serde(skip_serializing_if = "Option::is_none")]
pub errors: Option<Vec<ErrorDetail>>,
#[serde(rename = "id")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "params")]
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<Vec<UpdateParam>>,
#[serde(rename = "status")]
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct UpdateClusterVersionRequest {
#[serde(rename = "clientRequestToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub client_request_token: Option<String>,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "version")]
pub version: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateClusterVersionResponse {
#[serde(rename = "update")]
#[serde(skip_serializing_if = "Option::is_none")]
pub update: Option<Update>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct UpdateParam {
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<String>,
#[serde(rename = "value")]
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub struct VpcConfigRequest {
#[serde(rename = "securityGroupIds")]
#[serde(skip_serializing_if = "Option::is_none")]
pub security_group_ids: Option<Vec<String>>,
#[serde(rename = "subnetIds")]
pub subnet_ids: Vec<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(test, derive(Serialize))]
pub struct VpcConfigResponse {
#[serde(rename = "securityGroupIds")]
#[serde(skip_serializing_if = "Option::is_none")]
pub security_group_ids: Option<Vec<String>>,
#[serde(rename = "subnetIds")]
#[serde(skip_serializing_if = "Option::is_none")]
pub subnet_ids: Option<Vec<String>>,
#[serde(rename = "vpcId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub vpc_id: Option<String>,
}
#[derive(Debug, PartialEq)]
pub enum CreateClusterError {
Client(String),
InvalidParameter(String),
ResourceInUse(String),
ResourceLimitExceeded(String),
Server(String),
ServiceUnavailable(String),
UnsupportedAvailabilityZone(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl CreateClusterError {
pub fn from_response(res: BufferedHttpResponse) -> CreateClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => return CreateClusterError::Client(String::from(error_message)),
"InvalidParameterException" => {
return CreateClusterError::InvalidParameter(String::from(error_message));
}
"ResourceInUseException" => {
return CreateClusterError::ResourceInUse(String::from(error_message));
}
"ResourceLimitExceededException" => {
return CreateClusterError::ResourceLimitExceeded(String::from(error_message));
}
"ServerException" => return CreateClusterError::Server(String::from(error_message)),
"ServiceUnavailableException" => {
return CreateClusterError::ServiceUnavailable(String::from(error_message));
}
"UnsupportedAvailabilityZoneException" => {
return CreateClusterError::UnsupportedAvailabilityZone(String::from(
error_message,
));
}
"ValidationException" => {
return CreateClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return CreateClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for CreateClusterError {
fn from(err: serde_json::error::Error) -> CreateClusterError {
CreateClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for CreateClusterError {
fn from(err: CredentialsError) -> CreateClusterError {
CreateClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for CreateClusterError {
fn from(err: HttpDispatchError) -> CreateClusterError {
CreateClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for CreateClusterError {
fn from(err: io::Error) -> CreateClusterError {
CreateClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for CreateClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for CreateClusterError {
fn description(&self) -> &str {
match *self {
CreateClusterError::Client(ref cause) => cause,
CreateClusterError::InvalidParameter(ref cause) => cause,
CreateClusterError::ResourceInUse(ref cause) => cause,
CreateClusterError::ResourceLimitExceeded(ref cause) => cause,
CreateClusterError::Server(ref cause) => cause,
CreateClusterError::ServiceUnavailable(ref cause) => cause,
CreateClusterError::UnsupportedAvailabilityZone(ref cause) => cause,
CreateClusterError::Validation(ref cause) => cause,
CreateClusterError::Credentials(ref err) => err.description(),
CreateClusterError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
CreateClusterError::ParseError(ref cause) => cause,
CreateClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DeleteClusterError {
Client(String),
ResourceInUse(String),
ResourceNotFound(String),
Server(String),
ServiceUnavailable(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DeleteClusterError {
pub fn from_response(res: BufferedHttpResponse) -> DeleteClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => return DeleteClusterError::Client(String::from(error_message)),
"ResourceInUseException" => {
return DeleteClusterError::ResourceInUse(String::from(error_message));
}
"ResourceNotFoundException" => {
return DeleteClusterError::ResourceNotFound(String::from(error_message));
}
"ServerException" => return DeleteClusterError::Server(String::from(error_message)),
"ServiceUnavailableException" => {
return DeleteClusterError::ServiceUnavailable(String::from(error_message));
}
"ValidationException" => {
return DeleteClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return DeleteClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DeleteClusterError {
fn from(err: serde_json::error::Error) -> DeleteClusterError {
DeleteClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DeleteClusterError {
fn from(err: CredentialsError) -> DeleteClusterError {
DeleteClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for DeleteClusterError {
fn from(err: HttpDispatchError) -> DeleteClusterError {
DeleteClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for DeleteClusterError {
fn from(err: io::Error) -> DeleteClusterError {
DeleteClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DeleteClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DeleteClusterError {
fn description(&self) -> &str {
match *self {
DeleteClusterError::Client(ref cause) => cause,
DeleteClusterError::ResourceInUse(ref cause) => cause,
DeleteClusterError::ResourceNotFound(ref cause) => cause,
DeleteClusterError::Server(ref cause) => cause,
DeleteClusterError::ServiceUnavailable(ref cause) => cause,
DeleteClusterError::Validation(ref cause) => cause,
DeleteClusterError::Credentials(ref err) => err.description(),
DeleteClusterError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DeleteClusterError::ParseError(ref cause) => cause,
DeleteClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeClusterError {
Client(String),
ResourceNotFound(String),
Server(String),
ServiceUnavailable(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeClusterError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeClusterError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => {
return DescribeClusterError::Client(String::from(error_message));
}
"ResourceNotFoundException" => {
return DescribeClusterError::ResourceNotFound(String::from(error_message));
}
"ServerException" => {
return DescribeClusterError::Server(String::from(error_message));
}
"ServiceUnavailableException" => {
return DescribeClusterError::ServiceUnavailable(String::from(error_message));
}
"ValidationException" => {
return DescribeClusterError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeClusterError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeClusterError {
fn from(err: serde_json::error::Error) -> DescribeClusterError {
DescribeClusterError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeClusterError {
fn from(err: CredentialsError) -> DescribeClusterError {
DescribeClusterError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeClusterError {
fn from(err: HttpDispatchError) -> DescribeClusterError {
DescribeClusterError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeClusterError {
fn from(err: io::Error) -> DescribeClusterError {
DescribeClusterError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeClusterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeClusterError {
fn description(&self) -> &str {
match *self {
DescribeClusterError::Client(ref cause) => cause,
DescribeClusterError::ResourceNotFound(ref cause) => cause,
DescribeClusterError::Server(ref cause) => cause,
DescribeClusterError::ServiceUnavailable(ref cause) => cause,
DescribeClusterError::Validation(ref cause) => cause,
DescribeClusterError::Credentials(ref err) => err.description(),
DescribeClusterError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeClusterError::ParseError(ref cause) => cause,
DescribeClusterError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum DescribeUpdateError {
Client(String),
InvalidParameter(String),
ResourceNotFound(String),
Server(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl DescribeUpdateError {
pub fn from_response(res: BufferedHttpResponse) -> DescribeUpdateError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => {
return DescribeUpdateError::Client(String::from(error_message));
}
"InvalidParameterException" => {
return DescribeUpdateError::InvalidParameter(String::from(error_message));
}
"ResourceNotFoundException" => {
return DescribeUpdateError::ResourceNotFound(String::from(error_message));
}
"ServerException" => {
return DescribeUpdateError::Server(String::from(error_message));
}
"ValidationException" => {
return DescribeUpdateError::Validation(error_message.to_string());
}
_ => {}
}
}
return DescribeUpdateError::Unknown(res);
}
}
impl From<serde_json::error::Error> for DescribeUpdateError {
fn from(err: serde_json::error::Error) -> DescribeUpdateError {
DescribeUpdateError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for DescribeUpdateError {
fn from(err: CredentialsError) -> DescribeUpdateError {
DescribeUpdateError::Credentials(err)
}
}
impl From<HttpDispatchError> for DescribeUpdateError {
fn from(err: HttpDispatchError) -> DescribeUpdateError {
DescribeUpdateError::HttpDispatch(err)
}
}
impl From<io::Error> for DescribeUpdateError {
fn from(err: io::Error) -> DescribeUpdateError {
DescribeUpdateError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for DescribeUpdateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for DescribeUpdateError {
fn description(&self) -> &str {
match *self {
DescribeUpdateError::Client(ref cause) => cause,
DescribeUpdateError::InvalidParameter(ref cause) => cause,
DescribeUpdateError::ResourceNotFound(ref cause) => cause,
DescribeUpdateError::Server(ref cause) => cause,
DescribeUpdateError::Validation(ref cause) => cause,
DescribeUpdateError::Credentials(ref err) => err.description(),
DescribeUpdateError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
DescribeUpdateError::ParseError(ref cause) => cause,
DescribeUpdateError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListClustersError {
Client(String),
InvalidParameter(String),
Server(String),
ServiceUnavailable(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListClustersError {
pub fn from_response(res: BufferedHttpResponse) -> ListClustersError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => return ListClustersError::Client(String::from(error_message)),
"InvalidParameterException" => {
return ListClustersError::InvalidParameter(String::from(error_message));
}
"ServerException" => return ListClustersError::Server(String::from(error_message)),
"ServiceUnavailableException" => {
return ListClustersError::ServiceUnavailable(String::from(error_message));
}
"ValidationException" => {
return ListClustersError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListClustersError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListClustersError {
fn from(err: serde_json::error::Error) -> ListClustersError {
ListClustersError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListClustersError {
fn from(err: CredentialsError) -> ListClustersError {
ListClustersError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListClustersError {
fn from(err: HttpDispatchError) -> ListClustersError {
ListClustersError::HttpDispatch(err)
}
}
impl From<io::Error> for ListClustersError {
fn from(err: io::Error) -> ListClustersError {
ListClustersError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListClustersError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListClustersError {
fn description(&self) -> &str {
match *self {
ListClustersError::Client(ref cause) => cause,
ListClustersError::InvalidParameter(ref cause) => cause,
ListClustersError::Server(ref cause) => cause,
ListClustersError::ServiceUnavailable(ref cause) => cause,
ListClustersError::Validation(ref cause) => cause,
ListClustersError::Credentials(ref err) => err.description(),
ListClustersError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListClustersError::ParseError(ref cause) => cause,
ListClustersError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum ListUpdatesError {
Client(String),
InvalidParameter(String),
ResourceNotFound(String),
Server(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl ListUpdatesError {
pub fn from_response(res: BufferedHttpResponse) -> ListUpdatesError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => return ListUpdatesError::Client(String::from(error_message)),
"InvalidParameterException" => {
return ListUpdatesError::InvalidParameter(String::from(error_message));
}
"ResourceNotFoundException" => {
return ListUpdatesError::ResourceNotFound(String::from(error_message));
}
"ServerException" => return ListUpdatesError::Server(String::from(error_message)),
"ValidationException" => {
return ListUpdatesError::Validation(error_message.to_string());
}
_ => {}
}
}
return ListUpdatesError::Unknown(res);
}
}
impl From<serde_json::error::Error> for ListUpdatesError {
fn from(err: serde_json::error::Error) -> ListUpdatesError {
ListUpdatesError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for ListUpdatesError {
fn from(err: CredentialsError) -> ListUpdatesError {
ListUpdatesError::Credentials(err)
}
}
impl From<HttpDispatchError> for ListUpdatesError {
fn from(err: HttpDispatchError) -> ListUpdatesError {
ListUpdatesError::HttpDispatch(err)
}
}
impl From<io::Error> for ListUpdatesError {
fn from(err: io::Error) -> ListUpdatesError {
ListUpdatesError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for ListUpdatesError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for ListUpdatesError {
fn description(&self) -> &str {
match *self {
ListUpdatesError::Client(ref cause) => cause,
ListUpdatesError::InvalidParameter(ref cause) => cause,
ListUpdatesError::ResourceNotFound(ref cause) => cause,
ListUpdatesError::Server(ref cause) => cause,
ListUpdatesError::Validation(ref cause) => cause,
ListUpdatesError::Credentials(ref err) => err.description(),
ListUpdatesError::HttpDispatch(ref dispatch_error) => dispatch_error.description(),
ListUpdatesError::ParseError(ref cause) => cause,
ListUpdatesError::Unknown(_) => "unknown error",
}
}
}
#[derive(Debug, PartialEq)]
pub enum UpdateClusterVersionError {
Client(String),
InvalidParameter(String),
InvalidRequest(String),
ResourceInUse(String),
ResourceNotFound(String),
Server(String),
HttpDispatch(HttpDispatchError),
Credentials(CredentialsError),
Validation(String),
ParseError(String),
Unknown(BufferedHttpResponse),
}
impl UpdateClusterVersionError {
pub fn from_response(res: BufferedHttpResponse) -> UpdateClusterVersionError {
if let Ok(json) = from_slice::<SerdeJsonValue>(&res.body) {
let error_type = match res.headers.get("x-amzn-errortype") {
Some(raw_error_type) => raw_error_type
.split(':')
.next()
.unwrap_or_else(|| "Unknown"),
_ => json
.get("code")
.or_else(|| json.get("Code"))
.and_then(|c| c.as_str())
.unwrap_or_else(|| "Unknown"),
};
let error_message = json
.get("message")
.or_else(|| json.get("Message"))
.and_then(|m| m.as_str())
.unwrap_or("");
match error_type {
"ClientException" => {
return UpdateClusterVersionError::Client(String::from(error_message));
}
"InvalidParameterException" => {
return UpdateClusterVersionError::InvalidParameter(String::from(error_message));
}
"InvalidRequestException" => {
return UpdateClusterVersionError::InvalidRequest(String::from(error_message));
}
"ResourceInUseException" => {
return UpdateClusterVersionError::ResourceInUse(String::from(error_message));
}
"ResourceNotFoundException" => {
return UpdateClusterVersionError::ResourceNotFound(String::from(error_message));
}
"ServerException" => {
return UpdateClusterVersionError::Server(String::from(error_message));
}
"ValidationException" => {
return UpdateClusterVersionError::Validation(error_message.to_string());
}
_ => {}
}
}
return UpdateClusterVersionError::Unknown(res);
}
}
impl From<serde_json::error::Error> for UpdateClusterVersionError {
fn from(err: serde_json::error::Error) -> UpdateClusterVersionError {
UpdateClusterVersionError::ParseError(err.description().to_string())
}
}
impl From<CredentialsError> for UpdateClusterVersionError {
fn from(err: CredentialsError) -> UpdateClusterVersionError {
UpdateClusterVersionError::Credentials(err)
}
}
impl From<HttpDispatchError> for UpdateClusterVersionError {
fn from(err: HttpDispatchError) -> UpdateClusterVersionError {
UpdateClusterVersionError::HttpDispatch(err)
}
}
impl From<io::Error> for UpdateClusterVersionError {
fn from(err: io::Error) -> UpdateClusterVersionError {
UpdateClusterVersionError::HttpDispatch(HttpDispatchError::from(err))
}
}
impl fmt::Display for UpdateClusterVersionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl Error for UpdateClusterVersionError {
fn description(&self) -> &str {
match *self {
UpdateClusterVersionError::Client(ref cause) => cause,
UpdateClusterVersionError::InvalidParameter(ref cause) => cause,
UpdateClusterVersionError::InvalidRequest(ref cause) => cause,
UpdateClusterVersionError::ResourceInUse(ref cause) => cause,
UpdateClusterVersionError::ResourceNotFound(ref cause) => cause,
UpdateClusterVersionError::Server(ref cause) => cause,
UpdateClusterVersionError::Validation(ref cause) => cause,
UpdateClusterVersionError::Credentials(ref err) => err.description(),
UpdateClusterVersionError::HttpDispatch(ref dispatch_error) => {
dispatch_error.description()
}
UpdateClusterVersionError::ParseError(ref cause) => cause,
UpdateClusterVersionError::Unknown(_) => "unknown error",
}
}
}
pub trait Eks {
fn create_cluster(
&self,
input: CreateClusterRequest,
) -> RusotoFuture<CreateClusterResponse, CreateClusterError>;
fn delete_cluster(
&self,
input: DeleteClusterRequest,
) -> RusotoFuture<DeleteClusterResponse, DeleteClusterError>;
fn describe_cluster(
&self,
input: DescribeClusterRequest,
) -> RusotoFuture<DescribeClusterResponse, DescribeClusterError>;
fn describe_update(
&self,
input: DescribeUpdateRequest,
) -> RusotoFuture<DescribeUpdateResponse, DescribeUpdateError>;
fn list_clusters(
&self,
input: ListClustersRequest,
) -> RusotoFuture<ListClustersResponse, ListClustersError>;
fn list_updates(
&self,
input: ListUpdatesRequest,
) -> RusotoFuture<ListUpdatesResponse, ListUpdatesError>;
fn update_cluster_version(
&self,
input: UpdateClusterVersionRequest,
) -> RusotoFuture<UpdateClusterVersionResponse, UpdateClusterVersionError>;
}
#[derive(Clone)]
pub struct EksClient {
client: Client,
region: region::Region,
}
impl EksClient {
pub fn new(region: region::Region) -> EksClient {
EksClient {
client: Client::shared(),
region: region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> EksClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
P::Future: Send,
D: DispatchSignedRequest + Send + Sync + 'static,
D::Future: Send,
{
EksClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region: region,
}
}
}
impl Eks for EksClient {
fn create_cluster(
&self,
input: CreateClusterRequest,
) -> RusotoFuture<CreateClusterResponse, CreateClusterError> {
let request_uri = "/clusters";
let mut request = SignedRequest::new("POST", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<CreateClusterResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(CreateClusterError::from_response(response))),
)
}
})
}
fn delete_cluster(
&self,
input: DeleteClusterRequest,
) -> RusotoFuture<DeleteClusterResponse, DeleteClusterError> {
let request_uri = format!("/clusters/{name}", name = input.name);
let mut request = SignedRequest::new("DELETE", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<DeleteClusterResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DeleteClusterError::from_response(response))),
)
}
})
}
fn describe_cluster(
&self,
input: DescribeClusterRequest,
) -> RusotoFuture<DescribeClusterResponse, DescribeClusterError> {
let request_uri = format!("/clusters/{name}", name = input.name);
let mut request = SignedRequest::new("GET", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<DescribeClusterResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeClusterError::from_response(response))),
)
}
})
}
fn describe_update(
&self,
input: DescribeUpdateRequest,
) -> RusotoFuture<DescribeUpdateResponse, DescribeUpdateError> {
let request_uri = format!(
"/clusters/{name}/updates/{update_id}",
name = input.name,
update_id = input.update_id
);
let mut request = SignedRequest::new("GET", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<DescribeUpdateResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(DescribeUpdateError::from_response(response))),
)
}
})
}
fn list_clusters(
&self,
input: ListClustersRequest,
) -> RusotoFuture<ListClustersResponse, ListClustersError> {
let request_uri = "/clusters";
let mut request = SignedRequest::new("GET", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let mut params = Params::new();
if let Some(ref x) = input.max_results {
params.put("maxResults", x);
}
if let Some(ref x) = input.next_token {
params.put("nextToken", x);
}
request.set_params(params);
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<ListClustersResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListClustersError::from_response(response))),
)
}
})
}
fn list_updates(
&self,
input: ListUpdatesRequest,
) -> RusotoFuture<ListUpdatesResponse, ListUpdatesError> {
let request_uri = format!("/clusters/{name}/updates", name = input.name);
let mut request = SignedRequest::new("GET", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let mut params = Params::new();
if let Some(ref x) = input.max_results {
params.put("maxResults", x);
}
if let Some(ref x) = input.next_token {
params.put("nextToken", x);
}
request.set_params(params);
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result = serde_json::from_slice::<ListUpdatesResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response
.buffer()
.from_err()
.and_then(|response| Err(ListUpdatesError::from_response(response))),
)
}
})
}
fn update_cluster_version(
&self,
input: UpdateClusterVersionRequest,
) -> RusotoFuture<UpdateClusterVersionResponse, UpdateClusterVersionError> {
let request_uri = format!("/clusters/{name}/updates", name = input.name);
let mut request = SignedRequest::new("POST", "eks", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
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 == b"null" || body.is_empty() {
body = b"{}".to_vec();
}
debug!("Response body: {:?}", body);
debug!("Response status: {}", response.status);
let result =
serde_json::from_slice::<UpdateClusterVersionResponse>(&body).unwrap();
result
}))
} else {
Box::new(
response.buffer().from_err().and_then(|response| {
Err(UpdateClusterVersionError::from_response(response))
}),
)
}
})
}
}
#[cfg(test)]
mod protocol_tests {}