in nfm-controller/src/reports/publisher_endpoint.rs [144:203]
fn publish(&self, report: &NfmReport) -> bool {
let timestamp_ns = timespec_to_nsec(self.clock.now());
let report_body = self.build_report_body(report);
/* ---------- Sigv4 signature ----------------- */
let datetime = chrono::DateTime::from_timestamp_nanos(timestamp_ns as i64);
let mut headers = self.build_headers(datetime);
let rt = tokio::runtime::Runtime::new().unwrap();
let credentials = match rt.block_on(self.credentials_provider.provide_credentials()) {
Ok(credentials) => credentials,
Err(e) => {
error!("Error getting credentials: {}", e);
return false;
}
};
if let Some(token) = credentials.session_token() {
headers.insert("X-Amz-Security-Token", token.parse().unwrap());
}
let aws_sign = aws_sign_v4::AwsSign::new(
"POST",
&self.endpoint,
&datetime,
&headers,
&self.region,
credentials.access_key_id(),
credentials.secret_access_key(),
NFM_SERVICE,
&report_body,
);
let signature = aws_sign.sign();
headers.insert(reqwest::header::AUTHORIZATION, signature.parse().unwrap());
/* ------------ HTTP request --------------------- */
let res = match self
.client
.post(&self.endpoint)
.timeout(Duration::from_secs(20))
.headers(headers.to_owned())
.body(report_body)
.send()
{
Ok(res) => res,
Err(e) => {
error!("Error sending request: {}", e);
return false;
}
};
/* --------- HTTP Response --------------- */
let status = res.status().as_u16();
info!(status = res.status().as_u16(); "HTTP request complete");
if status != 200 {
warn!(body = res.text().unwrap_or("Invalid body".to_string()); "Request body");
return false;
}
true
}