Skip to content

Commit

Permalink
Add environment variable support to credential loading
Browse files Browse the repository at this point in the history
Load credentials from SLOT_AUTH env variable if set, else from file. This allows for easier configuration management and flexibility in different deployment environments.
  • Loading branch information
steebchen committed Sep 17, 2024
1 parent 267f4fb commit 91c69b8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions slot/src/credential.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::{Path, PathBuf};
use std::{env, fs};

use crate::account::Account;
use crate::error::Error;
Expand Down Expand Up @@ -65,13 +65,19 @@ impl Credentials {
}

pub(crate) fn load_at<P: AsRef<Path>>(config_dir: P) -> Result<Credentials, Error> {
let path = get_file_path(config_dir);
let content = if env::var("SLOT_AUTH").is_ok() {

Check failure on line 68 in slot/src/credential.rs

View workflow job for this annotation

GitHub Actions / clippy

the size for values of type `str` cannot be known at compilation time

Check failure on line 68 in slot/src/credential.rs

View workflow job for this annotation

GitHub Actions / test

the size for values of type `str` cannot be known at compilation time
env::var("SLOT_AUTH").unwrap();
} else {
let path = get_file_path(config_dir);

if !path.exists() {
return Err(Error::Unauthorized);
}

if !path.exists() {
return Err(Error::Unauthorized);
fs::read_to_string(path)?;
}
.into();

Check failure on line 79 in slot/src/credential.rs

View workflow job for this annotation

GitHub Actions / clippy

the trait bound `str: std::convert::From<()>` is not satisfied

Check failure on line 79 in slot/src/credential.rs

View workflow job for this annotation

GitHub Actions / test

the trait bound `str: From<()>` is not satisfied

let content = fs::read_to_string(path)?;
let credentials = serde_json::from_str::<Credentials>(&content);

match credentials {
Expand Down

0 comments on commit 91c69b8

Please sign in to comment.