smiklosovic commented on code in PR #4699:
URL: https://github.com/apache/cassandra/pull/4699#discussion_r3069360175


##########
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;

Review Comment:
   imho this is just fine as it is



-- 
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]

Reply via email to