Skip to content

Commit 3c6d764

Browse files
merge
1 parent 869efe8 commit 3c6d764

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/audit/builder.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@
1818

1919
use std::fmt::Display;
2020

21-
use crate::{about::current, parseable::PARSEABLE, storage::StorageMetadata, HTTP_CLIENT};
21+
use crate::{about::current, storage::StorageMetadata};
2222

23-
use chrono::{DateTime, Utc};
24-
use once_cell::sync::Lazy;
25-
use serde::Serialize;
26-
use serde_json::{json, Value};
23+
use chrono::Utc;
2724
use tracing::error;
2825
use ulid::Ulid;
2926

30-
use crate::{about::current, storage::StorageMetadata};
31-
3227
use super::{
3328
ActorDetails, AuditDetails, AuditLog, AuditLogVersion, RequestDetails, ResponseDetails,
3429
ServerDetails, AUDIT_LOG_TX,

src/audit/logger.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tokio::{
2828
use tracing::{error, info, warn};
2929
use url::Url;
3030

31-
use crate::{option::CONFIG, HTTP_CLIENT};
31+
use crate::{parseable::PARSEABLE, HTTP_CLIENT};
3232

3333
use super::{AuditLog, AUDIT_LOG_TX};
3434

@@ -48,15 +48,15 @@ impl Default for AuditLogger {
4848
fn default() -> Self {
4949
let mut logger = AuditLogger {
5050
log_endpoint: None,
51-
batch: Vec::with_capacity(CONFIG.options.audit_batch_size),
51+
batch: Vec::with_capacity(PARSEABLE.options.audit_batch_size),
5252
next_log_file_id: 0,
5353
oldest_log_file_id: 0,
5454
};
5555

5656
// Try to construct the log endpoint URL by joining the base URL
5757
// with the ingest path, This can fail if the URL is not valid,
5858
// when the base URL is not set or the ingest path is not valid
59-
let Some(url) = CONFIG.options.audit_logger.as_ref() else {
59+
let Some(url) = PARSEABLE.options.audit_logger.as_ref() else {
6060
return logger;
6161
};
6262

@@ -66,11 +66,11 @@ impl Default for AuditLogger {
6666
.ok();
6767

6868
// Created directory for audit logs if it doesn't exist
69-
std::fs::create_dir_all(&CONFIG.options.audit_log_dir)
69+
std::fs::create_dir_all(&PARSEABLE.options.audit_log_dir)
7070
.expect("Failed to create audit log directory");
7171

7272
// Figure out the latest and oldest log file in directory
73-
let files = std::fs::read_dir(&CONFIG.options.audit_log_dir)
73+
let files = std::fs::read_dir(&PARSEABLE.options.audit_log_dir)
7474
.expect("Failed to read audit log directory");
7575
let (oldest_log_file_id, latest_log_file_id) =
7676
files.fold((usize::MAX, 0), |(oldest, latest), r| {
@@ -106,7 +106,7 @@ impl AuditLogger {
106106
}
107107

108108
// swap the old batch with a new empty one
109-
let mut logs_to_send = Vec::with_capacity(CONFIG.options.audit_batch_size);
109+
let mut logs_to_send = Vec::with_capacity(PARSEABLE.options.audit_batch_size);
110110
std::mem::swap(&mut self.batch, &mut logs_to_send);
111111

112112
// send the logs to the remote logging system, if no backlog, else write to disk
@@ -117,7 +117,7 @@ impl AuditLogger {
117117
}
118118

119119
// write the logs to the next log file
120-
let log_file_path = CONFIG
120+
let log_file_path = PARSEABLE
121121
.options
122122
.audit_log_dir
123123
.join(format!("{}.json", self.next_log_file_id));
@@ -141,7 +141,7 @@ impl AuditLogger {
141141
self.batch.push(log);
142142

143143
// Flush if batch size exceeds threshold
144-
if self.batch.len() >= CONFIG.options.audit_batch_size {
144+
if self.batch.len() >= PARSEABLE.options.audit_batch_size {
145145
self.flush().await
146146
}
147147
}
@@ -154,7 +154,7 @@ impl AuditLogger {
154154
}
155155

156156
// read the oldest log file
157-
let oldest_file_path = CONFIG
157+
let oldest_file_path = PARSEABLE
158158
.options
159159
.audit_log_dir
160160
.join(format!("{}.json", self.oldest_log_file_id));
@@ -180,8 +180,8 @@ impl AuditLogger {
180180
.header("x-p-stream", "audit_log");
181181

182182
// Use basic auth if credentials are configured
183-
if let Some(username) = CONFIG.options.audit_username.as_ref() {
184-
req = req.basic_auth(username, CONFIG.options.audit_password.as_ref())
183+
if let Some(username) = PARSEABLE.options.audit_username.as_ref() {
184+
req = req.basic_auth(username, PARSEABLE.options.audit_password.as_ref())
185185
}
186186

187187
// Send batched logs to the audit logging backend
@@ -204,7 +204,7 @@ impl AuditLogger {
204204

205205
// spawn the batcher
206206
tokio::spawn(async move {
207-
let mut interval = interval(CONFIG.options.audit_flush_interval);
207+
let mut interval = interval(PARSEABLE.options.audit_flush_interval);
208208
loop {
209209
select! {
210210
_ = interval.tick() => {

0 commit comments

Comments
 (0)