rrd4j icon indicating copy to clipboard operation
rrd4j copied to clipboard

RrdDef expose validation method for parameter sanitization

Open stillalex opened this issue 8 years ago • 2 comments

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.

stillalex avatar Aug 23 '17 16:08 stillalex

Why would you like to have a datasource string without doing anything with it ? It would go to a RrdDef any ways.

fbacchella avatar Aug 23 '17 18:08 fbacchella

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

stillalex avatar Aug 24 '17 09:08 stillalex