Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sources to use AWS SDK Rust #2300

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
837 changes: 506 additions & 331 deletions sources/Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions sources/api/pluto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ apiclient = { path = "../apiclient", version = "0.1.0" }
constants = { path = "../../constants", version = "0.1.0" }
hyper = "0.14.2"
hyper-proxy = { version = "0.9", default-features = false, features = ["rustls"] }
hyper-rustls = "0.23"
hyper-rustls = { version = "0.23", default-features = false, features = ["http2", "native-tokio", "tls12", "logging"] }
imdsclient = { path = "../../imdsclient", version = "0.1.0" }
models = { path = "../../models", version = "0.1.0" }
rusoto_core = { version = "0.48.0", default-features = false, features = ["rustls"] }
rusoto_eks = { version = "0.48.0", default-features = false, features = ["rustls"] }
aws-config = "0.46.0"
aws-sdk-eks = "0.16.0"
aws-types = "0.46.0"
aws-smithy-client = { version = "0.46.0", default-features = false, features = ["rustls"] }
serde_json = "1"
snafu = "0.7"
tokio = { version = "~1.14", default-features = false, features = ["macros", "rt-multi-thread"] } # LTS
Expand Down
36 changes: 15 additions & 21 deletions sources/api/pluto/src/eks.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
use aws_sdk_eks::model::KubernetesNetworkConfigResponse;
use aws_types::region::Region;
use hyper::http::uri::InvalidUri;
use hyper::Uri;
use hyper_proxy::{Proxy, ProxyConnector};
use hyper_rustls::HttpsConnectorBuilder;
use rusoto_core::credential::ChainProvider;
use rusoto_core::region::ParseRegionError;
use rusoto_core::{Region, RusotoError};
use rusoto_eks::{DescribeClusterError, Eks, EksClient, KubernetesNetworkConfigResponse};
use snafu::{OptionExt, ResultExt, Snafu};
use std::env;
use std::str::FromStr;

pub(crate) type ClusterNetworkConfig = KubernetesNetworkConfigResponse;

#[derive(Debug, Snafu)]
pub(super) enum Error {
#[snafu(display("Error describing cluster: {}", source))]
DescribeCluster {
source: RusotoError<DescribeClusterError>,
source: aws_sdk_eks::types::SdkError<aws_sdk_eks::error::DescribeClusterError>,
etungsten marked this conversation as resolved.
Show resolved Hide resolved
},

#[snafu(display("Missing field '{}' EKS response", field))]
Missing { field: &'static str },

#[snafu(display("Unable to parse '{}' as a region: {}", region, source))]
RegionParse {
region: String,
source: ParseRegionError,
},

#[snafu(display("Unable to parse '{}' as URI: {}", input, source))]
UriParse { input: String, source: InvalidUri },

Expand All @@ -43,8 +34,6 @@ pub(super) async fn get_cluster_network_config(
region: &str,
cluster: &str,
) -> Result<ClusterNetworkConfig> {
let parsed_region = Region::from_str(region).context(RegionParseSnafu { region })?;

// Respect proxy environment variables when making AWS EKS API requests
let https_proxy = ["https_proxy", "HTTPS_PROXY"]
.iter()
Expand All @@ -57,6 +46,11 @@ pub(super) async fn get_cluster_network_config(
.find(|env_var| *env_var != Err(env::VarError::NotPresent))
.and_then(|s| s.ok());

let config = aws_config::from_env()
.region(Region::new(region.to_owned()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little weirded out by the fact that aws_sdk_rust doesn't attempt to do validation on the input string. We also don't do any validation on settings.aws.regions. I'm assuming this just takes whatever is given here and generates API endpoints. Just something to keep in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably make some guesses surrounding what a region name looked like, but, I feel like we open ourselves to being broken every time a new region is released by doing so.

.load()
.await;

let client = if let Some(https_proxy) = https_proxy {
// Determines whether a request of a given scheme, host and port should be proxied
// according to `https_proxy` and `no_proxy`.
Expand Down Expand Up @@ -104,17 +98,17 @@ pub(super) async fn get_cluster_network_config(
.build();
let proxy_connector =
ProxyConnector::from_proxy(https_connector, proxy).context(ProxyConnectorSnafu)?;
let http_client = rusoto_core::request::HttpClient::from_connector(proxy_connector);
EksClient::new_with(http_client, ChainProvider::new(), parsed_region)
let http_client = aws_smithy_client::hyper_ext::Adapter::builder().build(proxy_connector);
let eks_config = aws_sdk_eks::config::Builder::from(&config).build();
aws_sdk_eks::Client::from_conf_conn(eks_config, http_client)
} else {
EksClient::new(parsed_region)
};
let describe_cluster = rusoto_eks::DescribeClusterRequest {
name: cluster.to_owned(),
aws_sdk_eks::Client::new(&config)
};

client
.describe_cluster(describe_cluster)
.describe_cluster()
.name(cluster.to_owned())
.send()
.await
.context(DescribeClusterSnafu)?
.cluster
Expand Down
2 changes: 1 addition & 1 deletion sources/api/pluto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async fn get_cluster_dns_ip(client: &mut ImdsClient) -> Result<String> {
.context(error::EksSnafu)
{
// Derive cluster-dns-ip from the service IPv4 CIDR
if let Some(ipv4_cidr) = config.service_ipv_4_cidr {
if let Some(ipv4_cidr) = config.service_ipv4_cidr {
if let Ok(dns_ip) = get_dns_from_ipv4_cidr(&ipv4_cidr) {
return Ok(dns_ip);
}
Expand Down
5 changes: 3 additions & 2 deletions sources/cfsignal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ simplelog = "0.12"
snafu = { version = "0.7" }
toml = "0.5.1"
tokio = { version = "~1.14", default-features = false, features = ["macros", "rt-multi-thread"] }
rusoto_core = { version = "0.48.0", default-features = false, features = ["rustls"] }
rusoto_cloudformation = { version = "0.48.0", default-features = false, features = ["rustls"] }
aws-config = "0.46.0"
aws-sdk-cloudformation = "0.16.0"
aws-types = "0.46.0"
imdsclient = { path = "../imdsclient", version = "0.1.0" }
hyper = "0.14.2"

Expand Down
31 changes: 17 additions & 14 deletions sources/cfsignal/src/cloudformation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::str::FromStr;

Copy link
Contributor

@etungsten etungsten Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

use crate::error::{self, Result};
use aws_types::region::Region;
use imdsclient::ImdsClient;
use log::info;
use rusoto_cloudformation::{CloudFormation, CloudFormationClient, SignalResourceInput};
use rusoto_core::Region;
use snafu::{OptionExt, ResultExt};
use std::str::FromStr;

/// Signals Cloudformation stack resource
pub async fn signal_resource(
Expand All @@ -21,19 +21,22 @@ pub async fn signal_resource(
"Region: {:?} - InstanceID: {:?} - Signal: {:?}",
region, instance_id, status
);

let client = CloudFormationClient::new(
Region::from_str(&region).context(error::RegionParseSnafu { region })?,
);
let signal_resource_input = SignalResourceInput {
stack_name,
logical_resource_id,
status,
unique_id: instance_id,
};
let config = aws_config::from_env()
.region(Region::new(region.to_owned()))
.load()
.await;
let client = aws_sdk_cloudformation::Client::new(&config);

client
.signal_resource(signal_resource_input)
.signal_resource()
.stack_name(stack_name)
.logical_resource_id(logical_resource_id)
.status(
aws_sdk_cloudformation::model::ResourceSignalStatus::from_str(&status)
.context(error::ParseStatusSnafu)?,
)
.unique_id(instance_id)
.send()
.await
.context(error::SignalResourceSnafu)?;

Expand Down
11 changes: 5 additions & 6 deletions sources/cfsignal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ pub enum Error {

#[snafu(display("SignalResource request failed: {}", source))]
SignalResource {
source: rusoto_core::RusotoError<rusoto_cloudformation::SignalResourceError>,
source: aws_sdk_cloudformation::types::SdkError<
aws_sdk_cloudformation::error::SignalResourceError,
>,
},

#[snafu(display("Unable to parse '{}' as a region: {}", region, source))]
RegionParse {
region: String,
source: rusoto_core::region::ParseRegionError,
},
#[snafu(display("Failed to parse status: {}", source))]
ParseStatus { source: core::convert::Infallible },
}
8 changes: 8 additions & 0 deletions sources/clarify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ license-files = [
{ path = "LICENSE", hash = 0xfa2cf349 },
]

[clarify.unicode-ident]
expression = "(MIT OR Apache-2.0) AND Unicode-DFS-2016"
license-files = [
{ path = "LICENSE-APACHE", hash = 0x24b54f4b },
{ path = "LICENSE-MIT", hash = 0x386ca1bc },
{ path = "LICENSE-UNICODE", hash = 0x9698cbbe },
]

[clarify.vmw_backdoor]
expression = "MIT OR Apache-2.0"
license-files = [
Expand Down
7 changes: 7 additions & 0 deletions sources/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ allow = [
"Unlicense",
"Zlib"
]
exceptions = [
{ name = "unicode-ident", version = "1.0.2", allow = ["MIT", "Apache-2.0", "Unicode-DFS-2016"] },
]

# https://github.com/hsivonen/encoding_rs The non-test code that isn't generated from the WHATWG data in this crate is
# under Apache-2.0 OR MIT. Test code is under CC0.
Expand Down Expand Up @@ -56,6 +59,10 @@ skip = [
# older version used by argh_derive and structopt-derive
{ name = "heck", version = "0.3.3" },

# newer version used by headers
# older version used by tungstenite
{ name = "sha-1", version = "0.9.8" },

# newer version used by model-derive and darling
# older version used by clap 2.34.0, via cargo-readme
{ name = "strsim", version = "0.8.0" },
Expand Down