From 683a98256a1dee5ab5889b197f8c123b0602ebff Mon Sep 17 00:00:00 2001 From: Lassi Piironen Date: Mon, 9 Jan 2023 13:16:32 +0200 Subject: [PATCH 1/4] feat: add x-consent-token as known header --- src/lib/api_app/src/api/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/api_app/src/api/utils.rs b/src/lib/api_app/src/api/utils.rs index e92ef7a..60e15b7 100644 --- a/src/lib/api_app/src/api/utils.rs +++ b/src/lib/api_app/src/api/utils.rs @@ -54,7 +54,7 @@ pub fn get_cors_response_headers() -> HeaderMap { headers.insert( HeaderName::from_static("access-control-allow-headers"), HeaderValue::from_static( - "content-type, authorization, x-authorization-provider, x-authorization-context" + "content-type, authorization, x-authorization-provider, x-authorization-context, x-consent-token" ) ); From c4804d4beec10d04034c17ca541103feeed6a836 Mon Sep 17 00:00:00 2001 From: Lassi Piironen Date: Mon, 9 Jan 2023 13:16:48 +0200 Subject: [PATCH 2/4] fix: add a timeout to the external api requests --- src/lib/api_app/src/api/requests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/api_app/src/api/requests.rs b/src/lib/api_app/src/api/requests.rs index fb1f127..ab6c3f5 100644 --- a/src/lib/api_app/src/api/requests.rs +++ b/src/lib/api_app/src/api/requests.rs @@ -5,6 +5,7 @@ use serde::{ Serialize, Deserialize }; use std::fmt::Debug; use futures::future; use stopwatch::{ Stopwatch }; +use std::time::Duration; use super::{ responses::{ APIRoutingError, APIRoutingResponse, resolve_external_service_bad_response }, @@ -192,6 +193,7 @@ async fn engage_request( let stopwatch = Stopwatch::start_new(); let response = client .request(request_method, endpoint_url) + .timeout(Duration::from_secs(29)) .json(&request_input) .headers(request_headers) .send().await?; From 916de16d1dcc71e7a14bb82641db00d280ab6610 Mon Sep 17 00:00:00 2001 From: Lassi Piironen Date: Mon, 9 Jan 2023 13:22:16 +0200 Subject: [PATCH 3/4] fix: add docker host to the compose file so itll work in linux too --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e990b0c..33cba93 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,5 +17,5 @@ services: - ./:/builder ports: - 3003:3003 - stdin_open: true - tty: true + extra_hosts: + - "host.docker.internal:host-gateway" From aabb8d6860af1bb58016de56a7b563933ebcb2bd Mon Sep 17 00:00:00 2001 From: Lassi Piironen Date: Tue, 10 Jan 2023 11:23:42 +0200 Subject: [PATCH 4/4] refactor: rename endpoint reference variable names, add local configuration for local productizers --- .env.local | 5 ++++- infra/main.py | 8 ++++---- src/lib/api_app/src/api/routes/application.rs | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.env.local b/.env.local index ab87471..ef8ddab 100644 --- a/.env.local +++ b/.env.local @@ -1,2 +1,5 @@ USERS_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5001/productizer/test/lassipatanen/User/Profile/ -USERS_API_LAMBDA_ENDPOINT=http://host.docker.internal:5001/ \ No newline at end of file +USERS_API_ENDPOINT_ORIGIN=http://host.docker.internal:5001 +AUTHENTICATION_GW_ENDPOINT_ORIGIN=https://virtualfinland-authgw.localhost +TMT_PRODUCTIZER_ENDPOINT_ORIGIN=http://host.docker.internal:5286 +JOBS_IN_FINLAND_PRODUCTIZER_ENDPOINT_ORIGIN=http://host.docker.internal:80 \ No newline at end of file diff --git a/infra/main.py b/infra/main.py index 008bd8f..4713b89 100644 --- a/infra/main.py +++ b/infra/main.py @@ -83,10 +83,10 @@ variables={ "LOGGING_LEVEL": "info", **utils.get_dotenv_configuration(stage), # type: ignore - "AUTHENTICATION_GW_LAMBDA_ENDPOINT": authenticationGWLambdaEndpoint, - "USERS_API_LAMBDA_ENDPOINT": usersApiLambdaEndpoint, - "TMT_PRODUCTIZER_LAMBDA_ENDPOINT": tmtProductizerLambdaEndpoint, - "JOBS_IN_FINLAND_PRODUCTIZER_LAMBDA_ENDPOINT": jobsInFinlandProductizerLambdaEndpoint, + "AUTHENTICATION_GW_ENDPOINT_ORIGIN": authenticationGWLambdaEndpoint, + "USERS_API_ENDPOINT_ORIGIN": usersApiLambdaEndpoint, + "TMT_PRODUCTIZER_ENDPOINT_ORIGIN": tmtProductizerLambdaEndpoint, + "JOBS_IN_FINLAND_PRODUCTIZER_ENDPOINT_ORIGIN": jobsInFinlandProductizerLambdaEndpoint, } ), ) diff --git a/src/lib/api_app/src/api/routes/application.rs b/src/lib/api_app/src/api/routes/application.rs index 6684b27..7fca43c 100644 --- a/src/lib/api_app/src/api/routes/application.rs +++ b/src/lib/api_app/src/api/routes/application.rs @@ -75,12 +75,12 @@ pub async fn wake_up_external_services( _request: ParsedRequest ) -> Result { let endpoints = vec![ - format!("{}/health", env::var("AUTHENTICATION_GW_LAMBDA_ENDPOINT").unwrap_or_default()), - format!("{}", env::var("USERS_API_LAMBDA_ENDPOINT").unwrap_or_default()), - format!("{}/wake-up", env::var("TMT_PRODUCTIZER_LAMBDA_ENDPOINT").unwrap_or_default()), + format!("{}/health", env::var("AUTHENTICATION_GW_ENDPOINT_ORIGIN").unwrap_or_default()), + format!("{}", env::var("USERS_API_ENDPOINT_ORIGIN").unwrap_or_default()), + format!("{}/wake-up", env::var("TMT_PRODUCTIZER_ENDPOINT_ORIGIN").unwrap_or_default()), format!( "{}/wake-up", - env::var("JOBS_IN_FINLAND_PRODUCTIZER_LAMBDA_ENDPOINT").unwrap_or_default() + env::var("JOBS_IN_FINLAND_PRODUCTIZER_ENDPOINT_ORIGIN").unwrap_or_default() ) ]; let total_endpoints = endpoints.len();