Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path = "src/main.rs"
[dependencies]
openssl = { version = '0.10', features = ["vendored"] }
anyhow = "1.0.65"
clap = { version = "4.0.17", features = ["derive"] }
clap = { version = "4.0.17", features = ["derive", "cargo"] }
envtestkit = "1.1.2"
humantime = "2.1.0"
indicatif = "0.17.2"
Expand All @@ -26,6 +26,7 @@ tempdir = "0.3.7"
term = "0.7.0"
thiserror = "1.0.37"
dirs = "4.0.0"
http-auth-basic = "0.3.3"

[dev-dependencies]
httpmock = "0.6"
29 changes: 14 additions & 15 deletions src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ pub struct Config {
#[derive(Error, Debug)]
pub enum AuthenticationError {
#[error("wrong credentials error")]
WrongCredentialsError,
WrongCredentials,
#[error("no credentials error")]
NoCredentialsError,
NoCredentials,
#[error("request error")]
RequestError(#[from] reqwest::Error),
Request(#[from] reqwest::Error),
#[error("i/o error")]
IoError(#[from] std::io::Error),
Io(#[from] std::io::Error),
#[error("env error")]
EnvError(#[from] env::VarError),
Env(#[from] env::VarError),
#[error("missing home dir error")]
MissingHomeDirError(),
MissingHomeDir(),
#[error("invalid header error")]
InvalidHeaderError(#[from] InvalidHeaderValue),
InvalidHeader(#[from] InvalidHeaderValue),
#[error("unknown error")]
Unknown,
}
Expand Down Expand Up @@ -61,9 +61,9 @@ impl Authentication {

match dirs::home_dir() {
Some(path) => {
fs::read_to_string(path.join(".screenly")).map_err(AuthenticationError::IoError)
fs::read_to_string(path.join(".screenly")).map_err(AuthenticationError::Io)
}
None => Err(AuthenticationError::NoCredentialsError),
None => Err(AuthenticationError::NoCredentials),
}
}

Expand All @@ -80,7 +80,7 @@ impl Authentication {
fs::write(home.join(".screenly"), token)?;
Ok(())
}
None => Err(AuthenticationError::MissingHomeDirError()),
None => Err(AuthenticationError::MissingHomeDir()),
}
}

Expand All @@ -96,7 +96,7 @@ impl Authentication {
.send()?;

match res.status().as_u16() {
401 => Err(AuthenticationError::WrongCredentialsError),
401 => Err(AuthenticationError::WrongCredentials),
404 => Ok(()),
_ => Err(AuthenticationError::Unknown),
}
Expand All @@ -115,7 +115,7 @@ impl Authentication {
reqwest::blocking::Client::builder()
.default_headers(default_headers)
.build()
.map_err(AuthenticationError::RequestError)
.map_err(AuthenticationError::Request)
}
}

Expand All @@ -130,8 +130,7 @@ mod tests {
use simple_logger::SimpleLogger;
use tempdir::TempDir;

use crate::authentication::Config;
use crate::Authentication;
use super::*;

#[test]
fn test_verify_and_store_token_when_token_is_valid() {
Expand Down Expand Up @@ -184,7 +183,7 @@ mod tests {
}

#[test]
fn test_read_token_when_token_is_overriden_with_env_variable_correct_token_is_returned() {
fn test_read_token_when_token_is_overridden_with_env_variable_correct_token_is_returned() {
let tmp_dir = TempDir::new("test").unwrap();
let _lock = lock_test();
let _token = set_env(OsString::from("API_TOKEN"), "env_token");
Expand Down
Loading