Skip to content
Merged
Changes from 1 commit
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
62 changes: 7 additions & 55 deletions crates/stackable-operator/src/commons/s3/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,8 @@ pub struct S3ConnectionSpec {
/// NOTE: This is not the bucket region, and is used by the AWS SDK to
/// construct endpoints for various AWS service APIs. It is only useful when
/// using AWS S3 buckets.
///
/// When using AWS S3 buckets, you can configure optimal AWS service API
/// connections in the following ways:
/// - From **inside** AWS: Use an auto-discovery source (eg: AWS IMDS).
/// - From **outside** AWS, or when IMDS is disabled, explicity set the
/// region name nearest to where the client application is running from.
#[serde(default)]
pub region: AwsRegion,
pub region: Region,

/// Which access style to use.
/// Defaults to virtual hosted-style as most of the data products out there.
Expand Down Expand Up @@ -104,55 +98,13 @@ pub enum S3AccessStyle {
}

/// Set a named AWS region, or defer to an auto-discovery mechanism.
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum AwsRegion {
/// Defer region detection to an auto-discovery mechanism.
Source(AwsRegionAutoDiscovery),

/// An explicit region, eg: eu-central-1
Name(String),
}

impl AwsRegion {
/// Get the AWS region name.
///
/// Returns `None` if an auto-discovery source has been selected. Otherwise,
/// it returns the configured region name.
///
/// Example usage:
///
/// ```
/// # use stackable_operator::commons::s3::AwsRegion;
/// # fn set_property(key: &str, value: &str) {}
/// # fn example(aws_region: AwsRegion) {
/// if let Some(region_name) = aws_region.name() {
/// // set some property if the region is set, or is the default.
/// set_property("aws.region", region_name);
/// };
/// # }
/// ```
pub fn name(&self) -> Option<&str> {
match self {
AwsRegion::Name(name) => Some(name),
AwsRegion::Source(_) => None,
}
}
pub struct Region {
#[serde(default = "default_region_name")]
name: String,
}

impl Default for AwsRegion {
fn default() -> Self {
Self::Name("us-east-1".to_owned())
}
}

/// AWS region auto-discovery mechanism.
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub enum AwsRegionAutoDiscovery {
/// AWS Instance Meta Data Service.
///
/// This variant should result in no region being given to the AWS SDK,
/// which should, in turn, query the AWS IMDS.
AwsImds,
fn default_region_name() -> String {
"us-east-1".into()
}