Showing
3 changed files
with
7 additions
and
5 deletions
@@ -323,8 +323,11 @@ audit_log: | @@ -323,8 +323,11 @@ audit_log: | ||
323 | # Name of the index where audit logs stored | 323 | # Name of the index where audit logs stored |
324 | # Index name could contain next placeholders (not mandatory): | 324 | # Index name could contain next placeholders (not mandatory): |
325 | # @{TENANT} - substituted by tenant ID | 325 | # @{TENANT} - substituted by tenant ID |
326 | - # @{DATE} - substituted by current date in YYYY.MM.DD format | 326 | + # @{DATE} - substituted by current date in format provided in audit_log.sink.date_format |
327 | index_pattern: "${AUDIT_LOG_SINK_INDEX_PATTERN:@{TENANT}_AUDIT_LOG_@{DATE}}" | 327 | index_pattern: "${AUDIT_LOG_SINK_INDEX_PATTERN:@{TENANT}_AUDIT_LOG_@{DATE}}" |
328 | + # Date format. Details of the pattern could be found here: | ||
329 | + # https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html | ||
330 | + date_format: "${AUDIT_LOG_SINK_DATE_FORMAT:YYYY.MM.DD}" | ||
328 | scheme_name: "${AUDIT_LOG_SINK_SCHEME_NAME:http}" # http or https | 331 | scheme_name: "${AUDIT_LOG_SINK_SCHEME_NAME:http}" # http or https |
329 | host: "${AUDIT_LOG_SINK_HOST:localhost}" | 332 | host: "${AUDIT_LOG_SINK_HOST:localhost}" |
330 | port: "${AUDIT_LOG_SINK_POST:9200}" | 333 | port: "${AUDIT_LOG_SINK_POST:9200}" |
@@ -300,7 +300,6 @@ public class AuditLogServiceImpl implements AuditLogService { | @@ -300,7 +300,6 @@ public class AuditLogServiceImpl implements AuditLogService { | ||
300 | futures.add(auditLogDao.saveByTenantIdAndCustomerId(auditLogEntry)); | 300 | futures.add(auditLogDao.saveByTenantIdAndCustomerId(auditLogEntry)); |
301 | futures.add(auditLogDao.saveByTenantIdAndUserId(auditLogEntry)); | 301 | futures.add(auditLogDao.saveByTenantIdAndUserId(auditLogEntry)); |
302 | 302 | ||
303 | - // TODO: is this correct place to log action into sink? | ||
304 | auditLogSink.logAction(auditLogEntry); | 303 | auditLogSink.logAction(auditLogEntry); |
305 | 304 | ||
306 | return Futures.allAsList(futures); | 305 | return Futures.allAsList(futures); |
@@ -50,8 +50,6 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | @@ -50,8 +50,6 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | ||
50 | 50 | ||
51 | private static final String TENANT_PLACEHOLDER = "@{TENANT}"; | 51 | private static final String TENANT_PLACEHOLDER = "@{TENANT}"; |
52 | private static final String DATE_PLACEHOLDER = "@{DATE}"; | 52 | private static final String DATE_PLACEHOLDER = "@{DATE}"; |
53 | - private static final String DATE_FORMAT = "YYYY.MM.dd"; | ||
54 | - | ||
55 | private static final String INDEX_TYPE = "audit_log"; | 53 | private static final String INDEX_TYPE = "audit_log"; |
56 | 54 | ||
57 | private final ObjectMapper mapper = new ObjectMapper(); | 55 | private final ObjectMapper mapper = new ObjectMapper(); |
@@ -68,6 +66,8 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | @@ -68,6 +66,8 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | ||
68 | private String userName; | 66 | private String userName; |
69 | @Value("${audit_log.sink.password}") | 67 | @Value("${audit_log.sink.password}") |
70 | private String password; | 68 | private String password; |
69 | + @Value("${audit_log.sink.date_format}") | ||
70 | + private String dateFormat; | ||
71 | 71 | ||
72 | private RestClient restClient; | 72 | private RestClient restClient; |
73 | 73 | ||
@@ -152,7 +152,7 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | @@ -152,7 +152,7 @@ public class ElasticsearchAuditLogSink implements AuditLogSink { | ||
152 | } | 152 | } |
153 | if (indexName.contains(DATE_PLACEHOLDER)) { | 153 | if (indexName.contains(DATE_PLACEHOLDER)) { |
154 | LocalDateTime now = LocalDateTime.now(); | 154 | LocalDateTime now = LocalDateTime.now(); |
155 | - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); | 155 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat); |
156 | indexName = indexName.replace(DATE_PLACEHOLDER, now.format(formatter)); | 156 | indexName = indexName.replace(DATE_PLACEHOLDER, now.format(formatter)); |
157 | } | 157 | } |
158 | return indexName.toLowerCase(); | 158 | return indexName.toLowerCase(); |