Skip to content

Commit

Permalink
Merge pull request #83 from Telecominfraproject/fix/fix_state_serial
Browse files Browse the repository at this point in the history
AP Parser: fetch serial both from state:params:serial and state:serial
  • Loading branch information
Cahb authored Sep 20, 2024
2 parents 0188f26 + a2b7543 commit 1026a2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/cgw_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ pub async fn cgw_tls_read_certs(cert_file: &str) -> Result<Vec<CertificateDer<'s
file.read(&mut buffer).expect("buffer overflow");
let decoded_buffer = {
if let Ok(d) = BASE64_STANDARD.decode(buffer.clone()) {
info!("Cert file {} is base64 encoded, trying to use decoded.",
cert_file);
info!(
"Cert file {} is base64 encoded, trying to use decoded.",
cert_file
);
d
} else {
buffer
Expand Down Expand Up @@ -67,11 +69,13 @@ pub async fn cgw_tls_read_private_key(private_key_file: &str) -> Result<PrivateK
let decoded_buffer = {
match BASE64_STANDARD.decode(buffer.clone()) {
Err(e) => info!("err {e}"),
Ok(_) => ()
Ok(_) => (),
}
if let Ok(d) = BASE64_STANDARD.decode(buffer.clone()) {
info!("Private key file {} is base64 encoded, trying to use decoded.",
private_key_file);
info!(
"Private key file {} is base64 encoded, trying to use decoded.",
private_key_file
);
d
} else {
buffer
Expand Down
25 changes: 20 additions & 5 deletions src/cgw_ucentral_ap_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,26 @@ fn parse_state_event_data(
"Parsed, decompressed state message but failed to find state object",
));
} else if let Value::Object(state_map) = &params["state"] {
let serial = MacAddress::from_str(
params["serial"]
.as_str()
.ok_or_else(|| Error::UCentralParser("Failed to parse mac address"))?,
)?;
let serial = {
if let Value::String(_) = &params["serial"] {
MacAddress::from_str(
params["serial"]
.as_str()
.ok_or_else(|| Error::UCentralParser("Failed to parse mac address"))?,
)?
} else if let Value::String(_) = &state_map["serial"] {
MacAddress::from_str(
state_map["serial"]
.as_str()
.ok_or_else(|| Error::UCentralParser("Failed to parse mac address"))?,
)?
} else {
return Err(Error::UCentralParser(
"Failed to parse state: mac address is missing",
));
}
};

let mut lldp_links: HashMap<CGWUCentralEventStatePort, Vec<CGWUCentralEventStateLinks>> =
HashMap::new();
let mut clients_links: HashMap<
Expand Down

0 comments on commit 1026a2a

Please sign in to comment.