keyring support for linux

This commit is contained in:
veeso
2021-06-20 15:04:16 +02:00
parent 15d13af7d5
commit 19610479bd
6 changed files with 16 additions and 13 deletions

View File

@@ -21,7 +21,7 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --all-features --no-fail-fast args: --no-default-features --features githubActions --features with-containers --no-fail-fast
env: env:
CARGO_INCREMENTAL: "0" CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests" RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"

View File

@@ -19,7 +19,7 @@ jobs:
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --all-features --no-fail-fast args: --no-default-features --features githubActions --features with-containers --no-fail-fast
- name: Format - name: Format
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
- name: Clippy - name: Clippy

View File

@@ -70,6 +70,7 @@ features = ["json"]
version = "2.1.0" version = "2.1.0"
[features] [features]
default = [ "with-keyring" ]
githubActions = [] githubActions = []
with-containers = [] with-containers = []
with-keyring = [ "keyring" ] with-keyring = [ "keyring" ]
@@ -78,10 +79,6 @@ with-keyring = [ "keyring" ]
[target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies] [target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies]
users = "0.11.0" users = "0.11.0"
[target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))"]
[target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))".features]
default = [ "keyring" ]
[target."cfg(target_os = \"windows\")"] [target."cfg(target_os = \"windows\")"]
[target."cfg(target_os = \"windows\")".dependencies] [target."cfg(target_os = \"windows\")".dependencies]
path-slash = "0.1.4" path-slash = "0.1.4"

View File

@@ -28,7 +28,7 @@
// Deps // Deps
extern crate whoami; extern crate whoami;
// Crate // Crate
#[cfg(any(target_os = "windows", target_os = "macos"))] #[cfg(feature = "with-keyring")]
use super::keys::keyringstorage::KeyringStorage; use super::keys::keyringstorage::KeyringStorage;
use super::keys::{filestorage::FileStorage, KeyStorage, KeyStorageError}; use super::keys::{filestorage::FileStorage, KeyStorage, KeyStorageError};
// Local // Local
@@ -69,8 +69,8 @@ impl BookmarksClient {
// Create default hosts // Create default hosts
let default_hosts: UserHosts = Default::default(); let default_hosts: UserHosts = Default::default();
debug!("Setting up bookmarks client..."); debug!("Setting up bookmarks client...");
// Make a key storage (windows / macos) // Make a key storage (with-keyring)
#[cfg(any(target_os = "windows", target_os = "macos"))] #[cfg(feature = "with-keyring")]
let (key_storage, service_id): (Box<dyn KeyStorage>, &str) = { let (key_storage, service_id): (Box<dyn KeyStorage>, &str) = {
debug!("Setting up KeyStorage"); debug!("Setting up KeyStorage");
let username: String = whoami::username(); let username: String = whoami::username();
@@ -91,8 +91,8 @@ impl BookmarksClient {
} }
} }
}; };
// Make a key storage (linux / unix) // Make a key storage (wno-keyring)
#[cfg(any(target_os = "linux", target_os = "unix"))] #[cfg(not(feature = "with-keyring"))]
let (key_storage, service_id): (Box<dyn KeyStorage>, &str) = { let (key_storage, service_id): (Box<dyn KeyStorage>, &str) = {
#[cfg(not(test))] #[cfg(not(test))]
let app_name: &str = "bookmarks"; let app_name: &str = "bookmarks";

View File

@@ -67,7 +67,7 @@ impl KeyStorage for KeyringStorage {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
KeyringError::MacOsKeychainError(_) => Err(KeyStorageError::NoSuchKey), KeyringError::MacOsKeychainError(_) => Err(KeyStorageError::NoSuchKey),
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
KeyringError::SecretServiceError(SsError) => Err(KeyStorageError::ProviderError), KeyringError::SecretServiceError(_) => Err(KeyStorageError::ProviderError),
KeyringError::Parse(_) => Err(KeyStorageError::BadSytax), KeyringError::Parse(_) => Err(KeyStorageError::BadSytax),
_ => Err(KeyStorageError::ProviderError), _ => Err(KeyStorageError::ProviderError),
}, },
@@ -94,7 +94,13 @@ impl KeyStorage for KeyringStorage {
// Check what kind of error is returned // Check what kind of error is returned
match storage.get_password() { match storage.get_password() {
Ok(_) => true, Ok(_) => true,
#[cfg(not(target_os = "linux"))]
Err(err) => !matches!(err, KeyringError::NoBackendFound), Err(err) => !matches!(err, KeyringError::NoBackendFound),
#[cfg(target_os = "linux")]
Err(err) => !matches!(
err,
KeyringError::NoBackendFound | KeyringError::SecretServiceError(_)
),
} }
} }
} }

View File

@@ -27,7 +27,7 @@
*/ */
// Storages // Storages
pub mod filestorage; pub mod filestorage;
#[cfg(any(target_os = "windows", target_os = "macos"))] #[cfg(feature = "with-keyring")]
pub mod keyringstorage; pub mod keyringstorage;
// ext // ext
use thiserror::Error; use thiserror::Error;