Skip to content
Open
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
13 changes: 9 additions & 4 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ impl<'r> FromRequest<'r> for ShortyToken {
}
};

let actual_token = match env::var("TOKEN") {
Ok(x) => x,
Err(_) => {
return Outcome::Failure((Status::Unauthorized, String::from("Invalid API token.")))
let actual_token = if let Ok(token) = env::var("TOKEN") {
token
} else if let Ok(token_file) = env::var("TOKEN_FILE") {
let read_result = std::fs::read_to_string(token_file);
if read_result.is_err() {
return Outcome::Failure((Status::Unauthorized, String::from("Invalid API token.")));
}
read_result.expect("")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this condition wouldn't cause the app to crash

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't, because we already checked is_err().

} else {
return Outcome::Failure((Status::Unauthorized, String::from("Invalid API token.")));
};

if provided_token != actual_token {
Expand Down