ryerraguntla commented on code in PR #4043:
URL: https://github.com/apache/iggy/pull/4043#discussion_r4001364509


##########
gateways/kafka/src/bridge/topic_map.rs:
##########
@@ -0,0 +1,357 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::{HashMap, HashSet};
+use std::path::Path;
+
+use serde::Deserialize;
+
+use crate::bridge::error::BridgeError;
+
+/// Upper bound `Identifier::named` itself enforces (`identifier/mod.rs`). 
Checked here too so a
+/// too-long name in the mapping file fails at config load with a message that 
names the file and
+/// field at fault, instead of surfacing much later as an opaque 
`InvalidIdentifier` deep inside
+/// `IggyBridge::ensure_stream`/`ensure_topic`.
+const MAX_IDENTIFIER_LEN: usize = 255;
+
+/// Rejects an empty name, one with leading/trailing whitespace, or one over
+/// [`MAX_IDENTIFIER_LEN`] bytes.
+///
+/// Whitespace is rejected outright rather than trimmed and stored: silently 
trimming here (or
+/// adding that later) would change the resolved Iggy stream/topic name under 
an already-running
+/// deployment without the operator changing anything they can see in their 
own config file.
+///
+/// `pub(crate)`: also used by `bridge::config` for `IGGY_KAFKA_IGGY_STREAM`, 
which feeds
+/// `default_stream` through the same no-file path this module's own 
validation covers on the
+/// TOML-file path.
+pub(crate) fn validate_identifier_name(field: &str, value: &str) -> Result<(), 
BridgeError> {
+    if value.is_empty() {
+        return Err(BridgeError::InvalidConfig(format!(
+            "{field} must not be empty"
+        )));
+    }
+    if value.trim() != value {
+        return Err(BridgeError::InvalidConfig(format!(
+            "{field} must not have leading or trailing whitespace: {value:?}"
+        )));
+    }
+    if value.len() > MAX_IDENTIFIER_LEN {
+        return Err(BridgeError::InvalidConfig(format!(
+            "{field} is {} bytes, over the {MAX_IDENTIFIER_LEN}-byte limit 
Identifier::named \
+             enforces: {value:?}",
+            value.len()
+        )));
+    }
+    Ok(())
+}
+
+/// Explicit Kafka-topic → Iggy stream/topic override. Absent entries fall 
back to
+/// [`TopicMapping::default_stream`] plus the Kafka topic name unchanged - see
+/// [`TopicMapping::resolve`].
+#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
+#[serde(deny_unknown_fields)]
+pub struct TopicOverride {
+    pub stream: String,
+    pub topic: String,
+}
+
+/// Kafka topic name → Iggy stream/topic mapping, loaded from TOML.
+///
+/// Default rule (no override): the Iggy stream is 
[`default_stream`](Self::default_stream) and
+/// the Iggy topic name is the Kafka topic name unchanged. A gateway that 
fronts a single Kafka
+/// "cluster" for one Iggy stream never needs an override entry at all.
+///
+/// No `Default` impl: an empty `default_stream` is not a valid `TopicMapping` 
-
+/// [`from_toml_str`](Self::from_toml_str) rejects it, and a derived `Default` 
would silently
+/// produce exactly that.
+#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
+#[serde(deny_unknown_fields)]
+pub struct TopicMapping {

Review Comment:
   **Fixed**. TopicMapping's fields are now private; Deserialize moved to a 
private RawTopicMapping, and TopicMapping::new(default_stream, topics) -> 
Result<Self, BridgeError> is the sole checked constructor - used by both 
from_toml_str and the no-file path in config.rs, and by every direct 
construction in tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to