From 7f7aef72e3314c09d0aae345f4432bcac89e29e9 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:27:30 -0700 Subject: [PATCH 1/9] add uribuilder crate --- .github/workflows/crates.yaml | 6 +- Cargo.toml | 1 + crates/uribuilder/Cargo.toml | 8 +++ crates/uribuilder/src/lib.rs | 131 ++++++++++++++++++++++++++++++++++ project.yaml | 23 +++--- 5 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 crates/uribuilder/Cargo.toml create mode 100644 crates/uribuilder/src/lib.rs diff --git a/.github/workflows/crates.yaml b/.github/workflows/crates.yaml index 54d4b414..25605f86 100644 --- a/.github/workflows/crates.yaml +++ b/.github/workflows/crates.yaml @@ -20,12 +20,12 @@ jobs: - uses: taiki-e/install-action@nextest - name: crates lint run: | - cargo fmt -p pg -p types -p httpclient -- --check - cargo clippy -p pg -p types -p httpclient -- -Dwarnings + cargo fmt -p pg -p types -p httpclient -p uribuilder -- --check + cargo clippy -p pg -p types -p httpclient -p uribuilder -- -Dwarnings - name: install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: crates unit tests - run: cargo test -p pg -p types -p httpclient + run: cargo test -p pg -p types -p httpclient -p uribuilder - name: crates/types coverage report run: | make rust-coverage RUST_PKG=types diff --git a/Cargo.toml b/Cargo.toml index dd81d857..3a0e8f6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "crates/service", "crates/shutdown", "crates/types", + "crates/uribuilder", "crates/wsclient", "services/auto-confirm", "services/balance-by-account", diff --git a/crates/uribuilder/Cargo.toml b/crates/uribuilder/Cargo.toml new file mode 100644 index 00000000..eee114b7 --- /dev/null +++ b/crates/uribuilder/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "uribuilder" +version = "0.1.0" +edition = "2021" +rust-version.workspace = true + +[dependencies] +url = "2.5.3" diff --git a/crates/uribuilder/src/lib.rs b/crates/uribuilder/src/lib.rs new file mode 100644 index 00000000..db4caa28 --- /dev/null +++ b/crates/uribuilder/src/lib.rs @@ -0,0 +1,131 @@ +use std::fmt::{Display, Formatter, Result}; +use url::Url; + +// separate crate from httpclient because it +// creates ws:// uri and doesnt need reqwest + +pub enum Protocol { + Http, + Https, + Ws, +} + +impl Display for Protocol { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + match self { + Protocol::Http => write!(f, "http"), + Protocol::Https => write!(f, "https"), + Protocol::Ws => write!(f, "ws"), + } + } +} + +pub struct Uri(Url); + +impl Uri { + pub fn new(uri: &str) -> Self { + let uri = if !uri.contains("://") { + format!("{}://{}", Protocol::Http, uri) + } else { + uri.to_string() + }; + + let mut url = Url::parse(&uri).unwrap(); + + if std::env::var("ENABLE_TLS").is_ok() && std::env::var("ENABLE_TLS").unwrap() == "true" { + url.set_scheme(Protocol::Https.to_string().as_str()) + .unwrap(); + } + + Self(url) + } + + pub fn new_from_env_var(env_var: &str) -> Self { + let uri = std::env::var(env_var).unwrap(); + Self::new(&uri) + } + + pub fn with_ws(self) -> Self { + let mut url = self.0; + url.set_scheme(Protocol::Ws.to_string().as_str()).unwrap(); + Self(url) + } + + pub fn with_path(self, path: &str) -> Self { + let mut url = self.0; + url.set_path(path); + Self(url) + } +} + +impl Display for Uri { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + write!(f, "{}", self.0) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_scheme_display() { + assert_eq!(Protocol::Http.to_string(), "http"); + assert_eq!(Protocol::Https.to_string(), "https"); + assert_eq!(Protocol::Ws.to_string(), "ws"); + } + + #[test] + fn test_new_default_uri() { + let uri = Uri::new("example.com"); + assert_eq!(uri.to_string(), "http://example.com/"); + } + + #[test] + fn test_new_localhost_uri() { + let uri = Uri::new("localhost:8080"); + assert_eq!(uri.to_string(), "http://localhost:8080/"); + } + + #[test] + fn test_new_https_uri() { + let uri = Uri::new("https://example.com"); + assert_eq!(uri.to_string(), "https://example.com/"); + } + + #[test] + fn test_new_ws_uri() { + let uri = Uri::new("example.com").with_ws(); + assert_eq!(uri.to_string(), "ws://example.com/"); + } + + #[test] + fn test_http_uri_from_env_var() { + std::env::set_var("TEST_URI_1", "http://example.com"); + let uri = Uri::new_from_env_var("TEST_URI_1"); + assert_eq!(uri.to_string(), "http://example.com/"); + std::env::remove_var("TEST_URI_1"); + } + + #[test] + fn test_https_uri_from_env_var() { + std::env::set_var("TEST_URI_2", "https://example.com"); + let uri = Uri::new_from_env_var("TEST_URI_2"); + assert_eq!(uri.to_string(), "https://example.com/"); + std::env::remove_var("TEST_URI_2"); + } + + #[test] + fn test_localhost_uri_from_env_var() { + std::env::set_var("TEST_URI_3", "localhost:8080"); + let uri = Uri::new_from_env_var("TEST_URI_3"); + assert_eq!(uri.to_string(), "http://localhost:8080/"); + std::env::remove_var("TEST_URI_3"); + } + + #[test] + fn test_with_path() { + let uri = Uri::new("example.com").with_path("path/to/resource"); + assert_eq!(uri.to_string(), "http://example.com/path/to/resource"); + } +} diff --git a/project.yaml b/project.yaml index 23aa6214..e7533a34 100644 --- a/project.yaml +++ b/project.yaml @@ -81,6 +81,12 @@ crates: type: lib env_var: null params: [] + uribuilder: + runtime: rust1.x + min_code_cov: 0 + type: lib + env_var: null + params: [] wsclient: runtime: rust1.x min_code_cov: 0 @@ -164,7 +170,7 @@ infra: default: v1 GRAPHQL_URI: ssm: api/graphql/uri - default: null # script sets as localhost:$PORT + default: null # scripts/create-env-file.sh sets as localhost:$PORT GRAPHQL_SUBSCRIPTIONS_URI: ssm: null default: null @@ -435,7 +441,6 @@ services: ssm: null default: 10000 get: - - GRAPHQL_URI - RULE_URL - REQUEST_CREATE_URL - REQUEST_APPROVE_URL @@ -468,7 +473,6 @@ services: default: 10002 get: - READINESS_CHECK_PATH - - REQUEST_CREATE_URL - RULE_URL - REQUEST_CREATE_PORT - PGHOST @@ -494,7 +498,6 @@ services: default: 10003 get: - READINESS_CHECK_PATH - - REQUEST_APPROVE_URL - REQUEST_APPROVE_PORT - PGHOST - PGPORT @@ -538,7 +541,6 @@ services: - CLIENT_ID - POOL_ID - GRAPHQL_URI - - RULE_URL - READINESS_CHECK_PATH - RULE_PORT - HOSTNAME_OR_IP @@ -556,11 +558,10 @@ services: rust_log: off env_var: set: - REQUEST_BY_ID_PORT: - ssm: null - default: 10005 + REQUEST_BY_ID_PORT: + ssm: null + default: 10005 get: - - REQUEST_BY_ID_URL - REQUEST_BY_ID_PORT - PGHOST - PGPORT @@ -584,7 +585,6 @@ services: ssm: null default: 10006 get: - - REQUESTS_BY_ACCOUNT_URL - REQUESTS_BY_ACCOUNT_PORT - PGHOST - PGPORT @@ -609,7 +609,6 @@ services: ssm: null default: 10007 get: - - TRANSACTION_BY_ID_URL - TRANSACTION_BY_ID_PORT - PGHOST - PGPORT @@ -633,7 +632,6 @@ services: ssm: null default: 10008 get: - - TRANSACTIONS_BY_ACCOUNT_URL - TRANSACTIONS_BY_ACCOUNT_PORT - PGHOST - PGPORT @@ -658,7 +656,6 @@ services: ssm: null default: 10004 get: - - BALANCE_BY_ACCOUNT_URL - BALANCE_BY_ACCOUNT_PORT - PGHOST - PGPORT From 870a59e1e6b9b3f2b2785d0f9a870a6525d3347b Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:29:15 -0700 Subject: [PATCH 2/9] set addresses with uribuilder crate --- services/graphql/Cargo.toml | 1 + services/graphql/src/main.rs | 23 ++++---- services/request-create/Cargo.toml | 1 + services/request-create/src/main.rs | 3 +- tests/Cargo.toml | 1 + tests/src/helpers.rs | 3 +- tests/src/requests.rs | 82 ++++++++++++----------------- 7 files changed, 53 insertions(+), 61 deletions(-) diff --git a/services/graphql/Cargo.toml b/services/graphql/Cargo.toml index 9526d6fa..2ee0bcb7 100644 --- a/services/graphql/Cargo.toml +++ b/services/graphql/Cargo.toml @@ -24,6 +24,7 @@ futures-util = "0.3.30" wsclient = { path = "../../crates/wsclient" } tungstenite = { version = "0.24.0", default-features = false } async-stream = "0.3.5" +uribuilder = { path = "../../crates/uribuilder" } [target.x86_64-unknown-linux-musl.dependencies] # https://github.com/cross-rs/cross/wiki/Recipes#vendored diff --git a/services/graphql/src/main.rs b/services/graphql/src/main.rs index 0ac9eb4d..aa55e648 100644 --- a/services/graphql/src/main.rs +++ b/services/graphql/src/main.rs @@ -24,6 +24,7 @@ use std::{env, net::ToSocketAddrs, result::Result}; use tokio::net::TcpListener; use tower_http::cors::CorsLayer; use tungstenite::error::Error as WsError; +use uribuilder::Uri; const READINESS_CHECK_PATH: &str = "READINESS_CHECK_PATH"; const GRAPHQL_RESOURCE: &str = "query"; @@ -40,7 +41,7 @@ impl Query { #[graphql(name = "auth_account")] auth_account: String, ) -> String { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("BALANCE_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("BALANCE_BY_ACCOUNT_URL").to_string(); let body = account_auth(account_name, account_from_token); let client = Client::new(); let response = client.post(uri, body).await.unwrap(); @@ -55,7 +56,7 @@ impl Query { #[graphql(name = "auth_account")] auth_account: String, ) -> Vec { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("TRANSACTIONS_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("TRANSACTIONS_BY_ACCOUNT_URL").to_string(); let body = account_auth(account_name, account_from_token); let client = Client::new(); let response = client.post(uri, body).await.unwrap(); @@ -73,7 +74,7 @@ impl Query { #[graphql(name = "auth_account")] auth_account: String, ) -> Transaction { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("TRANSACTION_BY_ID_URL").unwrap(); + let uri = Uri::new_from_env_var("TRANSACTION_BY_ID_URL").to_string(); let body = id_account_auth(id, account_name, account_from_token); let client = Client::new(); let response = client.post(uri, body).await.unwrap(); @@ -90,7 +91,7 @@ impl Query { #[graphql(name = "auth_account")] auth_account: String, ) -> Vec { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("REQUESTS_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUESTS_BY_ACCOUNT_URL").to_string(); let client = Client::new(); let body = account_auth(account_name, account_from_token); let response = client.post(uri, body).await.unwrap(); @@ -108,7 +109,7 @@ impl Query { #[graphql(name = "auth_account")] auth_account: String, ) -> Transaction { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("REQUEST_BY_ID_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_BY_ID_URL").to_string(); let body = id_account_auth(id, account_name, account_from_token); let client = Client::new(); let response = client.post(uri, body).await.unwrap(); @@ -122,7 +123,7 @@ impl Query { &self, #[graphql(name = "transaction_items")] transaction_items: Vec, ) -> Transaction { - let uri = env::var("RULE_URL").unwrap(); + let uri = Uri::new_from_env_var("RULE_URL").to_string(); let client = Client::new(); let body = json!(transaction_items).to_string(); let response = client.post(uri, body).await.unwrap(); @@ -143,7 +144,7 @@ impl Mutation { #[graphql(name = "auth_account")] auth_account: String, ) -> Transaction { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("REQUEST_CREATE_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_CREATE_URL").to_string(); let client = Client::new(); let request = IntraTransaction::new( account_from_token.clone(), @@ -169,7 +170,7 @@ impl Mutation { #[graphql(name = "auth_account")] auth_account: String, ) -> Transaction { let account_from_token = get_auth_account(ctx, auth_account).unwrap(); - let uri = env::var("REQUEST_APPROVE_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_APPROVE_URL").to_string(); let client = Client::new(); let request = RequestApprove::new( account_from_token, @@ -197,9 +198,11 @@ impl Subscription { #[graphql(name = "region")] region: Option, #[graphql(name = "municipality")] municipality: Option, ) -> impl Stream { - let base_uri = env::var("MEASURE_URL").unwrap(); let resource = env::var("MEASURE_RESOURCE").unwrap(); - let uri = format!("{}/{}", base_uri, resource); + let uri = Uri::new_from_env_var("MEASURE_URL") + .with_path(resource.as_str()) + .with_ws() + .to_string(); let ws_client = WsClient::new(uri, "gdp".to_string(), date, country, region, municipality); stream! { let mut measure_socket = match ws_client.connect() { diff --git a/services/request-create/Cargo.toml b/services/request-create/Cargo.toml index 27ea2ab6..8e13eabc 100644 --- a/services/request-create/Cargo.toml +++ b/services/request-create/Cargo.toml @@ -15,6 +15,7 @@ pg = { path = "../../crates/pg" } service = { path = "../../crates/service" } types = { path = "../../crates/types" } httpclient = { path = "../../crates/httpclient" } +uribuilder = { path = "../../crates/uribuilder" } [target.x86_64-unknown-linux-musl.dependencies] openssl = { version = "0.10", features = ["vendored"] } \ No newline at end of file diff --git a/services/request-create/src/main.rs b/services/request-create/src/main.rs index 77aa1767..ea4b3e9f 100644 --- a/services/request-create/src/main.rs +++ b/services/request-create/src/main.rs @@ -15,6 +15,7 @@ use types::{ request_response::IntraTransaction, transaction::Transaction, transaction_item::TransactionItems, }; +use uribuilder::Uri; // used by lambda to test for service availability const READINESS_CHECK_PATH: &str = "READINESS_CHECK_PATH"; @@ -36,7 +37,7 @@ enum RequestCreateError { pub async fn get_rule_applied_transaction( transaction_items: TransactionItems, ) -> Result> { - let uri = env::var("RULE_URL").unwrap(); + let uri = Uri::new_from_env_var("RULE_URL").to_string(); let client = Client::new(); let body = transaction_items.to_json_string(); let response = client.post(uri, body).await?; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index cf0d5764..64a8d4e0 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -15,6 +15,7 @@ httpclient = { path = "../crates/httpclient" } serde_json = "1.0.111" gql_client = "1.0.7" regex = "1.10.3" +uribuilder = { path = "../crates/uribuilder" } [features] integration_tests = [] diff --git a/tests/src/helpers.rs b/tests/src/helpers.rs index 6f99a1ae..44070af9 100644 --- a/tests/src/helpers.rs +++ b/tests/src/helpers.rs @@ -6,6 +6,7 @@ use ::types::{ use httpclient::HttpClient as Client; use serde_json::json; use std::{env, fs::File, io::BufReader, process::Command}; +use uribuilder::Uri; pub fn restore_testseed() { // cloud dev env @@ -68,7 +69,7 @@ pub async fn create_transaction() -> Transaction { let transaction_id = create_request.id.clone().unwrap(); // approve the transaction request using the debit approver and transaction id - let approve_request_uri = env::var("REQUEST_APPROVE_URL").unwrap(); + let approve_request_uri = Uri::new_from_env_var("REQUEST_APPROVE_URL").to_string(); let approve_request_body = RequestApprove::new( debit_approver.clone(), transaction_id, diff --git a/tests/src/requests.rs b/tests/src/requests.rs index 67596766..3da05258 100644 --- a/tests/src/requests.rs +++ b/tests/src/requests.rs @@ -8,7 +8,7 @@ use gql_client::Client as GqlClient; use httpclient::HttpClient as Client; use serde::{Deserialize, Serialize}; use serde_json::json; -use std::env; +use uribuilder::Uri; const GRAPHQL_RESOURCE: &str = "query"; @@ -27,11 +27,9 @@ pub async fn get_balance_gql( account_name: String, auth_account: String, ) -> Result> { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getBalance($account_name: String!, $auth_account: String!) { balance(account_name: $account_name, auth_account: $auth_account) }"#; @@ -122,11 +120,9 @@ struct RuleVars { pub async fn get_rules_gql( transaction_items: Vec, ) -> Result> { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getRules($transaction_items: [TransactionItemInput!]) { rules(transaction_items: $transaction_items) { id @@ -187,11 +183,9 @@ pub async fn create_request_gql( auth_account: String, transaction_items: Vec, ) -> Transaction { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"mutation createRequest($transaction_items: [TransactionItemInput!], $auth_account: String!) { createRequest(transaction_items: $transaction_items, auth_account: $auth_account) { id @@ -258,11 +252,9 @@ pub async fn approve_request_gql( account_role: String, auth_account: String, ) -> Transaction { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let mutation = r#"mutation approveRequest($id: String!, $account_name: String!, $account_role: String!, $auth_account: String!) { approveRequest(id: $id, account_name: $account_name, account_role: $account_role, auth_account: $auth_account) { id @@ -328,11 +320,9 @@ pub async fn get_transactions_by_account_gql( auth_account: String, account_name: String, ) -> Vec { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getTransactionsByAccount($account_name: String!, $auth_account: String!) { transactionsByAccount(account_name: $account_name, auth_account: $auth_account) { id @@ -400,11 +390,9 @@ pub async fn get_transaction_by_id_gql( account_name: String, id: String, ) -> Transaction { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getTransactionByID($id: String!, $account_name: String!, $auth_account: String!) { transactionByID(id: $id, account_name: $account_name, auth_account: $auth_account) { id @@ -468,11 +456,9 @@ pub async fn get_requests_by_account_gql( auth_account: String, account_name: String, ) -> Vec { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getRequestsByAccount($account_name: String!, $auth_account: String!) { requestsByAccount(account_name: $account_name, auth_account: $auth_account) { id @@ -537,11 +523,9 @@ pub async fn get_request_by_id_gql( account_name: String, id: String, ) -> Transaction { - let uri = format!( - "{}/{}", - std::env::var("GRAPHQL_URI").unwrap(), - GRAPHQL_RESOURCE - ); + let uri = Uri::new_from_env_var("GRAPHQL_URI") + .with_path(GRAPHQL_RESOURCE) + .to_string(); let query = r#"query getRequestByID($id: String!, $account_name: String!, $auth_account: String!) { requestByID(id: $id, account_name: $account_name, auth_account: $auth_account) { id @@ -590,7 +574,7 @@ pub async fn get_request_by_id_gql( pub async fn get_rules_http(transaction_items: Vec) -> IntraTransaction { let client = Client::new(); - let uri = env::var("RULE_URL").unwrap(); + let uri = Uri::new_from_env_var("RULE_URL").to_string(); let body_json = json!(transaction_items).to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); @@ -605,7 +589,7 @@ pub async fn create_request_http( let body = IntraTransaction::new(auth_account.clone(), transaction); let body_json = json!(body).to_string(); let client = Client::new(); - let uri = env::var("REQUEST_CREATE_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_CREATE_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let transaction_request: IntraTransaction = serde_json::from_str(&response_string).unwrap(); @@ -626,7 +610,7 @@ pub async fn approve_request_http( }) .to_string(); let client = Client::new(); - let uri = env::var("REQUEST_APPROVE_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_APPROVE_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let approved: IntraTransaction = serde_json::from_str(&response_string).unwrap(); @@ -640,7 +624,7 @@ pub async fn get_account_balance_http(account_name: String, auth_account: String }) .to_string(); let client = Client::new(); - let uri = env::var("BALANCE_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("BALANCE_BY_ACCOUNT_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let balance_float: f32 = serde_json::from_str(&response_string).unwrap(); @@ -659,7 +643,7 @@ pub async fn get_transaction_by_id_http( }) .to_string(); let client = Client::new(); - let uri = env::var("TRANSACTION_BY_ID_URL").unwrap(); + let uri = Uri::new_from_env_var("TRANSACTION_BY_ID_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let intra_transaction: IntraTransaction = serde_json::from_str(&response_string).unwrap(); @@ -676,7 +660,7 @@ pub async fn get_transactions_by_account_http( }) .to_string(); let client = Client::new(); - let uri = env::var("TRANSACTIONS_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("TRANSACTIONS_BY_ACCOUNT_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let intra_transactions: IntraTransactions = serde_json::from_str(&response_string).unwrap(); @@ -695,7 +679,7 @@ pub async fn get_request_by_id_http( }) .to_string(); let client = Client::new(); - let uri = env::var("REQUEST_BY_ID_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUEST_BY_ID_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let intra_transaction: IntraTransaction = serde_json::from_str(&response_string).unwrap(); @@ -712,7 +696,7 @@ pub async fn get_requests_by_account_http( }) .to_string(); let client = Client::new(); - let uri = env::var("REQUESTS_BY_ACCOUNT_URL").unwrap(); + let uri = Uri::new_from_env_var("REQUESTS_BY_ACCOUNT_URL").to_string(); let response = client.post(uri, body_json).await.unwrap(); let response_string = response.text().await.unwrap(); let intra_transactions: IntraTransactions = serde_json::from_str(&response_string).unwrap(); From 7eb9a7dcd488e192dcb18fba8975863b9a768a15 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:29:31 -0700 Subject: [PATCH 3/9] cargo lock --- Cargo.lock | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 280 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4117a75f..c057425a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1514,6 +1514,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "dotenvy" version = "0.15.7" @@ -1957,6 +1968,7 @@ dependencies = [ "tracing-subscriber", "tungstenite 0.24.0", "types", + "uribuilder", "wsclient", ] @@ -2352,6 +2364,124 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2360,12 +2490,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -2612,6 +2753,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.9" @@ -3644,6 +3791,7 @@ dependencies = [ "tracing", "tracing-subscriber", "types", + "uribuilder", ] [[package]] @@ -4219,6 +4367,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions_next" version = "1.1.2" @@ -4356,6 +4510,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "system-configuration" version = "0.6.0" @@ -4436,6 +4601,7 @@ dependencies = [ "serde_json", "tokio", "types", + "uribuilder", ] [[package]] @@ -4508,6 +4674,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -4949,11 +5125,18 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "uribuilder" +version = "0.1.0" +dependencies = [ + "url", +] + [[package]] name = "url" -version = "2.5.0" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -4972,6 +5155,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "0.8.2" @@ -5385,6 +5580,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "wsclient" version = "0.1.0" @@ -5407,6 +5614,30 @@ version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.23" @@ -5427,8 +5658,51 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", + "synstructure", +] + [[package]] name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] From 4ebcd41fcd7a904f4b039f4fac84698a91df7b17 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:31:16 -0700 Subject: [PATCH 4/9] add uriBuilder client module --- client/package.json | 1 + client/src/graphql/client.ts | 7 +++++-- client/src/routes/measure/+page.svelte | 8 +++++--- client/src/utils/uriBuilder.ts | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 client/src/utils/uriBuilder.ts diff --git a/client/package.json b/client/package.json index c00f8fc4..9e027090 100644 --- a/client/package.json +++ b/client/package.json @@ -42,6 +42,7 @@ "svelte-loading-spinners": "^0.3.4", "tslib": "^2.4.1", "typescript": "^4.9.3", + "url": "^0.11.4", "vite": "^4.0.4" }, "type": "module" diff --git a/client/src/graphql/client.ts b/client/src/graphql/client.ts index 6ff2bfbc..aa8c915b 100644 --- a/client/src/graphql/client.ts +++ b/client/src/graphql/client.ts @@ -2,13 +2,16 @@ import { createClient, cacheExchange, fetchExchange } from '@urql/core'; import type { ClientOptions } from '@urql/core'; import { getIdToken } from '../auth/cognito'; import b64 from 'base-64'; +import buildUri from '../utils/uriBuilder'; const apiResource = 'query'; -const url: string = b64.decode(process.env.GRAPHQL_URI as string)?.trim() + '/' + apiResource; +const relativeUri: string = b64.decode(process.env.GRAPHQL_URI as string)?.trim() + '/' + apiResource; + +const uri: string = buildUri(relativeUri); const clientOpts: ClientOptions = { - url, + url: uri, exchanges: [cacheExchange, fetchExchange], maskTypename: true, fetchOptions: { diff --git a/client/src/routes/measure/+page.svelte b/client/src/routes/measure/+page.svelte index e450ad07..be2733ae 100644 --- a/client/src/routes/measure/+page.svelte +++ b/client/src/routes/measure/+page.svelte @@ -4,6 +4,7 @@ import b64 from 'base-64'; import { createClient as createWSClient } from 'graphql-ws'; import type { Client } from 'graphql-ws'; + import uriBuilder from '../../utils/uriBuilder'; let searchQuery = ''; let price: string; let priceTag: HTMLDivElement; @@ -20,14 +21,15 @@ region: string, municipality: string | null ) { - if (messageCount) { await resetWebsocket(); } + const uri = uriBuilder(b64.decode(process.env.GRAPHQL_SUBSCRIPTIONS_URI as string)) + wsClient = createWSClient({ - url: b64.decode(process.env.GRAPHQL_SUBSCRIPTIONS_URI as string), - }); + url: uri + }); const variables: any = { date, country, region }; if (municipality) { diff --git a/client/src/utils/uriBuilder.ts b/client/src/utils/uriBuilder.ts new file mode 100644 index 00000000..c82f837a --- /dev/null +++ b/client/src/utils/uriBuilder.ts @@ -0,0 +1,25 @@ +import url from 'url'; + +export default function (uri: string): string { + // if protocol prefix missing + if (!uri.includes('://')) { + // if its a websocket uri + if (uri.includes('/ws')) { + // add ws:// prefix + uri = 'ws://' + uri; + } else { + // add http:// prefix + uri = 'http://' + uri; + } + } + const parsed = url.parse(uri); + if (process.env.ENABLE_TLS && process.env.ENABLE_TLS === 'true') { + if (parsed.protocol === 'http:') { + parsed.protocol = 'https:'; + } + if (parsed.protocol === 'ws:') { + parsed.protocol = 'wss:'; + } + } + return url.format(parsed); +} \ No newline at end of file From 7af0786628330edd5040f2b8095d5bca650c2bad Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:31:30 -0700 Subject: [PATCH 5/9] client npm lock --- client/package-lock.json | 402 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 395 insertions(+), 7 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 97e374b1..8752c28e 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -36,6 +36,7 @@ "svelte-loading-spinners": "^0.3.4", "tslib": "^2.4.1", "typescript": "^4.9.3", + "url": "^0.11.4", "vite": "^4.0.4" } }, @@ -1129,6 +1130,26 @@ "node": ">=10.16.0" } }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -1278,6 +1299,24 @@ "node": ">=0.10.0" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/detect-indent": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", @@ -1326,6 +1365,29 @@ "node": ">=12" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es6-promise": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", @@ -1754,10 +1816,34 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/glob": { "version": "7.2.3", @@ -1838,6 +1924,19 @@ "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", "dev": true }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/graceful-fs": { "version": "4.2.10", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", @@ -1896,6 +1995,58 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -2330,6 +2481,19 @@ "node": ">=0.10.0" } }, + "node_modules/object-inspect": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", + "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -2537,6 +2701,22 @@ "node": ">=6" } }, + "node_modules/qs": { + "version": "6.13.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.1.tgz", + "integrity": "sha512-EJPeIn0CYrGu+hli1xilKAPXODtJ12T0sP63Ijx2/khC2JtuaN3JyNIpvmnkmaEtha9ocbG4A4cMcr+TvqvwQg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -2740,6 +2920,24 @@ "integrity": "sha512-1jeBGaKNGdEq4FgIrORu/N570dwoPYio8lSoYLWmX7sQ//0JY08Xh9o5pBcgmHQ/MbsYp/aZnOe1s1lIsbLprQ==", "dev": true }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "license": "MIT", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -2778,6 +2976,25 @@ "node": ">=4" } }, + "node_modules/side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/sirv": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.2.tgz", @@ -3146,6 +3363,27 @@ "punycode": "^2.1.0" } }, + "node_modules/url": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/url/-/url-0.11.4.tgz", + "integrity": "sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^1.4.1", + "qs": "^6.12.3" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/url/node_modules/punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", + "dev": true, + "license": "MIT" + }, "node_modules/vite": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/vite/-/vite-4.0.4.tgz", @@ -3964,6 +4202,19 @@ "streamsearch": "^1.1.0" } }, + "call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, + "requires": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -4072,6 +4323,17 @@ "integrity": "sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==", "dev": true }, + "define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "requires": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + } + }, "detect-indent": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", @@ -4108,6 +4370,21 @@ "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", "dev": true }, + "es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "requires": { + "get-intrinsic": "^1.2.4" + } + }, + "es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true + }, "es6-promise": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", @@ -4440,11 +4717,24 @@ "optional": true }, "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", "dev": true }, + "get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, + "requires": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + } + }, "glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -4503,6 +4793,15 @@ "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", "dev": true }, + "gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "requires": { + "get-intrinsic": "^1.1.3" + } + }, "graceful-fs": { "version": "4.2.10", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", @@ -4543,6 +4842,36 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, + "has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, + "requires": { + "es-define-property": "^1.0.0" + } + }, + "has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true + }, + "hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "requires": { + "function-bind": "^1.1.2" + } + }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -4851,6 +5180,12 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, + "object-inspect": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", + "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", + "dev": true + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -4985,6 +5320,15 @@ "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", "dev": true }, + "qs": { + "version": "6.13.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.1.tgz", + "integrity": "sha512-EJPeIn0CYrGu+hli1xilKAPXODtJ12T0sP63Ijx2/khC2JtuaN3JyNIpvmnkmaEtha9ocbG4A4cMcr+TvqvwQg==", + "dev": true, + "requires": { + "side-channel": "^1.0.6" + } + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -5112,6 +5456,20 @@ "integrity": "sha512-1jeBGaKNGdEq4FgIrORu/N570dwoPYio8lSoYLWmX7sQ//0JY08Xh9o5pBcgmHQ/MbsYp/aZnOe1s1lIsbLprQ==", "dev": true }, + "set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "requires": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + } + }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -5138,6 +5496,18 @@ "rechoir": "^0.6.2" } }, + "side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, + "requires": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + } + }, "sirv": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.2.tgz", @@ -5378,6 +5748,24 @@ "punycode": "^2.1.0" } }, + "url": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/url/-/url-0.11.4.tgz", + "integrity": "sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==", + "dev": true, + "requires": { + "punycode": "^1.4.1", + "qs": "^6.12.3" + }, + "dependencies": { + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", + "dev": true + } + } + }, "vite": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/vite/-/vite-4.0.4.tgz", From 476f40f2b9855dca05bf585e37719434c798b0b9 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:31:59 -0700 Subject: [PATCH 6/9] remove protocol prefix assignments in script --- scripts/create-env-file.sh | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/create-env-file.sh b/scripts/create-env-file.sh index 5f145969..81b449fe 100644 --- a/scripts/create-env-file.sh +++ b/scripts/create-env-file.sh @@ -54,7 +54,7 @@ fi # avoid env-id when developing locally if [[ $ENV != 'local' ]]; then - if [[ ! -f '.env' ]]; then + if [[ ! -f '.env' ]] && [[ -z $ENV_ID ]]; then echo 'set ENV_ID variable in project root .env or make build-dev to build a cloud dev environment' exit 1 fi @@ -69,24 +69,17 @@ ENABLE_API_AUTH=$(yq '.infra.terraform.aws.modules.environment.env_var.set.ENABL ENV_FILE_NAME=$(yq '.env_var.set.ENV_FILE_NAME.default' $PROJECT_CONF) ENV_FILE="$APP_DIR_PATH/$ENV_FILE_NAME" LOCAL_ADDRESS=$(yq '.env_var.set.LOCAL_ADDRESS.default' $PROJECT_CONF) -HOST="http://$LOCAL_ADDRESS" # set CLIENT_URI and GRAPHQL_URI vars source ./scripts/set-uri-vars.sh function set_default_value() { local SECRET="$1" - # todo: hardcode protocol prefixes in apps. this ws:// exception for MEASURE_URL is a hack - if [[ "$SECRET" == 'MEASURE_URL' ]]; then + if [[ "$SECRET" == *'_URL' ]]; then SVC_NAME=$(printf '%s' "$SECRET" | sed 's/_URL//') PORT_ENV_VAR="$SVC_NAME"_PORT PORT_VAL=$(yq "... | select(has(\"$PORT_ENV_VAR\")).$PORT_ENV_VAR.default" $PROJECT_CONF) - echo "$SECRET=ws://$LOCAL_ADDRESS:$PORT_VAL" >>$ENV_FILE - elif [[ "$SECRET" == *'_URL' ]]; then - SVC_NAME=$(printf '%s' "$SECRET" | sed 's/_URL//') - PORT_ENV_VAR="$SVC_NAME"_PORT - PORT_VAL=$(yq "... | select(has(\"$PORT_ENV_VAR\")).$PORT_ENV_VAR.default" $PROJECT_CONF) - echo "$SECRET=$HOST:$PORT_VAL" >>$ENV_FILE + echo "$SECRET=$LOCAL_ADDRESS:$PORT_VAL" >>$ENV_FILE elif [[ "$SECRET" == 'GRAPHQL_URI' ]]; then # todo: change GRAPHQL_URI to GRAPHQL_URL SVC_NAME=$(printf '%s' "$SECRET" | sed 's/_URI//') PORT_ENV_VAR="$SVC_NAME"_PORT @@ -94,7 +87,7 @@ function set_default_value() { if [[ $GITPOD_WORKSPACE_URL ]] || [[ $CODESPACES ]]; then echo "$SECRET=$GRAPHQL_URI" >>$ENV_FILE else - echo "$SECRET=$HOST:$PORT_VAL" >>$ENV_FILE + echo "$SECRET=$LOCAL_ADDRESS:$PORT_VAL" >>$ENV_FILE fi elif [[ "$SECRET" == 'GRAPHQL_SUBSCRIPTIONS_URI' ]]; then SVC_NAME=$(printf '%s' "$SECRET" | sed 's/_SUBSCRIPTIONS_URI//') @@ -104,7 +97,7 @@ function set_default_value() { if [[ $GITPOD_WORKSPACE_URL ]] || [[ $CODESPACES ]]; then echo "$SECRET=$GRAPHQL_URI" >>$ENV_FILE else - echo "$SECRET=ws://$LOCAL_ADDRESS:$PORT_VAL/ws" >>$ENV_FILE + echo "$SECRET=$LOCAL_ADDRESS:$PORT_VAL/ws" >>$ENV_FILE fi elif [[ "$SECRET" == 'CLIENT_URI' ]]; then # todo: change CLIENT_URI to CLIENT_URL SVC_NAME=$(printf '%s' "$SECRET" | sed 's/_URI//') @@ -113,7 +106,7 @@ function set_default_value() { if [[ $GITPOD_WORKSPACE_URL ]] || [[ $CODESPACES ]]; then echo "$SECRET=$CLIENT_URI" >>$ENV_FILE else - echo "$SECRET=$HOST:$PORT_VAL" >>$ENV_FILE + echo "$SECRET=$LOCAL_ADDRESS:$PORT_VAL" >>$ENV_FILE fi elif [[ "$SECRET" == 'RUST_LOG' ]]; then RUST_LOG_VAL=$(yq "$APP_CONF_PATH.rust_log" $PROJECT_CONF) @@ -167,7 +160,7 @@ rm -f $ENV_FILE for s in "${SECRETS[@]}"; do if [[ $ENV == 'local' ]]; then - if [[ "$SECRET" == 'AWS_LAMBDA_FUNCTION_NAME' ]]; then + if [[ "$s" == 'AWS_LAMBDA_FUNCTION_NAME' ]]; then continue # skip setting when ENV=local fi set_default_value "$s" From 1709f2d2019b76ed9d92e0d6e8a6677d22a16bf6 Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:32:53 -0700 Subject: [PATCH 7/9] disable provenance --- .github/workflows/prod-client-docker-base.yaml | 2 +- client/makefile | 6 +----- scripts/build-image-job.sh | 2 +- scripts/build-image.sh | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/prod-client-docker-base.yaml b/.github/workflows/prod-client-docker-base.yaml index 1c92e52f..3d0f46cc 100644 --- a/.github/workflows/prod-client-docker-base.yaml +++ b/.github/workflows/prod-client-docker-base.yaml @@ -19,6 +19,6 @@ jobs: - name: docker login run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u mxfactorial --password-stdin - name: docker build - run: docker build -f ./docker/client-base.Dockerfile -t "$IMAGE_NAME" . + run: docker build -f ./docker/client-base.Dockerfile -t "$IMAGE_NAME" --provenance=false . - name: docker push run: docker image push "$IMAGE_NAME" \ No newline at end of file diff --git a/client/makefile b/client/makefile index cfc88e7c..800cfbca 100644 --- a/client/makefile +++ b/client/makefile @@ -14,10 +14,6 @@ DEPS_DIR=$(CURDIR)/node_modules REGION=$(shell yq '.infra.terraform.aws.modules.environment.env_var.set.REGION.default' $(PROJECT_CONF)) ENV_FILE_NAME=$(shell yq '.env_var.set.ENV_FILE_NAME.default' $(PROJECT_CONF)) ENV_FILE=$(CURDIR)/$(ENV_FILE_NAME) -LOCAL_ADDRESS=$(shell yq '.env_var.set.LOCAL_ADDRESS.default' $(PROJECT_CONF)) -HOST=http://$(LOCAL_ADDRESS) -GRAPHQL_URI=$(HOST):$(shell yq '.services.graphql.env_var.set.GRAPHQL_PORT.default' $(PROJECT_CONF)) -B64_GRAPHQL_URI=$(shell if [ `uname -s` == 'Darwin' ]; then printf $(GRAPHQL_URI) | base64; else printf $(GRAPHQL_URI) | base64 -w 0; fi) NOHUP_LOG=$(RELATIVE_PROJECT_ROOT_PATH)/$(shell yq '.env_var.set.NOHUP_LOG.default' $(PROJECT_CONF)) GITHUB_ORG=$(shell yq '.[".github"].env_var.set.GITHUB_ORG.default' $(PROJECT_CONF)) GITHUB_REPO_NAME=$(shell yq '.[".github"].env_var.set.GITHUB_REPO_NAME.default' $(PROJECT_CONF)) @@ -167,7 +163,7 @@ down: build-k8s: cd $(RELATIVE_PROJECT_ROOT_PATH); \ - docker build -f ./docker/client.Dockerfile -t $(CONTAINER_REGISTRY):latest . + docker build -f ./docker/client.Dockerfile -t $(CONTAINER_REGISTRY):latest --provenance=false . push-k8s: docker push $(CONTAINER_REGISTRY):latest diff --git a/scripts/build-image-job.sh b/scripts/build-image-job.sh index 63a8ecfe..f0219c9d 100644 --- a/scripts/build-image-job.sh +++ b/scripts/build-image-job.sh @@ -37,4 +37,4 @@ unzip $SERVICES_ZIP -d $SERVICES_DIR cd $SERVICES_DIR -docker build -t $SERVICE_NAME:latest -f ./docker/$SERVICE_NAME.Dockerfile $BUILD_CTX \ No newline at end of file +docker build -t $SERVICE_NAME:latest -f ./docker/$SERVICE_NAME.Dockerfile --provenance=false $BUILD_CTX \ No newline at end of file diff --git a/scripts/build-image.sh b/scripts/build-image.sh index 8bf0f302..bda99f73 100644 --- a/scripts/build-image.sh +++ b/scripts/build-image.sh @@ -37,5 +37,5 @@ COUNT=$(docker image ls | grep --color=never -E "^$APP_NAME.*latest" | wc -l | x if [[ $COUNT -gt 0 ]]; then docker tag $APP_NAME:latest $IMAGE_TAG else - docker build -f $DOCKERFILE_PATH -t $IMAGE_TAG "$BUILD_CTX" + docker build -f $DOCKERFILE_PATH -t $IMAGE_TAG --provenance=false "$BUILD_CTX" fi From 92874cb86ce6dacfedc2d2b87d79c684339f318e Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:33:17 -0700 Subject: [PATCH 8/9] standardizing financial value with loc faq detail --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df60f402..9e73b403 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ encryption and replication are secondary ![sum conserved value now](https://github.com/user-attachments/assets/c6ea04b2-06a1-4234-b3d7-956007f5141f) **q.** how does standardizing financial value as a conserved quantity protect individuals? -**a.** applying a conservation law to financial value protects producers and consumers from an abuse of government authority. consumer wealth increases when producers increase the [purchasing power](https://en.wikipedia.org/wiki/Information_content) of money by shipping useful r&d. but government printing money, and government chartered "bankers" expecting money are not the same types of events as producers shipping useful r&d. theyre not even the same types of events as producers shipping common goods and services. so when government authority is used to violate conservation by defining money as something you can just print and [mix](https://en.wikipedia.org/wiki/Money_multiplier) with failing "bank" notes, the loss of information in money from these physically negative events steals away the 1) purchasing power created by producers, the 2) increased wealth of consumers, and the 3) value of all property owned by individuals +**a.** applying a conservation law to financial value protects producers and consumers from an abuse of government authority. consumer wealth increases when producers increase the [purchasing power](https://en.wikipedia.org/wiki/Information_content) of money by shipping useful r&d. but government printing money, and government chartered "bankers" expecting money are not the same types of events as producers shipping useful r&d. theyre not even the same types of events as producers shipping common goods and services since they unfairly depend on transferring their expense to everyone else. so when government authority is used to violate conservation by defining money as something you can just print and [mix](https://en.wikipedia.org/wiki/Money_multiplier) with failing "bank" notes, the loss of information in money from these physically negative events steals away the 1) purchasing power created by producers, the 2) increased wealth of consumers and 3) the value of all property government is not above failure, nor is it entitled to steal from the private sector to conceal its failure. improving government depends on failure [predicting](https://en.wikipedia.org/wiki/Time_travel_debugging) the individuals and laws that must be replaced. flying a flag and demanding loyalty before this step is just misdirection From 0c0ecdf8b3753393fb88be8b4d31537ceabc345a Mon Sep 17 00:00:00 2001 From: max funk Date: Fri, 22 Nov 2024 17:33:31 -0700 Subject: [PATCH 9/9] remove dev settings from project.yaml after summary testing --- scripts/test-all.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index c59f781b..97112677 100644 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -2,6 +2,8 @@ set -e +PROJECT_CONF=project.yaml + # standard lint cargo fmt --all -- --check # clippy lint @@ -13,4 +15,16 @@ make --no-print-directory -C crates/pg test-db # test integration make --no-print-directory -C tests test-local # test client -make --no-print-directory -C client test \ No newline at end of file +make --no-print-directory -C client test + +echo '' +echo "*** removing $PROJECT_CONF development settings" +if [[ $(uname -s) == "Darwin" ]]; then + sed -i '' 's/rust_log:.*/rust_log: off/' $PROJECT_CONF +else + sed -i 's/rust_log:.*/rust_log: off/' $PROJECT_CONF +fi +# use yq to set .client.env_var.set.GOOGLE_MAPS_API_KEY.default to null +yq -i '.client.env_var.set.GOOGLE_MAPS_API_KEY.default = null' $PROJECT_CONF +# remove empty line at end of project.yaml +printf %s "$(cat $PROJECT_CONF)" >$PROJECT_CONF