-
Notifications
You must be signed in to change notification settings - Fork 463
feat: Add protocol aliases for IOConfig #6252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,7 +213,6 @@ pub struct CosConfig { | |
| #[pymethods] | ||
| impl IOConfig { | ||
| #[new] | ||
| #[must_use] | ||
| #[allow(clippy::too_many_arguments)] | ||
| #[pyo3(signature = ( | ||
| s3=None, | ||
|
|
@@ -226,7 +225,8 @@ impl IOConfig { | |
| tos=None, | ||
| gravitino=None, | ||
| cos=None, | ||
| opendal_backends=None | ||
| opendal_backends=None, | ||
| protocol_aliases=None | ||
| ))] | ||
| #[allow(clippy::too_many_arguments)] | ||
|
Comment on lines
216
to
231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate The Context Used: Rule from |
||
| pub fn new( | ||
|
|
@@ -241,30 +241,36 @@ impl IOConfig { | |
| gravitino: Option<GravitinoConfig>, | ||
| cos: Option<CosConfig>, | ||
| opendal_backends: Option<HashMap<String, HashMap<String, String>>>, | ||
| ) -> Self { | ||
| Self { | ||
| config: config::IOConfig { | ||
| s3: s3.unwrap_or_default().config, | ||
| azure: azure.unwrap_or_default().config, | ||
| gcs: gcs.unwrap_or_default().config, | ||
| http: http.unwrap_or_default().config, | ||
| unity: unity.unwrap_or_default().config, | ||
| hf: hf.unwrap_or_default().config, | ||
| disable_suffix_range: disable_suffix_range.unwrap_or_default(), | ||
| tos: tos.unwrap_or_default().config, | ||
| gravitino: gravitino.unwrap_or_default().config, | ||
| cos: cos.unwrap_or_default().config, | ||
| opendal_backends: opendal_backends | ||
| .unwrap_or_default() | ||
| .into_iter() | ||
| .map(|(k, v)| (k, v.into_iter().collect())) | ||
| .collect(), | ||
| }, | ||
| } | ||
| protocol_aliases: Option<HashMap<String, String>>, | ||
| ) -> PyResult<Self> { | ||
| let cfg = config::IOConfig { | ||
| s3: s3.unwrap_or_default().config, | ||
| azure: azure.unwrap_or_default().config, | ||
| gcs: gcs.unwrap_or_default().config, | ||
| http: http.unwrap_or_default().config, | ||
| unity: unity.unwrap_or_default().config, | ||
| hf: hf.unwrap_or_default().config, | ||
| disable_suffix_range: disable_suffix_range.unwrap_or_default(), | ||
| tos: tos.unwrap_or_default().config, | ||
| gravitino: gravitino.unwrap_or_default().config, | ||
| cos: cos.unwrap_or_default().config, | ||
| opendal_backends: opendal_backends | ||
| .unwrap_or_default() | ||
| .into_iter() | ||
| .map(|(k, v)| (k, v.into_iter().collect())) | ||
| .collect(), | ||
| protocol_aliases: protocol_aliases | ||
| .unwrap_or_default() | ||
| .into_iter() | ||
| .map(|(k, v)| (k.to_lowercase(), v.to_lowercase())) | ||
| .collect(), | ||
| }; | ||
| cfg.validate_protocol_aliases() | ||
| .map_err(pyo3::exceptions::PyValueError::new_err)?; | ||
| Ok(Self { config: cfg }) | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_arguments)] | ||
| #[must_use] | ||
| #[pyo3(signature = ( | ||
| s3=None, | ||
| azure=None, | ||
|
|
@@ -276,7 +282,8 @@ impl IOConfig { | |
| tos=None, | ||
| gravitino=None, | ||
| cos=None, | ||
| opendal_backends=None | ||
| opendal_backends=None, | ||
| protocol_aliases=None | ||
| ))] | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub fn replace( | ||
|
|
@@ -292,47 +299,55 @@ impl IOConfig { | |
| gravitino: Option<GravitinoConfig>, | ||
| cos: Option<CosConfig>, | ||
| opendal_backends: Option<HashMap<String, HashMap<String, String>>>, | ||
| ) -> Self { | ||
| Self { | ||
| config: config::IOConfig { | ||
| s3: s3 | ||
| .map(|s3| s3.config) | ||
| .unwrap_or_else(|| self.config.s3.clone()), | ||
| azure: azure | ||
| .map(|azure| azure.config) | ||
| .unwrap_or_else(|| self.config.azure.clone()), | ||
| gcs: gcs | ||
| .map(|gcs| gcs.config) | ||
| .unwrap_or_else(|| self.config.gcs.clone()), | ||
| http: http | ||
| .map(|http| http.config) | ||
| .unwrap_or_else(|| self.config.http.clone()), | ||
| unity: unity | ||
| .map(|unity| unity.config) | ||
| .unwrap_or_else(|| self.config.unity.clone()), | ||
| hf: hf | ||
| .map(|hf| hf.config) | ||
| .unwrap_or_else(|| self.config.hf.clone()), | ||
| disable_suffix_range: disable_suffix_range | ||
| .unwrap_or(self.config.disable_suffix_range), | ||
| tos: tos | ||
| .map(|tos| tos.config) | ||
| .unwrap_or_else(|| self.config.tos.clone()), | ||
| gravitino: gravitino | ||
| .map(|gravitino| gravitino.config) | ||
| .unwrap_or_else(|| self.config.gravitino.clone()), | ||
| cos: cos | ||
| .map(|cos| cos.config) | ||
| .unwrap_or_else(|| self.config.cos.clone()), | ||
| opendal_backends: opendal_backends | ||
| .map(|b| { | ||
| b.into_iter() | ||
| .map(|(k, v)| (k, v.into_iter().collect())) | ||
| .collect() | ||
| }) | ||
| .unwrap_or_else(|| self.config.opendal_backends.clone()), | ||
| }, | ||
| } | ||
| protocol_aliases: Option<HashMap<String, String>>, | ||
| ) -> PyResult<Self> { | ||
| let cfg = config::IOConfig { | ||
| s3: s3 | ||
| .map(|s3| s3.config) | ||
| .unwrap_or_else(|| self.config.s3.clone()), | ||
| azure: azure | ||
| .map(|azure| azure.config) | ||
| .unwrap_or_else(|| self.config.azure.clone()), | ||
| gcs: gcs | ||
| .map(|gcs| gcs.config) | ||
| .unwrap_or_else(|| self.config.gcs.clone()), | ||
| http: http | ||
| .map(|http| http.config) | ||
| .unwrap_or_else(|| self.config.http.clone()), | ||
| unity: unity | ||
| .map(|unity| unity.config) | ||
| .unwrap_or_else(|| self.config.unity.clone()), | ||
| hf: hf | ||
| .map(|hf| hf.config) | ||
| .unwrap_or_else(|| self.config.hf.clone()), | ||
| disable_suffix_range: disable_suffix_range.unwrap_or(self.config.disable_suffix_range), | ||
| tos: tos | ||
| .map(|tos| tos.config) | ||
| .unwrap_or_else(|| self.config.tos.clone()), | ||
| gravitino: gravitino | ||
| .map(|gravitino| gravitino.config) | ||
| .unwrap_or_else(|| self.config.gravitino.clone()), | ||
| cos: cos | ||
| .map(|cos| cos.config) | ||
| .unwrap_or_else(|| self.config.cos.clone()), | ||
| opendal_backends: opendal_backends | ||
| .map(|b| { | ||
| b.into_iter() | ||
| .map(|(k, v)| (k, v.into_iter().collect())) | ||
| .collect() | ||
| }) | ||
| .unwrap_or_else(|| self.config.opendal_backends.clone()), | ||
| protocol_aliases: protocol_aliases | ||
| .map(|a| { | ||
| a.into_iter() | ||
| .map(|(k, v)| (k.to_lowercase(), v.to_lowercase())) | ||
| .collect() | ||
| }) | ||
| .unwrap_or_else(|| self.config.protocol_aliases.clone()), | ||
| }; | ||
| cfg.validate_protocol_aliases() | ||
| .map_err(pyo3::exceptions::PyValueError::new_err)?; | ||
| Ok(Self { config: cfg }) | ||
| } | ||
|
|
||
| pub fn __repr__(&self) -> PyResult<String> { | ||
|
|
@@ -415,6 +430,17 @@ impl IOConfig { | |
| .collect()) | ||
| } | ||
|
|
||
| /// Protocol aliases mapping custom scheme names to existing schemes | ||
| #[getter] | ||
| pub fn protocol_aliases(&self) -> PyResult<HashMap<String, String>> { | ||
| Ok(self | ||
| .config | ||
| .protocol_aliases | ||
| .iter() | ||
| .map(|(k, v)| (k.clone(), v.clone())) | ||
| .collect()) | ||
| } | ||
|
|
||
| /// Configuration to be used when accessing COS URLs | ||
| #[getter] | ||
| pub fn cos(&self) -> PyResult<CosConfig> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alias target values are not validated against known schemes
validate_protocol_aliasesonly verifies that alias keys don't shadow built-in schemes. It does not validate that alias values (targets) actually refer to a known scheme or a registered OpenDAL backend. A config like{"my-proto": "typo-schme"}will be accepted at construction time and only fail at runtime when a URL is first resolved. Consider validating that alias targets are either built-in schemes or present inopendal_backends, so users catch configuration mistakes early.