Skip to content

Commit d48ab36

Browse files
committed
use type String for alias_id
1 parent 1b9eb6a commit d48ab36

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/app_guard_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct AppGuardImpl {
4040
ip_info_handler: IpInfoHandler,
4141
tx_store: UnboundedSender<DbEntry>,
4242
ctx: AppContext,
43-
quarantine_alias_id: u64,
43+
quarantine_alias_id: String,
4444
// tx_ai: Sender<AiEntry>,
4545
}
4646

@@ -204,7 +204,7 @@ impl AppGuardImpl {
204204
};
205205
self.tx_store
206206
.send(DbEntry::DeniedIp((
207-
self.quarantine_alias_id,
207+
self.quarantine_alias_id.clone(),
208208
denied_ip,
209209
token.to_string(),
210210
)))

src/db/datastore_wrapper.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ impl DatastoreWrapper {
11601160
Ok(ret_val)
11611161
}
11621162

1163-
pub(crate) async fn upsert_quarantine_alias(&mut self, token: &str) -> Result<u64, Error> {
1163+
pub(crate) async fn upsert_quarantine_alias(&mut self, token: &str) -> Result<String, Error> {
11641164
let record = json!(
11651165
{
11661166
"type": "host",
@@ -1176,7 +1176,7 @@ impl DatastoreWrapper {
11761176
params: Some(Params {
11771177
id: String::new(),
11781178
table: table.into(),
1179-
r#type: String::new(),
1179+
r#type: String::from("root"),
11801180
}),
11811181
query: Some(Query {
11821182
pluck: String::from("id"),
@@ -1196,7 +1196,7 @@ impl DatastoreWrapper {
11961196
Ok(id)
11971197
}
11981198

1199-
fn internal_upsert_quarantine_alias_parse_response_data(data: String) -> Result<u64, Error> {
1199+
fn internal_upsert_quarantine_alias_parse_response_data(data: String) -> Result<String, Error> {
12001200
let array_val = serde_json::from_str::<serde_json::Value>(&data).handle_err(location!())?;
12011201
let array = array_val
12021202
.as_array()
@@ -1214,9 +1214,10 @@ impl DatastoreWrapper {
12141214
.handle_err(location!())?;
12151215
let id = map
12161216
.get("id")
1217-
.and_then(serde_json::Value::as_u64)
1217+
.and_then(serde_json::Value::as_str)
12181218
.ok_or("Invalid data")
1219-
.handle_err(location!())?;
1219+
.handle_err(location!())?
1220+
.to_string();
12201221

12211222
Ok(id)
12221223
}

src/db/entries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum DbEntry {
2121
TcpConnection((AppGuardTcpConnection, u64)),
2222
// Blacklist((Vec<String>, String)),
2323
Firewall((String, Firewall, String)),
24-
DeniedIp((u64, DeniedIp, String)),
24+
DeniedIp((String, DeniedIp, String)),
2525
Config((Config, String)),
2626
}
2727

@@ -101,7 +101,7 @@ impl DbEntry {
101101
// }
102102
DbEntry::Firewall((app_id, f, _)) => f.to_json(app_id),
103103
DbEntry::DeniedIp((quarantine_alias_id, denied_ip, _)) => {
104-
denied_ip.to_json(*quarantine_alias_id)
104+
denied_ip.to_json(quarantine_alias_id)
105105
}
106106
DbEntry::Config((configs, _)) => serde_json::to_string(configs).handle_err(location!()),
107107
}

src/db/store/denied_ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use nullnet_liberror::Error;
33
use serde_json::json;
44

55
impl DeniedIp {
6-
pub(crate) fn to_json(&self, quarantine_alias_id: u64) -> Result<String, Error> {
6+
pub(crate) fn to_json(&self, quarantine_alias_id: &str) -> Result<String, Error> {
77
// a denied IP is always a single IP and (not a subnet)
88
let prefix = if self.ip.is_ipv4() { 32 } else { 128 };
99
Ok(json!({

0 commit comments

Comments
 (0)