CalvinKirs opened a new pull request, #66153:
URL: https://github.com/apache/doris/pull/66153
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
`ConnectorProperty` currently describes property names, aliases, required
fields, supported fields, and sensitive values, while property-specific value
checks have to be implemented separately by each connector.
This PR adds a reusable validation extension point to the connector property
binding framework. A validator receives the target object, annotated field,
matched property name, converted value, and the complete raw property map.
Validation runs after type conversion and before field assignment. Validator
instances are stateless and reused across bindings.
To add validation to a connector property, implement
`ConnectorPropertyValidator`:
```java
public final class ExampleValidator implements ConnectorPropertyValidator {
@Override
public void validate(Object target, Field field, String propertyName,
Object value, Map<String, String> properties) {
if (!isValid(value)) {
throw new IllegalArgumentException("Invalid property " +
propertyName);
}
}
}
```
Then declare it on the property:
```java
@ConnectorProperty(
names = {"example.property"},
validator = ExampleValidator.class)
private String exampleProperty;
```
Properties without a validator retain the existing behavior through the
default no-op validator.
The PR also provides `NoPathTraversalValidator` as the first reusable
implementation. It rejects parent-directory components in path values and
comma-separated resource lists. Hadoop, JFS, OSS-HDFS, and Hive XML resource
properties now use this validator.
### Release note
Add connector property validators and validate parent-directory components
in Hadoop and Hive XML resource paths.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test
- `./run-fe-ut.sh --run
org.apache.doris.foundation.property.ConnectorPropertiesUtilsTest,org.apache.doris.filesystem.hdfs.properties.HdfsPropertiesTest`
- [ ] Manual test
- [ ] No need to test or manual test.
- Behavior changed:
- [ ] No.
- [x] Yes. Hadoop and Hive XML resource properties reject
parent-directory components.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]