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

Commit 3e95198

Browse files
authored
Merge branch 'main' into feat/automatic-openapi-specs
2 parents 5bbc214 + 326459a commit 3e95198

7 files changed

Lines changed: 76 additions & 54 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use http::{HeaderMap, HeaderValue};
2-
3-
use crate::api::{responses::APIRoutingError, utils::ParsedRequest};
1+
use std::env;
2+
use http::{ HeaderMap, HeaderValue };
3+
use crate::api::{ responses::{ APIRoutingError }, utils::{ ParsedRequest, get_stage } };
44

55
pub mod figure;
66
pub mod job;
@@ -19,10 +19,10 @@ fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, AP
1919
request
2020
.headers
2121
.get("authorization")
22-
.ok_or_else(|| {
22+
.ok_or_else(||
2323
APIRoutingError::UnprocessableEntity("No authorization header".to_string())
24-
})?
25-
.clone(),
24+
)?
25+
.clone()
2626
);
2727

2828
if request.headers.contains_key("x-consent-token") {
@@ -41,3 +41,42 @@ fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, AP
4141
}
4242
Ok(request_headers)
4343
}
44+
45+
/**
46+
* Builds the URI for the testbed data product
47+
*/
48+
fn build_data_product_uri(data_product: &str, data_source: &str) -> String {
49+
let mut testbed_base_url = env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set");
50+
let testbed_environment = env
51+
::var("TESTBED_ENVIRONMENT")
52+
.expect("TESTBED_ENVIRONMENT must be set");
53+
54+
if get_stage() == "local" {
55+
// @TODO: needs a local testbed data product gw simulation
56+
match data_product {
57+
"test/lassipatanen/User/Profile" => {
58+
testbed_base_url = env
59+
::var("USER_PROFILE_PRODUCTIZER_ENDPOINT")
60+
.expect("USER_PROFILE_PRODUCTIZER_ENDPOINT must be set");
61+
}
62+
"test/lsipii/User/StatusInfo" => {
63+
testbed_base_url = env
64+
::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
65+
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
66+
}
67+
"test/lsipii/User/StatusInfo/Write" => {
68+
testbed_base_url = env
69+
::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
70+
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
71+
}
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: 4 additions & 24 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::api::{
@@ -8,25 +6,12 @@ use crate::api::{
86
utils::ParsedRequest,
97
};
108

11-
use super::parse_testbed_request_headers;
9+
use super::{parse_testbed_request_headers, build_data_product_uri};
1210

1311
pub mod basic_information;
1412
pub mod job_applicant_profile;
1513

16-
fn build_data_product_uri(data_product: &str, data_source: &str) -> String {
17-
let testbed_base_url = env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set");
18-
let testbed_environment =
19-
env::var("TESTBED_ENVIRONMENT").expect("TESTBED_ENVIRONMENT must be set");
20-
let formatted_path =
21-
format!("{testbed_base_url}/{data_product}?source={data_source}:{testbed_environment}");
22-
formatted_path
23-
}
24-
25-
pub async fn get_data_product(
26-
data_product: &str,
27-
data_source: &str,
28-
request: ParsedRequest,
29-
) -> Result<APIRoutingResponse, APIRoutingError> {
14+
pub async fn get_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
3015
let request_input = json!({});
3116
let request_headers = parse_testbed_request_headers(request)?;
3217
let response = post_json_request::<JSONValue, JSONValue>(
@@ -38,13 +23,8 @@ pub async fn get_data_product(
3823
Ok(response)
3924
}
4025

41-
pub async fn write_data_product(
42-
data_product: &str,
43-
data_source: &str,
44-
request: ParsedRequest,
45-
) -> Result<APIRoutingResponse, APIRoutingError> {
46-
let request_input: JSONValue =
47-
serde_json::from_str(request.body.as_str()).unwrap_or(json!({}));
26+
pub async fn write_data_product(data_product: &str, data_source: &str, request: ParsedRequest) -> Result<APIRoutingResponse, APIRoutingError> {
27+
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({}));
4828
let request_headers = parse_testbed_request_headers(request)?;
4929
let response = post_json_request::<JSONValue, JSONValue>(
5030
build_data_product_uri(data_product, data_source),

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
32
use serde_json::{json, Value as JSONValue};
43

54
use super::parse_testbed_request_headers;
@@ -8,6 +7,7 @@ use crate::api::{
87
responses::{APIRoutingError, APIRoutingResponse},
98
utils::ParsedRequest,
109
};
10+
use super::{ parse_testbed_request_headers, build_data_product_uri };
1111

1212
#[utoipa::path(
1313
post,
@@ -35,12 +35,14 @@ use crate::api::{
3535
pub async fn fetch_user_profile(
3636
request: ParsedRequest,
3737
) -> Result<APIRoutingResponse, APIRoutingError> {
38-
let endpoint_url = env::var("USER_PROFILE_PRODUCTIZER_ENDPOINT")
39-
.expect("USER_PROFILE_PRODUCTIZER_ENDPOINT must be set");
38+
let endpoint_url = build_data_product_uri(
39+
"test/lassipatanen/User/Profile",
40+
"access_to_finland"
41+
);
4042
let request_input = json!({}); // Empty body
4143
let request_headers = parse_testbed_request_headers(request)?;
4244
let response = post_json_request::<JSONValue, JSONValue>(
43-
endpoint_url.to_string(),
45+
endpoint_url,
4446
&request_input,
4547
request_headers,
4648
)
@@ -74,10 +76,8 @@ pub async fn fetch_user_profile(
7476
pub async fn fetch_user_status_info(
7577
request: ParsedRequest,
7678
) -> Result<APIRoutingResponse, APIRoutingError> {
77-
let endpoint_url = env::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT")
78-
.expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set");
79-
let request_input: JSONValue =
80-
serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
79+
let endpoint_url = build_data_product_uri("test/lsipii/User/StatusInfo", "virtual_finland");
80+
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
8181
let request_headers = parse_testbed_request_headers(request)?;
8282
let response = post_json_request::<JSONValue, JSONValue>(
8383
endpoint_url.to_string(),
@@ -114,10 +114,12 @@ pub async fn fetch_user_status_info(
114114
pub async fn update_user_status_info(
115115
request: ParsedRequest,
116116
) -> Result<APIRoutingResponse, APIRoutingError> {
117-
let endpoint_url = env::var("USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT")
118-
.expect("USER_STATUS_INFO_WRITE_PRODUCTIZER_ENDPOINT must be set");
119-
let request_input: JSONValue =
120-
serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
117+
let endpoint_url = build_data_product_uri(
118+
"test/lsipii/User/StatusInfo/Write",
119+
"virtual_finland"
120+
);
121+
122+
let request_input: JSONValue = serde_json::from_str(request.body.as_str()).unwrap_or_else(|_| json!({})); // Pass through body
121123
let request_headers = parse_testbed_request_headers(request)?;
122124
let response = post_json_request::<JSONValue, JSONValue>(
123125
endpoint_url.to_string(),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ pub mod strings {
123123
result
124124
}
125125
}
126+
127+
pub fn get_stage() -> String {
128+
std::env::var("STAGE").unwrap_or_else(|_| "local".to_string())
129+
}

0 commit comments

Comments
 (0)