Skip to content

Commit fb6e65f

Browse files
committed
Bugfix: S3 endpoint protocol selection. (#390)
1 parent aad7eaf commit fb6e65f

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Changed
8+
9+
- 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]).
10+
11+
[#390]: https://github.com/stackabletech/operator-rs/issues/390
12+
713
## [0.18.0] - 2022-05-04
814

915
### Added

src/commons/s3.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,10 @@ pub struct InlinedS3BucketSpec {
7777

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

9086
/// Shortcut to [S3ConnectionSpec::secret_class]
@@ -96,24 +92,6 @@ impl InlinedS3BucketSpec {
9692
}
9793
}
9894

99-
/// The implementation the product should use when interacting with S3
100-
/// It is sometimes called protocol as it is prepended to the connection endpoint, e.g. `s3a://<host>`
101-
/// but it often specifies which s3 client implemtation to use, the used protocol on the wire is always S3.
102-
/// Spark e.g. supports `s3a` and `cos` as S3 connectors/implementations, which are different implementations but talk to the same S3 endpoint.
103-
pub enum S3ConnectionImplementation {
104-
S3,
105-
S3a,
106-
}
107-
108-
impl ToString for S3ConnectionImplementation {
109-
fn to_string(&self) -> String {
110-
match self {
111-
S3ConnectionImplementation::S3 => "s3".to_string(),
112-
S3ConnectionImplementation::S3a => "s3a".to_string(),
113-
}
114-
}
115-
}
116-
11795
/// Operators are expected to define fields for this type in order to work with S3 buckets.
11896
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
11997
#[serde(rename_all = "camelCase")]
@@ -205,6 +183,18 @@ impl S3ConnectionSpec {
205183
name: resource_name.to_string(),
206184
})
207185
}
186+
187+
/// Build the endpoint URL from this connection
188+
pub fn endpoint(&self) -> Option<String> {
189+
let protocol = match self.tls.as_ref() {
190+
Some(_tls) => "https",
191+
_ => "http",
192+
};
193+
self.host.as_ref().map(|h| match self.port {
194+
Some(p) => format!("{protocol}://{h}:{p}"),
195+
None => format!("{protocol}://{h}"),
196+
})
197+
}
208198
}
209199

210200
#[cfg(test)]

0 commit comments

Comments
 (0)