smiklosovic commented on a change in pull request #1051:
URL: https://github.com/apache/cassandra/pull/1051#discussion_r688348410



##########
File path: src/java/org/apache/cassandra/audit/AuditLogOptions.java
##########
@@ -37,11 +46,242 @@
     public String included_users = StringUtils.EMPTY;
     public String excluded_users = StringUtils.EMPTY;
 
-    /**
-     * AuditLogs directory can be configured using `cassandra.logdir.audit` or 
default is set to `cassandra.logdir` + /audit/
-     */
-    public String audit_logs_dir = System.getProperty("cassandra.logdir.audit",
-                                                      
System.getProperty("cassandra.logdir",".")+"/audit/");
+    public String audit_logs_dir;
+
+    public AuditLogOptions()
+    {
+        String auditLogDir = 
CassandraRelevantProperties.LOG_DIR_AUDIT.getString();
+        String logDir = CassandraRelevantProperties.LOG_DIR.getString() + 
"/audit";
+        Path path = auditLogDir == null ? Paths.get(logDir) : 
Paths.get(auditLogDir);
+        audit_logs_dir = path.normalize().toString();
+    }
+
+    public static AuditLogOptions validate(final AuditLogOptions options) 
throws ConfigurationException
+    {
+        // not validating keyspaces nor users on purpose,
+        // logging might be enabled on these entities before they exist
+        // so they are picked up automatically
+
+        validateCategories(options.included_categories);
+        validateCategories(options.excluded_categories);
+
+        // other fields in BinLogOptions are validated upon BinAuditLogger 
initialisation
+
+        return options;
+    }
+
+    public static class Builder
+    {
+        private boolean enabled;
+        private ParameterizedClass logger;
+        private String includedKeyspaces;
+        private String excludedKeyspaces;
+        private String includedCategories;
+        private String excludedCategories;
+        private String includedUsers;
+        private String excludedUsers;
+        private String auditLogDir;
+        private int maxQueueWeight;
+        private int maxArchiveRetries;
+        private String rollCycle;
+        private String archiveCommand;
+        private boolean block;
+        private long maxLogSize;
+
+        public Builder()
+        {
+            this(new AuditLogOptions());
+        }
+
+        public Builder(final AuditLogOptions opts)
+        {
+            this.enabled = opts.enabled;
+            this.logger = opts.logger;
+            this.includedKeyspaces = opts.included_keyspaces;
+            this.excludedKeyspaces = opts.excluded_keyspaces;
+            this.includedCategories = opts.included_categories;
+            this.excludedCategories = opts.excluded_categories;
+            this.includedUsers = opts.included_users;
+            this.excludedUsers = opts.excluded_users;
+            this.auditLogDir = opts.audit_logs_dir;
+            this.maxQueueWeight = opts.max_queue_weight;
+            this.maxArchiveRetries = opts.max_archive_retries;
+            this.rollCycle = opts.roll_cycle;
+            this.archiveCommand = opts.archive_command;
+            this.block = opts.block;
+            this.maxLogSize = opts.max_log_size;
+        }
+
+        public Builder withEnabled(boolean enabled)
+        {
+            this.enabled = enabled;
+            return this;
+        }
+
+        public Builder withLogger(final String loggerName, Map<String, String> 
parameters)
+        {
+
+            if (loggerName != null && !loggerName.trim().isEmpty())
+            {
+                this.logger = new ParameterizedClass(loggerName.trim(), 
parameters);
+            }
+
+            return this;
+        }
+
+        public Builder withIncludedKeyspaces(final String includedKeyspaces)
+        {
+            sanitise(includedKeyspaces).map(v -> this.includedKeyspaces = v);
+            return this;
+        }
+
+        public Builder withExcludedKeyspaces(final String excludedKeyspaces)
+        {
+            sanitise(excludedKeyspaces).map(v -> this.excludedKeyspaces = v);
+            return this;
+        }
+
+        public Builder withIncludedCategories(final String includedCategories)
+        {
+            sanitise(includedCategories).map(v -> this.includedCategories = 
v.toUpperCase());
+            return this;
+        }
+
+        public Builder withExcludedCategories(final String excludedCategories)
+        {
+            sanitise(excludedCategories).map(v -> this.excludedCategories = 
v.toUpperCase());
+            return this;
+        }
+
+        public Builder withIncludedUsers(final String includedUsers)
+        {
+            sanitise(includedUsers).map(v -> this.includedUsers = v);
+            return this;
+        }
+
+        public Builder withExcludedUsers(final String excludedUsers)
+        {
+            sanitise(excludedUsers).map(v -> this.excludedUsers = v);
+            return this;
+        }
+
+        public Builder withAuditLogDir(final String auditLogDir)
+        {
+            this.auditLogDir = auditLogDir;
+            return this;
+        }

Review comment:
       let's keep it how 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