use std::error::Error;
use std::fmt;
use async_trait::async_trait;
use rusoto_core::credential::ProvideAwsCredentials;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoError};
use rusoto_core::proto;
use rusoto_core::signature::SignedRequest;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
use serde_json;
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct Connection {
#[serde(rename = "ConnectionArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_arn: Option<String>,
#[serde(rename = "ConnectionName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_name: Option<String>,
#[serde(rename = "ConnectionStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_status: Option<String>,
#[serde(rename = "OwnerAccountId")]
#[serde(skip_serializing_if = "Option::is_none")]
pub owner_account_id: Option<String>,
#[serde(rename = "ProviderType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_type: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct CreateConnectionInput {
#[serde(rename = "ConnectionName")]
pub connection_name: String,
#[serde(rename = "ProviderType")]
pub provider_type: String,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct CreateConnectionOutput {
#[serde(rename = "ConnectionArn")]
pub connection_arn: String,
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct DeleteConnectionInput {
#[serde(rename = "ConnectionArn")]
pub connection_arn: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct DeleteConnectionOutput {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct GetConnectionInput {
#[serde(rename = "ConnectionArn")]
pub connection_arn: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct GetConnectionOutput {
#[serde(rename = "Connection")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connection: Option<Connection>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct ListConnectionsInput {
#[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 = "ProviderTypeFilter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_type_filter: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct ListConnectionsOutput {
#[serde(rename = "Connections")]
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Connection>>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct ListTagsForResourceInput {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct ListTagsForResourceOutput {
#[serde(rename = "Tags")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<Tag>>,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tag {
#[serde(rename = "Key")]
pub key: String,
#[serde(rename = "Value")]
pub value: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct TagResourceInput {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
#[serde(rename = "Tags")]
pub tags: Vec<Tag>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct TagResourceOutput {}
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct UntagResourceInput {
#[serde(rename = "ResourceArn")]
pub resource_arn: String,
#[serde(rename = "TagKeys")]
pub tag_keys: Vec<String>,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct UntagResourceOutput {}
#[derive(Debug, PartialEq)]
pub enum CreateConnectionError {
LimitExceeded(String),
}
impl CreateConnectionError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<CreateConnectionError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"LimitExceededException" => {
return RusotoError::Service(CreateConnectionError::LimitExceeded(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for CreateConnectionError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
CreateConnectionError::LimitExceeded(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for CreateConnectionError {}
#[derive(Debug, PartialEq)]
pub enum DeleteConnectionError {
ResourceNotFound(String),
}
impl DeleteConnectionError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeleteConnectionError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"ResourceNotFoundException" => {
return RusotoError::Service(DeleteConnectionError::ResourceNotFound(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for DeleteConnectionError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DeleteConnectionError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for DeleteConnectionError {}
#[derive(Debug, PartialEq)]
pub enum GetConnectionError {
ResourceNotFound(String),
}
impl GetConnectionError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetConnectionError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"ResourceNotFoundException" => {
return RusotoError::Service(GetConnectionError::ResourceNotFound(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for GetConnectionError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
GetConnectionError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for GetConnectionError {}
#[derive(Debug, PartialEq)]
pub enum ListConnectionsError {}
impl ListConnectionsError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListConnectionsError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for ListConnectionsError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {}
}
}
impl Error for ListConnectionsError {}
#[derive(Debug, PartialEq)]
pub enum ListTagsForResourceError {
ResourceNotFound(String),
}
impl ListTagsForResourceError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListTagsForResourceError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"ResourceNotFoundException" => {
return RusotoError::Service(ListTagsForResourceError::ResourceNotFound(
err.msg,
))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for ListTagsForResourceError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ListTagsForResourceError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for ListTagsForResourceError {}
#[derive(Debug, PartialEq)]
pub enum TagResourceError {
LimitExceeded(String),
ResourceNotFound(String),
}
impl TagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<TagResourceError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"LimitExceededException" => {
return RusotoError::Service(TagResourceError::LimitExceeded(err.msg))
}
"ResourceNotFoundException" => {
return RusotoError::Service(TagResourceError::ResourceNotFound(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for TagResourceError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TagResourceError::LimitExceeded(ref cause) => write!(f, "{}", cause),
TagResourceError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for TagResourceError {}
#[derive(Debug, PartialEq)]
pub enum UntagResourceError {
ResourceNotFound(String),
}
impl UntagResourceError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<UntagResourceError> {
if let Some(err) = proto::json::Error::parse(&res) {
match err.typ.as_str() {
"ResourceNotFoundException" => {
return RusotoError::Service(UntagResourceError::ResourceNotFound(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for UntagResourceError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
UntagResourceError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for UntagResourceError {}
#[async_trait]
pub trait CodeStarConnections {
async fn create_connection(
&self,
input: CreateConnectionInput,
) -> Result<CreateConnectionOutput, RusotoError<CreateConnectionError>>;
async fn delete_connection(
&self,
input: DeleteConnectionInput,
) -> Result<DeleteConnectionOutput, RusotoError<DeleteConnectionError>>;
async fn get_connection(
&self,
input: GetConnectionInput,
) -> Result<GetConnectionOutput, RusotoError<GetConnectionError>>;
async fn list_connections(
&self,
input: ListConnectionsInput,
) -> Result<ListConnectionsOutput, RusotoError<ListConnectionsError>>;
async fn list_tags_for_resource(
&self,
input: ListTagsForResourceInput,
) -> Result<ListTagsForResourceOutput, RusotoError<ListTagsForResourceError>>;
async fn tag_resource(
&self,
input: TagResourceInput,
) -> Result<TagResourceOutput, RusotoError<TagResourceError>>;
async fn untag_resource(
&self,
input: UntagResourceInput,
) -> Result<UntagResourceOutput, RusotoError<UntagResourceError>>;
}
#[derive(Clone)]
pub struct CodeStarConnectionsClient {
client: Client,
region: region::Region,
}
impl CodeStarConnectionsClient {
pub fn new(region: region::Region) -> CodeStarConnectionsClient {
CodeStarConnectionsClient {
client: Client::shared(),
region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> CodeStarConnectionsClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
D: DispatchSignedRequest + Send + Sync + 'static,
{
CodeStarConnectionsClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region,
}
}
pub fn new_with_client(client: Client, region: region::Region) -> CodeStarConnectionsClient {
CodeStarConnectionsClient { client, region }
}
}
#[async_trait]
impl CodeStarConnections for CodeStarConnectionsClient {
async fn create_connection(
&self,
input: CreateConnectionInput,
) -> Result<CreateConnectionOutput, RusotoError<CreateConnectionError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.CreateConnection",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<CreateConnectionOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(CreateConnectionError::from_response(response))
}
}
async fn delete_connection(
&self,
input: DeleteConnectionInput,
) -> Result<DeleteConnectionOutput, RusotoError<DeleteConnectionError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.DeleteConnection",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<DeleteConnectionOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(DeleteConnectionError::from_response(response))
}
}
async fn get_connection(
&self,
input: GetConnectionInput,
) -> Result<GetConnectionOutput, RusotoError<GetConnectionError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.GetConnection",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<GetConnectionOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(GetConnectionError::from_response(response))
}
}
async fn list_connections(
&self,
input: ListConnectionsInput,
) -> Result<ListConnectionsOutput, RusotoError<ListConnectionsError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.ListConnections",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<ListConnectionsOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(ListConnectionsError::from_response(response))
}
}
async fn list_tags_for_resource(
&self,
input: ListTagsForResourceInput,
) -> Result<ListTagsForResourceOutput, RusotoError<ListTagsForResourceError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.ListTagsForResource",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response)
.deserialize::<ListTagsForResourceOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(ListTagsForResourceError::from_response(response))
}
}
async fn tag_resource(
&self,
input: TagResourceInput,
) -> Result<TagResourceOutput, RusotoError<TagResourceError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.TagResource",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<TagResourceOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(TagResourceError::from_response(response))
}
}
async fn untag_resource(
&self,
input: UntagResourceInput,
) -> Result<UntagResourceOutput, RusotoError<UntagResourceError>> {
let mut request = SignedRequest::new("POST", "codestar-connections", &self.region, "/");
request.set_content_type("application/x-amz-json-1.0".to_owned());
request.add_header(
"x-amz-target",
"com.amazonaws.codestar.connections.CodeStar_connections_20191201.UntagResource",
);
let encoded = serde_json::to_string(&input).unwrap();
request.set_payload(Some(encoded));
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
proto::json::ResponsePayload::new(&response).deserialize::<UntagResourceOutput, _>()
} else {
let try_response = response.buffer().await;
let response = try_response.map_err(RusotoError::HttpDispatch)?;
Err(UntagResourceError::from_response(response))
}
}
}