rrd4j
rrd4j copied to clipboard
RrdDef expose validation method for parameter sanitization
Right now the only option I see is calling new RrdDef("path").addDatasource(ds); for each datasource input string I have just for validation, which throws an IllegalArgumentException.
It would be nice to have a public validation method that I can call to perform input parameter sanitization.
Why would you like to have a datasource string without doing anything with it ? It would go to a RrdDef any ways.
We're leaving the config open to users, so they can setup the things they need persisted, see this for more background [0]. So what happens is I'm trying to verify that the inputs are valid (datasource and archive) by creating a new RrdDef and catching the IllegalArgumentException, which I think could be done in a cleaner way via a dedicated validate method.
So instead of doing
private static boolean checkIt(String ds) {
try {
new RrdDef("path").addDatasource(ds);
return true;
} catch (IllegalArgumentException e) {
// ignore
}
return false;
}
I could simply be doing RrdDef.isValidDatasource(ds), if you agree to refactor the check into a dedicated method.
And same applies to the archive validation bits.
If this is still not clear, I can do a PR later with the proposed changes to clarify.
thanks!
[0] https://issues.apache.org/jira/browse/SLING-7055