tolbertam commented on code in PR #4699:
URL: https://github.com/apache/cassandra/pull/4699#discussion_r3068440925
##########
src/java/org/apache/cassandra/config/GuardrailsOptions.java:
##########
@@ -1601,4 +1636,57 @@ private static void
validateRoleNamePolicy(CustomGuardrailConfig config)
{
ValueGenerator.getGenerator("role_name_policy",
config).generate(ValueValidator.getValidator("role_name_policy", config),
Map.of());
}
+
+ @VisibleForTesting
+ public static void validateAndSanitizeClientDriverVersions(Map<String,
String> map, String guardrailName)
+ {
+ if (map == null || map.isEmpty())
+ return;
+
+ List<String> invalidEntries = new ArrayList<>();
+
+ for (Map.Entry<String, String> entry : map.entrySet())
+ {
+ String sanitized = sanitizeVersion(entry.getValue());
+ if (!isValidVersion(sanitized))
+ invalidEntries.add(entry.getKey());
+ }
+
+ if (!invalidEntries.isEmpty())
+ throw new IllegalArgumentException("Invalid version entries for "
+ guardrailName + " guardrail, they do not follow semver: " + invalidEntries);
+
+ map.replaceAll((driver, version) -> sanitizeVersion(version));
+ }
+
+ public static boolean isValidVersion(String version)
+ {
+ if (version == null)
+ return false;
+
+ // try to construct it
+ try
+ {
+ new Semver(version);
+ }
+ catch (Throwable t)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static final Pattern VERSION_SANITATION_PATTERN =
Pattern.compile("^[vV]");
Review Comment:
:+1: I see you mentioned this is needed for gocql
[here](https://issues.apache.org/jira/browse/CASSANDRA-21146?focusedCommentId=18069914&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-18069914)
--
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]