Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Commit 3f079df

Browse files
committed
feat: switch to testbed product gw tags when referencing to runtime stages
1 parent ec8dfd0 commit 3f079df

7 files changed

Lines changed: 73 additions & 36 deletions

File tree

.env

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
USER_PROFILE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lassipatanen/User/Profile?source=access_to_finland"
2-
USER_STATUS_INFO_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lsipii/User/StatusInfo?source=access_to_finland:vfd"
3-
USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo/Write?source=access_to_finland:vfd"
4-
POPULATION_FIGURE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lsipii/Figure/Population?source=virtual_finland"
5-
JOB_POSTING_PRODUCTIZER_ENDPOINTS = "https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=tyomarkkinatori, https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=jobs_in_finland"
6-
JMF_SKILL_RECOMMENDATIONS_ENDPOINT = "https://tyomarkkinatori.fi/hakupalvelu/api/1.0/skillrecommendation/skillrecommendation/"
71
TESTBED_BASE_URL = "https://gateway.testbed.fi"
82
TESTBED_ENVIRONMENT = "development"
3+
4+
POPULATION_FIGURE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lsipii/Figure/Population?source=virtual_finland"
5+
JOB_POSTING_PRODUCTIZER_ENDPOINTS = "https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=tyomarkkinatori, https://gateway.testbed.fi/test/lassipatanen/Job/JobPosting?source=jobs_in_finland"
6+
JMF_SKILL_RECOMMENDATIONS_ENDPOINT = "https://tyomarkkinatori.fi/hakupalvelu/api/1.0/skillrecommendation/skillrecommendation/"

.env.local

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
USER_PROFILE_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5001/productizer/test/lassipatanen/User/Profile
2-
USER_STATUS_INFO_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5747/productizers/test/lsipii/User/StatusInfo
3-
USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5747/productizers/test/lsipii/User/StatusInfo/Write
1+
# @TODO: needs a local testbed product gw router sim
2+
USER_PROFILE_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5001/productizer
3+
USER_STATUS_INFO_PRODUCTIZER_ENDPOINT=http://host.docker.internal:5747/productizers
4+
5+
# All good for these endpoints
46
USERS_API_ENDPOINT_ORIGIN=http://host.docker.internal:5001
57
AUTHENTICATION_GW_ENDPOINT_ORIGIN=https://virtualfinland-authgw.localhost
68
TMT_PRODUCTIZER_ENDPOINT_ORIGIN=http://host.docker.internal:5286

.env.staging

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
USER_PROFILE_PRODUCTIZER_ENDPOINT = "https://gateway.testbed.fi/test/lassipatanen/User/Profile?source=access_to_finland__staging"
2-
USER_STATUS_INFO_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo?source=access_to_finland__staging:vfd"
3-
USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT="https://gateway.testbed.fi/test/lsipii/User/StatusInfo/Write?source=access_to_finland__staging:vfd"
41
TESTBED_ENVIRONMENT = "staging"

src/lib/api_app/src/api/routes/testbed/productizers/mod.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::env;
2+
13
use http::{ HeaderMap, HeaderValue };
24

3-
use crate::api::{ responses::APIRoutingError, utils::ParsedRequest };
5+
use crate::api::{ responses::{ APIRoutingError }, utils::{ ParsedRequest, get_stage } };
46

57
pub mod figure;
68
pub mod job;
@@ -35,3 +37,46 @@ fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, AP
3537
}
3638
Ok(request_headers)
3739
}
40+
41+
/**
42+
* Builds the URI for the testbed data product
43+
*/
44+
fn build_data_product_uri(data_product: &str, data_source: &str) -> String {
45+
let mut testbed_base_url = env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set");
46+
let testbed_environment = env
47+
::var("TESTBED_ENVIRONMENT")
48+
.expect("TESTBED_ENVIRONMENT must be set");
49+
50+
if get_stage() == "local" {
51+
// @TODO: needs a local testbed data product gw simulation
52+
match data_product {
53+
"test/lassipatanen/User/Profile" => {
54+
testbed_base_url = env
55+
::var("USER_PROFILE_PRODUCTIZER_ENDPOINT")
56+
.expect("USER_PROFILE_PRODUCTIZER_ENDPOINT must be set");
57+
}
58+
"test/lsipii/User/StatusInfo" => {
59+
testbed_base_url = env
60+
::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
61+
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
62+
}
63+
"test/lsipii/User/StatusInfo/Write" => {
64+
testbed_base_url = env
65+
::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
66+
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
67+
}
68+
_ => {
69+
testbed_base_url = env
70+
::var("TESTBED_BASE_URL")
71+
.expect("TESTBED_BASE_URL must be set");
72+
}
73+
}
74+
}
75+
76+
// Remove trailing slash from base url
77+
if testbed_base_url.ends_with("/") {
78+
testbed_base_url.pop();
79+
}
80+
81+
format!("{testbed_base_url}/{data_product}?source={data_source}:{testbed_environment}")
82+
}

src/lib/api_app/src/api/routes/testbed/productizers/person/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::env;
2-
31
use serde_json::{json, Value as JSONValue};
42

53
use crate::{
@@ -10,18 +8,11 @@ use crate::{
108
}
119
};
1210

13-
use super::parse_testbed_request_headers;
11+
use super::{parse_testbed_request_headers, build_data_product_uri};
1412

1513
pub mod basic_information;
1614
pub mod job_applicant_profile;
1715

18-
fn build_data_product_uri(data_product: &str, data_source: &str) -> String {
19-
let testbed_base_url = env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set");
20-
let testbed_environment = env::var("TESTBED_ENVIRONMENT").expect("TESTBED_ENVIRONMENT must be set");
21-
let formatted_path = format!("{testbed_base_url}/{data_product}?source={data_source}:{testbed_environment}");
22-
formatted_path
23-
}
24-
2516
pub async fn get_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
2617
let request_input = json!({});
2718
let request_headers = parse_testbed_request_headers(request)?;

src/lib/api_app/src/api/routes/testbed/productizers/user/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
use std::env;
2-
31
use serde_json::{ Value as JSONValue, json };
42

53
use crate::api::{
64
responses::{ APIRoutingError, APIRoutingResponse },
75
requests::post_json_request,
86
utils::ParsedRequest,
97
};
10-
use super::parse_testbed_request_headers;
8+
use super::{ parse_testbed_request_headers, build_data_product_uri };
119

1210
pub async fn fetch_user_profile(
1311
request: ParsedRequest
1412
) -> Result<APIRoutingResponse, APIRoutingError> {
15-
let endpoint_url = env
16-
::var("USER_PROFILE_PRODUCTIZER_ENDPOINT")
17-
.expect("USER_PROFILE_PRODUCTIZER_ENDPOINT must be set");
13+
let endpoint_url = build_data_product_uri(
14+
"test/lassipatanen/User/Profile",
15+
"access_to_finland"
16+
);
1817
let request_input = json!({}); // Empty body
1918
let request_headers = parse_testbed_request_headers(request)?;
2019
let response = post_json_request::<JSONValue, JSONValue>(
21-
endpoint_url.to_string(),
20+
endpoint_url,
2221
&request_input,
2322
request_headers
2423
).await?;
@@ -28,9 +27,8 @@ pub async fn fetch_user_profile(
2827
pub async fn fetch_user_status_info(
2928
request: ParsedRequest
3029
) -> Result<APIRoutingResponse, APIRoutingError> {
31-
let endpoint_url = env
32-
::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
33-
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
30+
let endpoint_url = build_data_product_uri("test/lsipii/User/StatusInfo", "virtual_finland");
31+
3432
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or(json!({})); // Pass through body
3533
let request_headers = parse_testbed_request_headers(request)?;
3634
let response = post_json_request::<JSONValue, JSONValue>(
@@ -44,9 +42,11 @@ pub async fn fetch_user_status_info(
4442
pub async fn update_user_status_info(
4543
request: ParsedRequest
4644
) -> Result<APIRoutingResponse, APIRoutingError> {
47-
let endpoint_url = env
48-
::var("USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT")
49-
.expect("USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT must be set");
45+
let endpoint_url = build_data_product_uri(
46+
"test/lsipii/User/StatusInfo/Write",
47+
"virtual_finland"
48+
);
49+
5050
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or(json!({})); // Pass through body
5151
let request_headers = parse_testbed_request_headers(request)?;
5252
let response = post_json_request::<JSONValue, JSONValue>(

src/lib/api_app/src/api/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,8 @@ pub mod strings {
121121
let result: Vec<String> = split.map(|s| s.trim().to_string()).collect();
122122
return result;
123123
}
124+
}
125+
126+
pub fn get_stage() -> String {
127+
std::env::var("STAGE").unwrap_or_else(|_| "local".to_string())
124128
}

0 commit comments

Comments
 (0)