@@ -73,28 +73,19 @@ pub struct ConnectionSpec {
73
73
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
74
74
pub port : Option < u16 > ,
75
75
76
- /// AWS service API region used by the AWS SDK when using AWS S3 buckets .
76
+ /// Bucket region used for signing headers (sigv4) .
77
77
///
78
- /// This defaults to `us-east-1` and can be ignored if not using AWS S3
79
- /// buckets.
78
+ /// This defaults to `us-east-1` which is compatible with other implementations such as Minio.
80
79
///
81
- /// NOTE: This is not the bucket region, and is used by the AWS SDK to
82
- /// construct endpoints for various AWS service APIs. It is only useful when
83
- /// using AWS S3 buckets.
84
- ///
85
- /// When using AWS S3 buckets, you can configure optimal AWS service API
86
- /// connections in the following ways:
87
- /// - From **inside** AWS: Use an auto-discovery source (eg: AWS IMDS).
88
- /// - From **outside** AWS, or when IMDS is disabled, explicity set the
89
- /// region name nearest to where the client application is running from.
80
+ /// WARNING: Some products use the Hadoop S3 implementation which falls back to us-east-2.
90
81
#[ serde( default ) ]
91
- pub region : AwsRegion ,
82
+ pub region : Region ,
92
83
93
84
/// Which access style to use.
94
85
/// Defaults to virtual hosted-style as most of the data products out there.
95
86
/// Have a look at the [AWS documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
96
87
#[ serde( default ) ]
97
- pub access_style : AccessStyle ,
88
+ pub access_style : S3AccessStyle ,
98
89
99
90
/// If the S3 uses authentication you have to specify you S3 credentials.
100
91
/// In the most cases a [SecretClass](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass)
@@ -111,7 +102,7 @@ pub struct ConnectionSpec {
111
102
strum:: Display , Clone , Debug , Default , Deserialize , Eq , JsonSchema , PartialEq , Serialize ,
112
103
) ]
113
104
#[ strum( serialize_all = "PascalCase" ) ]
114
- pub enum AccessStyle {
105
+ pub enum S3AccessStyle {
115
106
/// Use path-style access as described in <https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access>
116
107
Path ,
117
108
@@ -120,60 +111,40 @@ pub enum AccessStyle {
120
111
VirtualHosted ,
121
112
}
122
113
123
- /// Set a named AWS region, or defer to an auto-discovery mechanism .
114
+ /// Set a named S3 Bucket region .
124
115
#[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
125
116
#[ serde( rename_all = "camelCase" ) ]
126
- pub enum AwsRegion {
127
- /// Defer region detection to an auto-discovery mechanism.
128
- Source ( AwsRegionAutoDiscovery ) ,
129
-
130
- /// An explicit region, eg: eu-central-1
131
- Name ( String ) ,
117
+ pub struct Region {
118
+ #[ serde( default = "Region::default_region_name" ) ]
119
+ pub name : String ,
132
120
}
133
121
134
- impl AwsRegion {
135
- /// Get the AWS region name.
136
- ///
137
- /// Returns `None` if an auto-discovery source has been selected. Otherwise,
138
- /// it returns the configured region name.
139
- ///
140
- /// Example usage:
122
+ impl Region {
123
+ /// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons
124
+ pub const DEFAULT_REGION_NAME : & str = "us-east-1" ;
125
+
126
+ fn default_region_name ( ) -> String {
127
+ Self :: DEFAULT_REGION_NAME . to_string ( )
128
+ }
129
+
130
+ /// Returns if the region sticks to the Stackable defaults.
141
131
///
142
- /// ```
143
- /// # use stackable_operator::commons::s3::AwsRegion;
144
- /// # fn set_property(key: &str, value: &str) {}
145
- /// # fn example(aws_region: AwsRegion) {
146
- /// if let Some(region_name) = aws_region.name() {
147
- /// // set some property if the region is set, or is the default.
148
- /// set_property("aws.region", region_name);
149
- /// };
150
- /// # }
151
- /// ```
152
- pub fn name ( & self ) -> Option < & str > {
153
- match self {
154
- AwsRegion :: Name ( name) => Some ( name) ,
155
- AwsRegion :: Source ( _) => None ,
156
- }
132
+ /// Some products don't really support configuring the region.
133
+ /// This function can be used to determine if a warning or error should be raised to inform the
134
+ /// user of this situation.
135
+ pub fn is_default_config ( & self ) -> bool {
136
+ self . name == Self :: DEFAULT_REGION_NAME
157
137
}
158
138
}
159
139
160
- impl Default for AwsRegion {
140
+ impl Default for Region {
161
141
fn default ( ) -> Self {
162
- Self :: Name ( "us-east-1" . to_owned ( ) )
142
+ Self {
143
+ name : Self :: default_region_name ( ) ,
144
+ }
163
145
}
164
146
}
165
147
166
- /// AWS region auto-discovery mechanism.
167
- #[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
168
- #[ serde( rename_all = "PascalCase" ) ]
169
- pub enum AwsRegionAutoDiscovery {
170
- /// AWS Instance Meta Data Service.
171
- ///
172
- /// This variant should result in no region being given to the AWS SDK,
173
- /// which should, in turn, query the AWS IMDS.
174
- AwsImds ,
175
- }
176
-
177
148
#[ derive( Clone , Debug , Deserialize , Eq , JsonSchema , PartialEq , Serialize ) ]
178
149
#[ serde( rename_all = "camelCase" ) ]
179
150
// TODO: This probably should be serde(untagged), but this would be a breaking change
0 commit comments