-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/SM-1174 ## 📔 Objective This PR switches `bws` to use access token login state by default. This will help prevent many users from running into rate limiting issues. The two related config keys in a profile: - `state_dir` -> this is the same as it has been; a custom directory for where state files will be stored - `state_opt_out` -> this is a new key. If it's `true` or `1`, state files will not be used **Note**: the `gnu` build failures are already happening on `main` and have been brought up internally ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
- Loading branch information
1 parent
8e9e8f1
commit 9e4df97
Showing
6 changed files
with
105 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
use std::path::PathBuf; | ||
|
||
use color_eyre::eyre::Result; | ||
use color_eyre::eyre::{bail, Result}; | ||
use directories::BaseDirs; | ||
|
||
use crate::DEFAULT_CONFIG_DIRECTORY; | ||
|
||
pub(crate) const DEFAULT_STATE_DIRECTORY: &str = "state"; | ||
|
||
pub(crate) fn get_state_file( | ||
state_dir: Option<PathBuf>, | ||
access_token_id: String, | ||
) -> Result<Option<PathBuf>> { | ||
if let Some(mut state_dir) = state_dir { | ||
std::fs::create_dir_all(&state_dir)?; | ||
state_dir.push(access_token_id); | ||
) -> Result<PathBuf> { | ||
let mut state_dir = match state_dir { | ||
Some(state_dir) => state_dir, | ||
None => { | ||
if let Some(base_dirs) = BaseDirs::new() { | ||
base_dirs | ||
.home_dir() | ||
.join(DEFAULT_CONFIG_DIRECTORY) | ||
.join(DEFAULT_STATE_DIRECTORY) | ||
} else { | ||
bail!("A valid home directory doesn't exist"); | ||
} | ||
} | ||
}; | ||
|
||
return Ok(Some(state_dir)); | ||
} | ||
std::fs::create_dir_all(&state_dir)?; | ||
state_dir.push(access_token_id); | ||
|
||
Ok(None) | ||
Ok(state_dir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const STRING_TO_BOOL_ERROR_MESSAGE: &str = "Could not convert string to bool"; | ||
|
||
pub(crate) fn string_to_bool(value: &str) -> Result<bool, &str> { | ||
match value.trim().to_lowercase().as_str() { | ||
"true" | "1" => Ok(true), | ||
"false" | "0" => Ok(false), | ||
_ => Err(STRING_TO_BOOL_ERROR_MESSAGE), | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_string_to_bool_true_true() { | ||
let result = string_to_bool("true"); | ||
assert_eq!(result, Ok(true)); | ||
} | ||
|
||
#[test] | ||
fn test_string_to_bool_one_true() { | ||
let result = string_to_bool("1"); | ||
assert_eq!(result, Ok(true)); | ||
} | ||
|
||
#[test] | ||
fn test_string_to_bool_false_false() { | ||
let result = string_to_bool("false"); | ||
assert_eq!(result, Ok(false)); | ||
} | ||
|
||
#[test] | ||
fn test_string_to_bool_zero_false() { | ||
let result = string_to_bool("0"); | ||
assert_eq!(result, Ok(false)); | ||
} | ||
|
||
#[test] | ||
fn test_string_to_bool_bad_string_errors() { | ||
let result = string_to_bool("hello world"); | ||
assert_eq!(result, Err(STRING_TO_BOOL_ERROR_MESSAGE)); | ||
} | ||
} |