|
1 | | -use http::{HeaderMap, HeaderValue}; |
2 | | -use std::env; |
3 | | - |
4 | | -use app::{responses::APIRoutingError, router::ParsedRequest}; |
5 | | -use utils::environment::get_stage; |
6 | | - |
7 | 1 | pub mod figure; |
8 | 2 | pub mod job; |
9 | 3 | pub mod nsg; |
10 | 4 | pub mod person; |
11 | 5 | pub mod user; |
12 | | - |
13 | | -/** |
14 | | - * Parses the authorization headers from the input request |
15 | | - */ |
16 | | -fn parse_testbed_request_headers(request: ParsedRequest) -> Result<HeaderMap, APIRoutingError> { |
17 | | - // Prep auth header forwarding |
18 | | - let mut request_headers = HeaderMap::new(); |
19 | | - request_headers.insert("Content-Type", HeaderValue::from_static("application/json")); |
20 | | - request_headers.insert( |
21 | | - "authorization", |
22 | | - request |
23 | | - .headers |
24 | | - .get("authorization") |
25 | | - .ok_or_else(|| { |
26 | | - APIRoutingError::UnprocessableEntity("No authorization header".to_string()) |
27 | | - })? |
28 | | - .clone(), |
29 | | - ); |
30 | | - |
31 | | - if request.headers.contains_key("x-consent-token") { |
32 | | - request_headers.insert( |
33 | | - "x-consent-token", |
34 | | - request |
35 | | - .headers |
36 | | - .get("x-consent-token") |
37 | | - .ok_or_else(|| { |
38 | | - APIRoutingError::UnprocessableEntity( |
39 | | - "No x-consent-token header".to_string(), |
40 | | - ) |
41 | | - })? |
42 | | - .clone(), |
43 | | - ); |
44 | | - } |
45 | | - Ok(request_headers) |
46 | | -} |
47 | | - |
48 | | -/** |
49 | | - * Builds the URI for the testbed data product |
50 | | - */ |
51 | | -fn build_data_product_stage_uri(data_product: &str, data_source: &str) -> String { |
52 | | - let testbed_environment = |
53 | | - env::var("TESTBED_ENVIRONMENT").expect("TESTBED_ENVIRONMENT must be set"); |
54 | | - build_data_product_uri( |
55 | | - data_product, |
56 | | - format!("{data_source}:{testbed_environment}").as_str(), |
57 | | - ) |
58 | | -} |
59 | | - |
60 | | -fn build_data_product_uri(data_product: &str, data_source: &str) -> String { |
61 | | - let mut testbed_base_url = |
62 | | - env::var("TESTBED_BASE_URL").expect("TESTBED_BASE_URL must be set"); |
63 | | - |
64 | | - if get_stage() == "local" { |
65 | | - // @TODO: needs a local testbed data product gw simulation |
66 | | - match data_product { |
67 | | - "test/lassipatanen/User/Profile" => { |
68 | | - testbed_base_url = env::var("USER_PROFILE_PRODUCTIZER_ENDPOINT") |
69 | | - .expect("USER_PROFILE_PRODUCTIZER_ENDPOINT must be set"); |
70 | | - } |
71 | | - "test/lsipii/User/StatusInfo" => { |
72 | | - testbed_base_url = env::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT") |
73 | | - .expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set"); |
74 | | - } |
75 | | - "test/lsipii/User/StatusInfo/Write" => { |
76 | | - testbed_base_url = env::var("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT") |
77 | | - .expect("USER_STATUS_INFO_PRODUCTIZER_ENDPOINT must be set"); |
78 | | - } |
79 | | - "draft/NSG/Agent/LegalEntity/NonListedCompany/Establishment/Write" => { |
80 | | - testbed_base_url = env::var("PRH_MOCK_PRODUCTIZER_ENDPOINT") |
81 | | - .expect("PRH_MOCK_PRODUCTIZER_ENDPOINT must be set"); |
82 | | - } |
83 | | - "draft/NSG/Agent/LegalEntity/NonListedCompany/BeneficialOwners" => { |
84 | | - testbed_base_url = env::var("PRH_MOCK_PRODUCTIZER_ENDPOINT") |
85 | | - .expect("PRH_MOCK_PRODUCTIZER_ENDPOINT must be set"); |
86 | | - } |
87 | | - "draft/NSG/Agent/LegalEntity/NonListedCompany/SignatoryRights" => { |
88 | | - testbed_base_url = env::var("PRH_MOCK_PRODUCTIZER_ENDPOINT") |
89 | | - .expect("PRH_MOCK_PRODUCTIZER_ENDPOINT must be set"); |
90 | | - } |
91 | | - "draft/NSG/Agent/BasicInformation" => { |
92 | | - if data_source.starts_with("virtualfinland") { |
93 | | - testbed_base_url = env::var("PRH_MOCK_PRODUCTIZER_ENDPOINT") |
94 | | - .expect("PRH_MOCK_PRODUCTIZER_ENDPOINT must be set"); |
95 | | - } |
96 | | - } |
97 | | - _ => {} |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - // Remove trailing slash from base url |
102 | | - if testbed_base_url.ends_with('/') { |
103 | | - testbed_base_url.pop(); |
104 | | - } |
105 | | - |
106 | | - format!("{testbed_base_url}/{data_product}?source={data_source}") |
107 | | -} |
0 commit comments