results.add(new ValidationResult.Builder().valid(false).input(null).subject(descriptor.getName()).explanation(descriptor.getName() + " is required").build()); continue; } else if (value == null) {
new ValidationResult.Builder() .explanation("You must declare " + SCRIPT_CODE_PROCESS.getName() + " or " + SCRIPT_PATH.getName() + " but not both") .valid(false) .build()); new ValidationResult.Builder() .explanation("No python code declared. Use " + SCRIPT_CODE_PROCESS.getName() + " or " + SCRIPT_PATH.getName() + " to define some python code") .valid(false) .build()); } else new ValidationResult.Builder() .explanation("Inline mode requires at least " + SCRIPT_CODE_PROCESS.getName() + " to be defined") .valid(false) .build()); new ValidationResult.Builder() .explanation("Inline mode requires at least " + SCRIPT_CODE_IMPORTS.getName() + " to be defined") .valid(false) .build());
results.add(new ValidationResult.Builder() .subject(RedisUtils.CONNECTION_STRING.getDisplayName()) .valid(false) .explanation("Connection String cannot be blank") .build()); } else if (RedisUtils.REDIS_MODE_STANDALONE.getValue().equals(redisMode)) { final String[] hostAndPort = connectionString.split("[:]"); if (hostAndPort == null || hostAndPort.length != 2 || StringUtils.isBlank(hostAndPort[0]) || StringUtils.isBlank(hostAndPort[1]) || !isInteger(hostAndPort[1])) { results.add(new ValidationResult.Builder() .subject(RedisUtils.CONNECTION_STRING.getDisplayName()) .input(connectionString) .valid(false) .explanation("Standalone Connection String must be in the form host:port") .build()); final String[] hostAndPort = connection.split("[:]"); if (hostAndPort == null || hostAndPort.length != 2 || StringUtils.isBlank(hostAndPort[0]) || StringUtils.isBlank(hostAndPort[1]) || !isInteger(hostAndPort[1])) { results.add(new ValidationResult.Builder() .subject(RedisUtils.CONNECTION_STRING.getDisplayName()) .input(connection) .valid(false) .explanation("Connection String must be in the form host:port,host:port,host:port,etc.") .build()); results.add(new ValidationResult.Builder() .subject(RedisUtils.DATABASE.getDisplayName()) .valid(false) .explanation("Database Index must be 0 when using clustered Redis") .build());
new ValidationResult.Builder() .explanation("if " + MAIL_TO.getName() + " is not set, " + ALLOW_OVERWRITE.getName() + " must be true" + " so that the record holds a " + FIELD_MAIL_TO + " field that is used.") .valid(false) .build()); new ValidationResult.Builder() .explanation("Both " + SMTP_SECURITY_USERNAME.getName() + " and " + SMTP_SECURITY_PASSWORD.getName() + " should be set" + " or none of them.") .valid(false) .build());
new ValidationResult.Builder() .input(KEY_REGEX.getName()) .explanation("key regex and fields must be set together") .valid(false) .build());
public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); // if security is enabled then the keytab and principal are required final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext context) { final Collection<ValidationResult> results = new ArrayList<>(); if (context.getPropertyValue(DECAY).asDouble() < 0.0) { results.add( new ValidationResult.Builder() .valid(false) .input(null) .subject(DECAY.getName()) .explanation(DECAY.getName() + " must be >= 0.0") .build() ); } if (context.getPropertyValue(DECAY).asDouble() >= 1.0) { results.add( new ValidationResult.Builder() .valid(false) .input(null) .subject(DECAY.getName()) .explanation(DECAY.getName() + " must be < 1.0") .build() ); } return results; }
@Override public ValidationResult validate(final String subject, final String input) { /* if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build(); }*/ if (input == null) { return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Time Period cannot be null").build(); } if (TIME_DURATION_PATTERN.matcher(input.toLowerCase()).matches()) { return new ValidationResult.Builder().subject(subject).input(input).valid(true).build(); } else { return new ValidationResult.Builder() .subject(subject) .input(input) .valid(false) .explanation("Must be of format <duration> <TimeUnit> where <duration> is a " + "non-negative integer and TimeUnit is a supported Time Unit, such " + "as: nanos, millis, secs, mins, hrs, days") .build(); } } };
@Override public ValidationResult validate(String subject, String input) { // Check that the Kerberos configuration is set if (kerberosConfigFile == null) { return new ValidationResult.Builder() .subject(subject).input(input).valid(false) .explanation("you are missing the logisland.kerberos.krb5.file property which " + "must be set in order to use Kerberos") .build(); } // Check that the Kerberos configuration is readable if (!kerberosConfigFile.canRead()) { return new ValidationResult.Builder().subject(subject).input(input).valid(false) .explanation(String.format("unable to read Kerberos config [%s], please make sure the path is valid " + "and logisland has adequate permissions", kerberosConfigFile.getAbsoluteFile())) .build(); } return new ValidationResult.Builder().subject(subject).input(input).valid(true).build(); } };
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { final File file = new File(value); if (!file.exists()) { if (!create) { reason = "Directory does not exist"; } else if (!file.mkdirs()) { reason = "Directory does not exist and could not be created"; } } else if (!file.isDirectory()) { reason = "Path does not point to a directory"; } } catch (final Exception e) { reason = "Value is not a valid directory name"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } }
@Override protected Collection<ValidationResult> customValidate(ValidationContext context) { final List<ValidationResult> validationResults = new ArrayList<>(super.customValidate(context)); if (context.getPropertyValue(STRATEGY).isSet()) { if (context.getPropertyValue(STRATEGY).getRawValue().equals(JAVA_FORMAT_STRING_WITH_FIELDS_STRATEGY.getValue())) { if (!context.getPropertyValue(JAVA_FORMAT_STRING).isSet()) { validationResults.add( new ValidationResult.Builder() .input(JAVA_FORMAT_STRING.getName()) .explanation(String.format("%s must be set when strategy is %s", JAVA_FORMAT_STRING.getName(), context.getPropertyValue(STRATEGY).getRawValue())) .valid(false) .build()); } } } return validationResults; }
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { if (value == null) { reason = "null is not a valid integer"; } else { final long longVal = Long.parseLong(value); if (longVal <= 0) { reason = "not a positive value"; } } } catch (final NumberFormatException e) { reason = "not a valid 64-bit integer"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { if (value == null) { reason = "null is not a valid integer"; } else { final int intVal = Integer.parseInt(value); if (intVal <= 0) { reason = "not a positive value"; } } } catch (final NumberFormatException e) { reason = "not a valid integer"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String value) { if (value.length() < minimum || value.length() > maximum) { return new ValidationResult.Builder() .subject(subject) .valid(false) .input(value) .explanation(String.format("String length invalid [min: %d, max: %d]", minimum, maximum)) .build(); } else { return new ValidationResult.Builder() .valid(true) .input(value) .subject(subject) .build(); } } }
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { if (value == null) { reason = "null is not a valid integer"; } else { final int intVal = Integer.parseInt(value); if (intVal < 0) { reason = "value is negative"; } } } catch (final NumberFormatException e) { reason = "value is not a valid integer"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { String[] fields = value.split(","); for (String field : fields) { String f = field.trim(); if (!defaultFields.contains(f)) { reason += "The field " + f + " is not valid. "; } } } catch (final Exception e) { reason = "not a comma separated list"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } })
@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); int jsonPathCount = 0; for (final PropertyDescriptor desc : context.getProperties().keySet()) { if (desc.isDynamic()) { jsonPathCount++; } } if (jsonPathCount != 1) { results.add(new ValidationResult.Builder().subject("JsonPaths").valid(false) .explanation("Exactly one JsonPath must be set if using d").build()); } return results; }
@Override public ValidationResult validate(final String subject, final String input) { final ValidationResult.Builder builder = new ValidationResult.Builder(); builder.input(input); builder.subject(subject); if (validValues.contains(input)) { builder.valid(true); builder.explanation(POSITIVE_EXPLANATION); } else { builder.valid(false); builder.explanation(String.format(NEGATIVE_EXPLANATION, validStrings)); } return builder.build(); } }
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { if (value == null) { reason = "null is not a valid integer"; } else { Integer.parseInt(value); } } catch (final NumberFormatException e) { reason = "not a valid integer"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String value) { String reason = null; try { if (value == null) { reason = "null is not a valid long"; } else { Long.parseLong(value); } } catch (final NumberFormatException e) { reason = "not a valid Long"; } return new ValidationResult.Builder().subject(subject).input(value).explanation(reason).valid(reason == null).build(); } };