From ce4dd1df74e052b995ffd4cb251cbb873a803a45 Mon Sep 17 00:00:00 2001 From: Rohit Sarpotdar Date: Mon, 18 Mar 2024 16:55:11 +0530 Subject: [PATCH 1/2] changed config structure changed fly deploy to local --- ...deploy-to-production-on-merge-to-main.yaml | 2 +- AppConfig.toml | 20 +++---- src/init.rs | 54 +++++++------------ src/main.rs | 6 +-- 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/.github/workflows/deploy-to-production-on-merge-to-main.yaml b/.github/workflows/deploy-to-production-on-merge-to-main.yaml index 93e6e84..1047bf3 100644 --- a/.github/workflows/deploy-to-production-on-merge-to-main.yaml +++ b/.github/workflows/deploy-to-production-on-merge-to-main.yaml @@ -44,4 +44,4 @@ jobs: flyctl secrets set --stage AUTH_SIGN_KEY="$AUTH_SIGN_KEY" flyctl secrets set --stage CLOUDFLARE_API_TOKEN="$CLOUDFLARE_API_TOKEN" flyctl secrets set --stage GOOGLE_CLIENT_SECRET="$GOOGLE_CLIENT_SECRET" - flyctl deploy --remote-only --build-arg CLOUDFLARE_ACCOUNT_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_ACCOUNT_ID }} --build-arg CLOUDFLARE_NAMESPACE_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_NAMESPACE_ID }} --build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_SIGNING_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID }} + flyctl deploy --local-only --build-arg CLOUDFLARE_ACCOUNT_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_ACCOUNT_ID }} --build-arg CLOUDFLARE_NAMESPACE_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_NAMESPACE_ID }} --build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_SIGNING_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID }} diff --git a/AppConfig.toml b/AppConfig.toml index 708a7c9..f8eed75 100644 --- a/AppConfig.toml +++ b/AppConfig.toml @@ -1,16 +1,12 @@ -[auth] -ic_url = "https://ic0.app" -sign_key = "" +auth_ic_url = "https://ic0.app" +auth_sign_key = "" auth_domain = "https://hot-or-not-auth.fly.dev" app_domain = "https://hot-or-not-web-leptos-ssr.fly.dev" -[cloudflare] -account_identifier = "" -api_token = "" -namespace_identifier = "" +cloudflare_account_identifier = "" +cloudflare_api_token = "" +cloudflare_namespace_identifier = "" -[[oauth]] -provider_name = "google" -auth_landing_url = "https://hot-or-not-auth.fly.dev/google_oauth2_response" -client_id = "" -client_secret = "" +google_auth_landing_url = "https://hot-or-not-auth.fly.dev/google_oauth2_response" +google_client_id = "" +google_client_secret = "" diff --git a/src/init.rs b/src/init.rs index 93a9079..ef1550d 100644 --- a/src/init.rs +++ b/src/init.rs @@ -32,12 +32,9 @@ pub fn configure() -> AppConfig { .merge(Env::raw()) .extract() .unwrap(); - info!("sign: {}", config.auth.sign_key.len()); - info!("ctoken: {}", config.cloudflare.api_token.len()); - info!( - "gtoken: {}", - config.oauth.get(0).unwrap().client_secret.len() - ); + info!("sign: {}", config.auth_sign_key.len()); + info!("ctoken: {}", config.cloudflare_api_token.len()); + info!("gtoken: {}", config.google_client_secret.len()); config } @@ -45,24 +42,25 @@ pub fn configure() -> AppConfig { pub fn cloudflare_config(config: &AppConfig) -> cloudflare_api::connect::ApiClientConfig { use cloudflare_api::connect::{ApiClientConfig, Credentials, HttpApiClient}; ApiClientConfig { - account_identifier: config.cloudflare.account_identifier.clone(), - namespace_identifier: config.cloudflare.namespace_identifier.clone(), + account_identifier: config.cloudflare_account_identifier.clone(), + namespace_identifier: config.cloudflare_namespace_identifier.clone(), cloudflare_client: HttpApiClient::new(&Credentials::UserAuthToken { - token: config.cloudflare.api_token.clone(), + token: config.cloudflare_api_token.clone(), }), } } #[cfg(feature = "ssr")] pub fn oauth2_client_init(config: &AppConfig) -> oauth2::basic::BasicClient { - let google = config.oauth.get(0).unwrap(); oauth2::basic::BasicClient::new( - oauth2::ClientId::new(google.client_id.to_owned()), - Some(oauth2::ClientSecret::new(google.client_secret.to_owned())), + oauth2::ClientId::new(config.google_client_id.to_owned()), + Some(oauth2::ClientSecret::new( + config.google_client_secret.to_owned(), + )), oauth2::AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap(), Some(oauth2::TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap()), ) - .set_redirect_uri(oauth2::RedirectUrl::new(google.auth_landing_url.to_owned()).unwrap()) + .set_redirect_uri(oauth2::RedirectUrl::new(config.google_auth_landing_url.to_owned()).unwrap()) } #[cfg(feature = "ssr")] @@ -90,30 +88,16 @@ pub fn cors_layer() -> CorsLayer { #[derive(Debug, Deserialize, Clone)] pub struct AppConfig { - pub auth: AuthConfig, - pub cloudflare: CloudflareConfig, - pub oauth: Vec, -} - -#[derive(Debug, Deserialize, Clone)] -pub struct AuthConfig { - pub ic_url: String, - pub sign_key: String, + pub auth_ic_url: String, + pub auth_sign_key: String, pub auth_domain: String, pub app_domain: String, -} -#[derive(Debug, Deserialize, Clone)] -pub struct CloudflareConfig { - pub account_identifier: String, - pub api_token: String, - pub namespace_identifier: String, -} + pub cloudflare_account_identifier: String, + pub cloudflare_api_token: String, + pub cloudflare_namespace_identifier: String, -#[derive(Debug, Deserialize, Clone)] -pub struct OAuthConfig { - pub provider_name: String, - pub auth_landing_url: String, - pub client_id: String, - pub client_secret: String, + pub google_auth_landing_url: String, + pub google_client_id: String, + pub google_client_secret: String, } diff --git a/src/main.rs b/src/main.rs index c035836..f093fdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,12 +88,12 @@ async fn main() { let app_state = identity::AppState { leptos_options, - key: Key::from(app_config.auth.sign_key.as_bytes()), + key: Key::from(app_config.auth_sign_key.as_bytes()), routes: routes.clone(), oauth2_client, reqwest_client: reqwest::Client::new(), - auth_domain: Url::parse(&app_config.auth.auth_domain).unwrap(), - app_domain: Url::parse(&app_config.auth.app_domain).unwrap(), + auth_domain: Url::parse(&app_config.auth_domain).unwrap(), + app_domain: Url::parse(&app_config.auth_app_domain).unwrap(), cloudflare_config, }; let app_state: identity::AppState = app_state; From 7f75c66ec6ea368e7e9d6af2396ae901f95f75d4 Mon Sep 17 00:00:00 2001 From: Rohit Sarpotdar Date: Mon, 18 Mar 2024 17:04:55 +0530 Subject: [PATCH 2/2] config structure update fix --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f093fdf..708f5a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ async fn main() { oauth2_client, reqwest_client: reqwest::Client::new(), auth_domain: Url::parse(&app_config.auth_domain).unwrap(), - app_domain: Url::parse(&app_config.auth_app_domain).unwrap(), + app_domain: Url::parse(&app_config.app_domain).unwrap(), cloudflare_config, }; let app_state: identity::AppState = app_state;