From ec03396e4574f287187b998f45a79b963e49bf38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Mon, 2 Sep 2024 17:04:31 -0500 Subject: [PATCH] Fix API URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses the new API endpoint to update analysis metadata. Signed-off-by: Rémy Greinhofer --- Cargo.toml | 1 + lambdas/Cargo.toml | 1 + lambdas/src/bna-fargate-run.rs | 38 ++++++++++++++++++++++++++++++++- lambdas/src/bna-save-results.rs | 3 ++- lambdas/src/bna-setup.rs | 2 +- lambdas/src/bna-teardown.rs | 2 +- lambdas/src/lib.rs | 2 +- 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3cd2401..dedfd3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ color-eyre = "0.6.2" csv = "1.1" dotenv = "0.15.0" fontdb = "0.20.0" +heck = "0.5.0" http = "1.0.0" image = "0.25.0" lambda_http = "0.12.0" diff --git a/lambdas/Cargo.toml b/lambdas/Cargo.toml index fb1d765..6a644d0 100644 --- a/lambdas/Cargo.toml +++ b/lambdas/Cargo.toml @@ -13,6 +13,7 @@ aws_lambda_events = { workspace = true } bnacore = { path = "../bnacore" } csv = { workspace = true } fontdb = { workspace = true } +heck = { workspace = true } image = { workspace = true } lambda_http = { workspace = true } lambda_runtime = { workspace = true } diff --git a/lambdas/src/bna-fargate-run.rs b/lambdas/src/bna-fargate-run.rs index 91ba7c5..1fb186c 100644 --- a/lambdas/src/bna-fargate-run.rs +++ b/lambdas/src/bna-fargate-run.rs @@ -35,7 +35,7 @@ async fn function_handler(event: LambdaEvent) -> Result Result<(), Error> { e }) } + #[cfg(test)] mod tests { + use bnalambdas::AuthResponse; + use uuid::Uuid; + use super::*; #[test] @@ -208,4 +212,36 @@ mod tests { }"#; let _deserialized = serde_json::from_str::(json_input).unwrap(); } + + #[tokio::test] + async fn test_create_pipeline() { + let auth = AuthResponse { + access_token: String::from(""), + expires_in: 3600, + token_type: String::from("Bearer"), + }; + + // Prepare the API URL. + let url = format!("https://api.peopleforbikes.xyz/ratings/analysis"); + + // Prepare the payload. + let pipeline = BNAPipeline { + state_machine_id: Uuid::parse_str("fc009967-c4d0-416b-baee-93708ac80cbc").unwrap(), + step: Some("Analysis".to_string()), + sqs_message: Some(serde_json::to_string(r#"{"analysis_parameters": "test"}"#).unwrap()), + ..Default::default() + }; + dbg!(&pipeline); + dbg!(serde_json::to_string(&pipeline).unwrap()); + + // Send the request. + let post = reqwest::Client::new() + .post(&url) + .bearer_auth(auth.access_token.clone()) + .json(&pipeline) + .send() + .await; + let p = post; + dbg!(p); + } } diff --git a/lambdas/src/bna-save-results.rs b/lambdas/src/bna-save-results.rs index a80eb5f..875aa47 100644 --- a/lambdas/src/bna-save-results.rs +++ b/lambdas/src/bna-save-results.rs @@ -6,6 +6,7 @@ use bnalambdas::{ Fargate, AWSS3, }; use csv::ReaderBuilder; +use heck::ToTitleCase; use lambda_runtime::{run, service_fn, Error, LambdaEvent}; use reqwest::blocking::Client; use rust_decimal::Decimal; @@ -218,7 +219,7 @@ async fn function_handler(event: LambdaEvent) -> Result<(), Error> { info!("Create a new city..."); // Create the city. let c = City { - country: country.clone(), + country: country.clone().to_title_case(), state: region.clone(), name: name.clone(), ..Default::default() diff --git a/lambdas/src/bna-setup.rs b/lambdas/src/bna-setup.rs index aa4f157..0ac49c3 100644 --- a/lambdas/src/bna-setup.rs +++ b/lambdas/src/bna-setup.rs @@ -34,7 +34,7 @@ async fn function_handler(event: LambdaEvent) -> Result) -> Result<(), Error> { let api_hostname = get_aws_parameter_value("BNA_API_HOSTNAME").await?; // Prepare the API URL. - let url = format!("{api_hostname}/bnas/analysis"); + let url = format!("{api_hostname}/ratings/analysis"); // Authenticate the service account. let auth = authenticate_service_account() diff --git a/lambdas/src/lib.rs b/lambdas/src/lib.rs index 89429e2..ed6b66b 100644 --- a/lambdas/src/lib.rs +++ b/lambdas/src/lib.rs @@ -78,10 +78,10 @@ pub struct BNAPipeline { pub fargate_task_arn: Option, pub result_posted: Option, pub s3_bucket: Option, - pub status: Option, pub sqs_message: Option, pub start_time: OffsetDateTime, pub state_machine_id: Uuid, + pub status: Option, pub step: Option, pub torn_down: Option, }