Skip to content

Commit

Permalink
Fix API URL
Browse files Browse the repository at this point in the history
Uses the new API endpoint to update analysis metadata.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho committed Sep 3, 2024
1 parent 83f233b commit ec03396
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lambdas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
38 changes: 37 additions & 1 deletion lambdas/src/bna-fargate-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn function_handler(event: LambdaEvent<TaskInput>) -> Result<TaskOutput, E
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()
Expand Down Expand Up @@ -170,8 +170,12 @@ async fn main() -> Result<(), Error> {
e
})
}

#[cfg(test)]
mod tests {
use bnalambdas::AuthResponse;
use uuid::Uuid;

use super::*;

#[test]
Expand Down Expand Up @@ -208,4 +212,36 @@ mod tests {
}"#;
let _deserialized = serde_json::from_str::<TaskInput>(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);
}
}
3 changes: 2 additions & 1 deletion lambdas/src/bna-save-results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -218,7 +219,7 @@ async fn function_handler(event: LambdaEvent<TaskInput>) -> 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()
Expand Down
2 changes: 1 addition & 1 deletion lambdas/src/bna-setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn function_handler(event: LambdaEvent<TaskInput>) -> Result<TaskOutput, E
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.
info!("Authenticating service account...");
Expand Down
2 changes: 1 addition & 1 deletion lambdas/src/bna-teardown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn function_handler(event: LambdaEvent<TaskInput>) -> 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()
Expand Down
2 changes: 1 addition & 1 deletion lambdas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub struct BNAPipeline {
pub fargate_task_arn: Option<String>,
pub result_posted: Option<bool>,
pub s3_bucket: Option<String>,
pub status: Option<String>,
pub sqs_message: Option<String>,
pub start_time: OffsetDateTime,
pub state_machine_id: Uuid,
pub status: Option<String>,
pub step: Option<String>,
pub torn_down: Option<bool>,
}
Expand Down

0 comments on commit ec03396

Please sign in to comment.