style: applied uniform formatting across library code
Check / stable / fmt (push) Failing after 24s
Check / beta / clippy (push) Failing after 42s
Check / stable / clippy (push) Failing after 41s
Check / nightly / doc (push) Failing after 41s
Check / 1.89.0 / check (push) Failing after 44s
Test Suite / ubuntu / beta (push) Failing after 44s
Test Suite / ubuntu / stable (push) Failing after 44s
Test Suite / ubuntu / stable / coverage (push) Failing after 1m14s
Test Suite / macos-latest / stable (push) Has been cancelled
Test Suite / windows-latest / stable (push) Has been cancelled
Check / stable / fmt (push) Failing after 24s
Check / beta / clippy (push) Failing after 42s
Check / stable / clippy (push) Failing after 41s
Check / nightly / doc (push) Failing after 41s
Check / 1.89.0 / check (push) Failing after 44s
Test Suite / ubuntu / beta (push) Failing after 44s
Test Suite / ubuntu / stable (push) Failing after 44s
Test Suite / ubuntu / stable / coverage (push) Failing after 1m14s
Test Suite / macos-latest / stable (push) Has been cancelled
Test Suite / windows-latest / stable (push) Has been cancelled
This commit is contained in:
@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::providers::error::{SecretError, classify_aws_error};
|
||||
use crate::providers::SecretProvider;
|
||||
use crate::providers::error::{SecretError, classify_aws_error};
|
||||
|
||||
const PROVIDER: &str = "aws_secrets_manager";
|
||||
|
||||
@@ -120,7 +120,10 @@ impl AwsSecretsManagerProvider {
|
||||
provider: PROVIDER,
|
||||
message: "aws_region is required".to_string(),
|
||||
})?;
|
||||
let profile = self.aws_profile.clone().ok_or_else(|| SecretError::Config {
|
||||
let profile = self
|
||||
.aws_profile
|
||||
.clone()
|
||||
.ok_or_else(|| SecretError::Config {
|
||||
provider: PROVIDER,
|
||||
message: "aws_profile is required".to_string(),
|
||||
})?;
|
||||
|
||||
@@ -67,9 +67,9 @@ impl SecretProvider for AzureKeyVaultProvider {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let body = params
|
||||
.try_into()
|
||||
.map_err(|e: azure_core::Error| classify_azure_error(e.into(), Some(key), "set_secret"))?;
|
||||
let body = params.try_into().map_err(|e: azure_core::Error| {
|
||||
classify_azure_error(e.into(), Some(key), "set_secret")
|
||||
})?;
|
||||
|
||||
self.get_client()?
|
||||
.set_secret(key, body, None)
|
||||
@@ -123,7 +123,10 @@ impl AzureKeyVaultProvider {
|
||||
provider: PROVIDER,
|
||||
source: e.into(),
|
||||
})?;
|
||||
let vault_name = self.vault_name.as_ref().ok_or_else(|| SecretError::Config {
|
||||
let vault_name = self
|
||||
.vault_name
|
||||
.as_ref()
|
||||
.ok_or_else(|| SecretError::Config {
|
||||
provider: PROVIDER,
|
||||
message: "vault_name is required".to_string(),
|
||||
})?;
|
||||
|
||||
+29
-8
@@ -1,5 +1,5 @@
|
||||
use std::io;
|
||||
use anyhow::anyhow;
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::providers::git_sync::SyncError;
|
||||
@@ -105,13 +105,19 @@ pub(crate) fn classify_aws_error(
|
||||
|| chain_text.contains("unauthorized")
|
||||
|| chain_text.contains("unrecognizedclient")
|
||||
{
|
||||
SecretError::AuthFailed { provider, source: err }
|
||||
SecretError::AuthFailed {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else if chain_text.contains("dispatch failure")
|
||||
|| chain_text.contains("timeout")
|
||||
|| chain_text.contains("connection")
|
||||
|| chain_text.contains("dns")
|
||||
{
|
||||
SecretError::Network { provider, source: err }
|
||||
SecretError::Network {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else {
|
||||
SecretError::Other(err)
|
||||
}
|
||||
@@ -165,9 +171,15 @@ pub(crate) fn classify_gcp_error(
|
||||
provider,
|
||||
}
|
||||
} else if chain_text.contains("unauthenticated") || chain_text.contains("permissiondenied") {
|
||||
SecretError::AuthFailed { provider, source: err }
|
||||
SecretError::AuthFailed {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else if chain_text.contains("unavailable") || chain_text.contains("deadlineexceeded") {
|
||||
SecretError::Network { provider, source: err }
|
||||
SecretError::Network {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else {
|
||||
SecretError::Other(err)
|
||||
}
|
||||
@@ -185,7 +197,10 @@ pub(crate) fn classify_azure_error(
|
||||
if let ErrorKind::HttpResponse { status, .. } = azure_err.kind() {
|
||||
let code = u16::from(*status);
|
||||
return match code {
|
||||
401 | 403 => SecretError::AuthFailed { provider, source: err },
|
||||
401 | 403 => SecretError::AuthFailed {
|
||||
provider,
|
||||
source: err,
|
||||
},
|
||||
404 => SecretError::NotFound {
|
||||
key: key.unwrap_or("").to_string(),
|
||||
provider,
|
||||
@@ -213,12 +228,18 @@ pub(crate) fn classify_azure_error(
|
||||
|| chain_text.contains("403")
|
||||
|| chain_text.contains("authentication")
|
||||
{
|
||||
SecretError::AuthFailed { provider, source: err }
|
||||
SecretError::AuthFailed {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else if chain_text.contains("timeout")
|
||||
|| chain_text.contains("connection")
|
||||
|| chain_text.contains("dns")
|
||||
{
|
||||
SecretError::Network { provider, source: err }
|
||||
SecretError::Network {
|
||||
provider,
|
||||
source: err,
|
||||
}
|
||||
} else {
|
||||
SecretError::Other(err)
|
||||
}
|
||||
|
||||
@@ -72,9 +72,8 @@ impl SecretProvider for GcpSecretManagerProvider {
|
||||
provider: PROVIDER,
|
||||
})?;
|
||||
let secret_value = payload.data.ref_sensitive_value().to_vec();
|
||||
let secret_string = String::from_utf8(secret_value).map_err(|_| {
|
||||
SecretError::Other(anyhow!("secret value is not valid UTF-8"))
|
||||
})?;
|
||||
let secret_string = String::from_utf8(secret_value)
|
||||
.map_err(|_| SecretError::Other(anyhow!("secret value is not valid UTF-8")))?;
|
||||
|
||||
Ok(secret_string)
|
||||
}
|
||||
|
||||
+11
-20
@@ -1,13 +1,13 @@
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{env, fs};
|
||||
use anyhow::anyhow;
|
||||
use chrono::Utc;
|
||||
use dialoguer::Confirm;
|
||||
use dialoguer::theme::ColorfulTheme;
|
||||
use indoc::formatdoc;
|
||||
use log::debug;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{env, fs};
|
||||
use thiserror::Error;
|
||||
use validator::Validate;
|
||||
|
||||
@@ -78,9 +78,11 @@ pub fn sync_and_push(opts: &SyncOpts<'_>) -> SyncResult<()> {
|
||||
let repo_dir = config_dir.join(format!(".{}", repo_name));
|
||||
fs::create_dir_all(&repo_dir)?;
|
||||
|
||||
let default_vault = confy::get_configuration_file_path(&calling_app_name(), "vault")
|
||||
.map_err(|e| SyncError::Config {
|
||||
let default_vault =
|
||||
confy::get_configuration_file_path(&calling_app_name(), "vault").map_err(|e| {
|
||||
SyncError::Config {
|
||||
message: format!("get default vault path: {}", e),
|
||||
}
|
||||
})?;
|
||||
let repo_vault = repo_dir.join("vault.yml");
|
||||
if default_vault.exists() && !repo_vault.exists() {
|
||||
@@ -156,9 +158,7 @@ fn resolve_git_email(git: &Path, email: Option<&String>) -> SyncResult<String> {
|
||||
})
|
||||
}
|
||||
|
||||
pub(in crate::providers) fn resolve_git(
|
||||
override_path: Option<&PathBuf>,
|
||||
) -> SyncResult<PathBuf> {
|
||||
pub(in crate::providers) fn resolve_git(override_path: Option<&PathBuf>) -> SyncResult<PathBuf> {
|
||||
debug!("Resolving git executable");
|
||||
if let Some(p) = override_path {
|
||||
return Ok(p.to_path_buf());
|
||||
@@ -199,11 +199,7 @@ pub(in crate::providers) fn ensure_git_available(git: &Path) -> SyncResult<()> {
|
||||
}
|
||||
|
||||
fn run_git(git: &Path, repo: &Path, args: &[&str]) -> SyncResult<()> {
|
||||
let out = Command::new(git)
|
||||
.arg("-C")
|
||||
.arg(repo)
|
||||
.args(args)
|
||||
.output()?;
|
||||
let out = Command::new(git).arg("-C").arg(repo).args(args).output()?;
|
||||
|
||||
if !out.status.success() {
|
||||
return Err(SyncError::GitCommandFailed {
|
||||
@@ -305,12 +301,7 @@ fn init_repo_if_needed(git: &Path, repo: &Path, branch: &str) -> SyncResult<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_local_identity(
|
||||
git: &Path,
|
||||
repo: &Path,
|
||||
username: String,
|
||||
email: String,
|
||||
) -> SyncResult<()> {
|
||||
fn set_local_identity(git: &Path, repo: &Path, username: String, email: String) -> SyncResult<()> {
|
||||
run_git(git, repo, &["config", "user.name", &username]).map_err(|e| SyncError::Config {
|
||||
message: format!("failed to set git user.name: {}", e),
|
||||
})?;
|
||||
|
||||
+7
-12
@@ -128,8 +128,7 @@ impl SecretProvider for LocalProvider {
|
||||
}
|
||||
|
||||
let password = self.get_password()?;
|
||||
let envelope =
|
||||
encrypt_string(&password, value).map_err(SecretError::Other)?;
|
||||
let envelope = encrypt_string(&password, value).map_err(SecretError::Other)?;
|
||||
drop(password);
|
||||
|
||||
vault.insert(key.to_string(), envelope);
|
||||
@@ -142,8 +141,7 @@ impl SecretProvider for LocalProvider {
|
||||
let mut vault: HashMap<String, String> = load_vault(&vault_path).unwrap_or_default();
|
||||
|
||||
let password = self.get_password()?;
|
||||
let envelope =
|
||||
encrypt_string(&password, value).map_err(SecretError::Other)?;
|
||||
let envelope = encrypt_string(&password, value).map_err(SecretError::Other)?;
|
||||
drop(password);
|
||||
|
||||
if vault.contains_key(key) {
|
||||
@@ -373,12 +371,8 @@ impl LocalProvider {
|
||||
}
|
||||
}
|
||||
|
||||
let password = SecretString::new(
|
||||
fs::read_to_string(password_file)?
|
||||
.trim()
|
||||
.to_string()
|
||||
.into(),
|
||||
);
|
||||
let password =
|
||||
SecretString::new(fs::read_to_string(password_file)?.trim().to_string().into());
|
||||
|
||||
Ok(password)
|
||||
} else {
|
||||
@@ -600,10 +594,11 @@ fn decrypt_string(password: &SecretString, envelope: &str) -> LocalResult<String
|
||||
|
||||
let aad_current = format!("{};{};{};m={},t={},p={}", HEADER, VERSION, KDF, m, t, p);
|
||||
|
||||
let mut key = derive_key_with_params(password, &salt, m, t, p)
|
||||
.map_err(|source| SecretError::AuthFailed {
|
||||
let mut key = derive_key_with_params(password, &salt, m, t, p).map_err(|source| {
|
||||
SecretError::AuthFailed {
|
||||
provider: PROVIDER,
|
||||
source,
|
||||
}
|
||||
})?;
|
||||
let cipher = XChaCha20Poly1305::new(&key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user