Skip to content

Commit ea1b751

Browse files
feat: Add Region::is_default_config function (#983)
* feat: Add Region::is_default_config function * changelog * update docs * Update crates/stackable-operator/src/commons/s3/crd.rs Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> * Fix compilation --------- Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
1 parent bc176bf commit ea1b751

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

crates/stackable-operator/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+
### Added
8+
9+
- Add a `Region::is_default_config` function to determine if a region sticks to the default config ([#983]).
10+
11+
[#983]: https://github.com/stackabletech/operator-rs/pull/983
12+
713
## [0.87.2] - 2025-03-10
814

915
### Changed

crates/stackable-operator/src/commons/s3/crd.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,32 @@ pub enum S3AccessStyle {
9898
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
9999
#[serde(rename_all = "camelCase")]
100100
pub struct Region {
101-
#[serde(default = "default_region_name")]
101+
#[serde(default = "Region::default_region_name")]
102102
pub name: String,
103103
}
104104

105+
impl Region {
106+
/// Having it as `const &str` as well, so we don't always allocate a [`String`] just for comparisons
107+
pub const DEFAULT_REGION_NAME: &str = "us-east-1";
108+
109+
fn default_region_name() -> String {
110+
Self::DEFAULT_REGION_NAME.to_string()
111+
}
112+
113+
/// Returns if the region sticks to the Stackable defaults.
114+
///
115+
/// Some products don't really support configuring the region.
116+
/// This function can be used to determine if a warning or error should be raised to inform the
117+
/// user of this situation.
118+
pub fn is_default_config(&self) -> bool {
119+
self.name == Self::DEFAULT_REGION_NAME
120+
}
121+
}
122+
105123
impl Default for Region {
106124
fn default() -> Self {
107125
Self {
108-
name: default_region_name(),
126+
name: Self::default_region_name(),
109127
}
110128
}
111129
}
112-
113-
fn default_region_name() -> String {
114-
"us-east-1".into()
115-
}

0 commit comments

Comments
 (0)