Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Add Region::is_default_config function
  • Loading branch information
sbernauer committed Mar 14, 2025
commit 4d68587e7d9b426e10710c1a1575fe627d354c99
4 changes: 4 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add a `Region::is_default_config` function to determine if a region sticks to the default config ([#XXX]).

## [0.87.2] - 2025-03-10

### Changed
Expand Down
25 changes: 19 additions & 6 deletions crates/stackable-operator/src/commons/s3/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,31 @@ pub enum S3AccessStyle {
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Region {
#[serde(default = "default_region_name")]
#[serde(default = "Region::default_region_name")]
pub name: String,
}

/// Having it as const &str as well, so we don't always allocate a [`String`] just for comparisons
const DEFAULT_REGION_NAME: &str = "us-east-1";
impl Region {
fn default_region_name() -> String {
DEFAULT_REGION_NAME.to_string()
}

/// Returns if the region sticks to the Stackable defaults.
///
/// Some products don't really support configuring the region.
/// This function can be used to determine if a warning or error should be raised to inform the
/// user of this situation.
pub fn is_default_config(&self) -> bool {
self.name == DEFAULT_REGION_NAME
}
}

impl Default for Region {
fn default() -> Self {
Self {
name: default_region_name(),
name: Self::default_region_name(),
}
}
}

fn default_region_name() -> String {
"us-east-1".into()
}