Skip to content

Commit

Permalink
Merge pull request #167 from Screenly/feature/base_url_env
Browse files Browse the repository at this point in the history
Adds: API_BASE_URL env var
  • Loading branch information
korvyashka authored May 16, 2024
2 parents e5c45d5 + 07c9b37 commit 8a0b996
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 33 additions & 1 deletion src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)".
Expand Down Expand Up @@ -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()
}
},
}
}

Expand Down Expand Up @@ -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"));
}
}
2 changes: 1 addition & 1 deletion src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8a0b996

Please sign in to comment.