From 209c570789bbf3fc1ffd9b64bb357feb7dbec0bf Mon Sep 17 00:00:00 2001 From: korvyashka Date: Thu, 16 May 2024 12:42:25 +0400 Subject: [PATCH 1/2] Adds: API_BASE_URL env var --- src/authentication.rs | 34 +++++++++++++++++++++++++++++++++- src/commands/edge_app.rs | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/authentication.rs b/src/authentication.rs index 1d69f01..fd1ef03 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -4,6 +4,7 @@ use reqwest::header::{HeaderMap, InvalidHeaderValue}; use reqwest::{header, StatusCode}; use thiserror::Error; +// For compatability reasons - let's leave build env as well. include!(concat!(env!("OUT_DIR"), "/config.rs")); // for local development // also uncomment unsafe certificate lines "danger_accept_invalid_certs(true)". @@ -40,7 +41,13 @@ pub struct Authentication { impl Config { pub fn default() -> Self { Self { - url: API_BASE_URL.to_string(), + url: { + if let Ok(url) = env::var("API_BASE_URL") { + url + } else { + API_BASE_URL.to_string() + } + }, } } @@ -231,4 +238,29 @@ mod tests { Authentication::remove_token().unwrap(); assert!(!tmp_dir.path().join(".screenly").exists()); } + + #[test] + fn test_verify_and_store_token_when_base_url_is_overdriven() { + env::set_var("API_BASE_URL", "https://login.screenly.local"); + let tmp_dir = tempdir().unwrap(); + let _lock = lock_test(); + let _test = set_env(OsString::from("HOME"), tmp_dir.path().to_str().unwrap()); + + let mock_server = MockServer::start(); + let group_call_mock = mock_server.mock(|when, then| { + when.method(GET) + .path("/v3/groups/11CF9Z3GZR0005XXKH00F8V20R/") + .header("Authorization", "Token correct_token"); + then.status(404); + }); + + let config = Config::new(mock_server.base_url()); + let authentication = Authentication::new_with_config(config, ""); + assert!(verify_and_store_token("correct_token", &authentication.config.url).is_ok()); + let path = tmp_dir.path().join(".screenly"); + assert!(path.exists()); + let contents = fs::read_to_string(path).unwrap(); + group_call_mock.assert(); + assert!(contents.eq("correct_token")); + } } diff --git a/src/commands/edge_app.rs b/src/commands/edge_app.rs index c638646..859009c 100644 --- a/src/commands/edge_app.rs +++ b/src/commands/edge_app.rs @@ -405,7 +405,7 @@ impl EdgeAppCommand { actual_app_id: String, changed_settings: SettingChanges, ) -> Result<(), CommandError> { - match delete_missing_settings { + match delete_missing_settings { Some(delete) => { if delete { self.delete_deleted_settings( From 07c9b37416230341d04c45eca1208d4452ba6ff6 Mon Sep 17 00:00:00 2001 From: korvyashka Date: Thu, 16 May 2024 12:57:56 +0400 Subject: [PATCH 2/2] Updates: workflow passing arguments to not return error on lint --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a5ea502..7d73588 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,6 +18,7 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets --all-features -- -D warnings - name: rust-fmt-check uses: actions-rust-lang/rustfmt@v1 with: