Skip to content

[Merged by Bors] - Bugfix: S3 endpoint protocol selection. #390

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

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- BREAKING: Removed `commons::s3::S3ConnectionImplementation`. `commons::s3::InlinedBucketSpec::endpoint()` doesn't take arguments since the protocol decision is now based on the existance of TLS configuration ([#390]).

[#390]: https://github.com/stackabletech/operator-rs/issues/390

## [0.18.0] - 2022-05-04

### Added
Expand Down
42 changes: 16 additions & 26 deletions src/commons/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ pub struct InlinedS3BucketSpec {

impl InlinedS3BucketSpec {
/// Build the endpoint URL from [S3ConnectionSpec::host] and [S3ConnectionSpec::port] and the S3 implementation to use
pub fn endpoint(&self, implementation: &S3ConnectionImplementation) -> Option<String> {
let implementation = implementation.to_string();
self.connection.as_ref().and_then(|connection| {
connection.host.as_ref().map(|h| match connection.port {
Some(p) => format!("{implementation}://{h}:{p}"),
None => format!("{implementation}://{h}"),
})
})
pub fn endpoint(&self) -> Option<String> {
self.connection
.as_ref()
.and_then(|connection| connection.endpoint())
}

/// Shortcut to [S3ConnectionSpec::secret_class]
Expand All @@ -96,24 +92,6 @@ impl InlinedS3BucketSpec {
}
}

/// The implementation the product should use when interacting with S3
/// It is sometimes called protocol as it is prepended to the connection endpoint, e.g. `s3a://<host>`
/// but it often specifies which s3 client implemtation to use, the used protocol on the wire is always S3.
/// Spark e.g. supports `s3a` and `cos` as S3 connectors/implementations, which are different implementations but talk to the same S3 endpoint.
pub enum S3ConnectionImplementation {
S3,
S3a,
}

impl ToString for S3ConnectionImplementation {
fn to_string(&self) -> String {
match self {
S3ConnectionImplementation::S3 => "s3".to_string(),
S3ConnectionImplementation::S3a => "s3a".to_string(),
}
}
}

/// Operators are expected to define fields for this type in order to work with S3 buckets.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -205,6 +183,18 @@ impl S3ConnectionSpec {
name: resource_name.to_string(),
})
}

/// Build the endpoint URL from this connection
pub fn endpoint(&self) -> Option<String> {
let protocol = match self.tls.as_ref() {
Some(_tls) => "https",
_ => "http",
};
self.host.as_ref().map(|h| match self.port {
Some(p) => format!("{protocol}://{h}:{p}"),
None => format!("{protocol}://{h}"),
})
}
}

#[cfg(test)]
Expand Down