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

Commit 326459a

Browse files
authored
Merge pull request #24 from Virtual-Finland-Development/feat/use-testbed-gw-tags-as-stages
feat: switch to testbed product gw tags when referencing to runtime stages
2 parents 925ee7b + fb501cd commit 326459a

7 files changed

Lines changed: 72 additions & 38 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: 45 additions & 2 deletions
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;
@@ -18,7 +20,9 @@ fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, AP
1820
"authorization",
1921
request.headers
2022
.get("authorization")
21-
.ok_or_else(|| APIRoutingError::UnprocessableEntity("No authorization header".to_string()))?
23+
.ok_or_else(||
24+
APIRoutingError::UnprocessableEntity("No authorization header".to_string())
25+
)?
2226
.clone()
2327
);
2428

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

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

Lines changed: 2 additions & 11 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)?;
@@ -34,7 +25,7 @@ pub async fn get_data_product(data_product: &str, data_source: &str, request: Pa
3425
}
3526

3627
pub async fn write_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
37-
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or(json!({}));
28+
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({}));
3829
let request_headers = parse_testbed_request_headers(request)?;
3930
let response = post_json_request::<JSONValue, JSONValue>(
4031
build_data_product_uri(data_product, data_source),

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

Lines changed: 12 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,7 @@ 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");
3431
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
3532
let request_headers = parse_testbed_request_headers(request)?;
3633
let response = post_json_request::<JSONValue, JSONValue>(
@@ -44,9 +41,11 @@ pub async fn fetch_user_status_info(
4441
pub async fn update_user_status_info(
4542
request: ParsedRequest
4643
) -> 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");
44+
let endpoint_url = build_data_product_uri(
45+
"test/lsipii/User/StatusInfo/Write",
46+
"virtual_finland"
47+
);
48+
5049
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
5150
let request_headers = parse_testbed_request_headers(request)?;
5251
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
@@ -119,4 +119,8 @@ pub mod strings {
119119
let result: Vec<String> = split.map(|s| s.trim().to_string()).collect();
120120
result
121121
}
122+
}
123+
124+
pub fn get_stage() -> String {
125+
std::env::var("STAGE").unwrap_or_else(|_| "local".to_string())
122126
}

0 commit comments

Comments
 (0)