Skip to content

Commit 3fc14ab

Browse files
[#149]: updated address parsing in map handlers
1 parent 350d8fb commit 3fc14ab

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

core/src/components/identity/src/map_handlers.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use anyhow::Error;
22
use anyhow::Ok;
33
use aya::Bpf;
4+
use aya::maps::HashMap;
45
use aya::maps::Map;
6+
use k8s_openapi::api::core::v1::ConfigMap;
7+
use kube::{Api, Client};
58
use std::net::Ipv4Addr;
69
use std::path::PathBuf;
710
use std::str::FromStr;
811
use std::sync::Arc;
912
use std::sync::Mutex;
1013
use tokio::fs;
1114
use tracing::{error, info};
12-
use aya::maps::HashMap;
13-
use k8s_openapi::api::core::v1::ConfigMap;
14-
use kube::{Api, Client};
1515

1616
pub fn init_bpf_maps(bpf: Arc<Mutex<Bpf>>) -> Result<(Map, Map, Map), anyhow::Error> {
1717
// this function init the bpfs maps used in the main program
@@ -81,19 +81,16 @@ pub async fn populate_blocklist(map: &mut Map) -> Result<(), Error> {
8181
info!("[CONFIGMAP]: {:?} ", configs);
8282
if let Some(data) = configs.data {
8383
if let Some(blocklist) = data.get("blocklist") {
84-
match serde_yaml::from_str::<Vec<String>>(&blocklist) {
85-
std::result::Result::Ok(addresses) => {
86-
info!("Inserting addresses: {:?}", addresses);
87-
88-
for item in addresses{
89-
let addr = Ipv4Addr::from_str(&item)?.octets();
90-
let _ = blocklist_map.insert(addr,addr,0);
91-
}
92-
93-
}
94-
std::result::Result::Err(e) => {
95-
error!("Error during blocklist addresses import: {}", e);
96-
}
84+
let addresses: Vec<String> = blocklist
85+
.lines()
86+
.map(|s| s.trim().to_string())
87+
.filter(|s| !s.is_empty())
88+
.collect();
89+
//String parsing from "x y" to ["x","y"]
90+
info!("Inserting addresses: {:?}", addresses);
91+
for item in addresses {
92+
let addr = Ipv4Addr::from_str(&item)?.octets();
93+
let _ = blocklist_map.insert(addr, addr, 0);
9794
}
9895
}
9996
}

0 commit comments

Comments
 (0)