chore(core): fix rustfmt drift
This commit is contained in:
3 files changed
+35
-119
No files matched your search
@@ -14,8 +14,8 @@ use std::net::{IpAddr, Ipv4Addr};
|
||||
use crate::ai::AiConfigItem;
|
||||
use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_API_KEY_VALUE_KEY,
|
||||
MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY,
|
||||
NACOS_AUTH_PASSWORD_KEY, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||
MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||
};
|
||||
use crate::models::connection::{ConnectionConfig, DatabaseType, TransportLayerConfig};
|
||||
use crate::saved_sql::SavedSqlLibrary;
|
||||
@@ -1115,20 +1115,8 @@ fn push_cassandra_tls_secrets(secrets: &mut Vec<ConnectionSecretSnapshot>, confi
|
||||
else {
|
||||
return;
|
||||
};
|
||||
push_json_secret(
|
||||
secrets,
|
||||
&config.id,
|
||||
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
tls,
|
||||
"truststore_password",
|
||||
);
|
||||
push_json_secret(
|
||||
secrets,
|
||||
&config.id,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
tls,
|
||||
"keystore_password",
|
||||
);
|
||||
push_json_secret(secrets, &config.id, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, tls, "truststore_password");
|
||||
push_json_secret(secrets, &config.id, CASSANDRA_KEYSTORE_PASSWORD_KEY, tls, "keystore_password");
|
||||
}
|
||||
|
||||
fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||
@@ -2234,11 +2222,8 @@ mod tests {
|
||||
let config = cassandra_connection("cassandra");
|
||||
let mut public_config = config.clone();
|
||||
scrub_connection_secrets(&mut public_config);
|
||||
let tls = public_config
|
||||
.external_config
|
||||
.as_ref()
|
||||
.and_then(|external_config| external_config.get("tls"))
|
||||
.unwrap();
|
||||
let tls =
|
||||
public_config.external_config.as_ref().and_then(|external_config| external_config.get("tls")).unwrap();
|
||||
assert_eq!(tls["truststore_password"], "");
|
||||
assert_eq!(tls["keystore_password"], "");
|
||||
|
||||
|
||||
@@ -560,10 +560,7 @@ fn scrub_mq_token_signing_secret(config: &mut ConnectionConfig) {
|
||||
scrub_json_secret(signing, "key");
|
||||
}
|
||||
|
||||
fn persist_cassandra_tls_secrets(
|
||||
store: &dyn ConnectionSecretStore,
|
||||
config: &ConnectionConfig,
|
||||
) -> Result<(), String> {
|
||||
fn persist_cassandra_tls_secrets(store: &dyn ConnectionSecretStore, config: &ConnectionConfig) -> Result<(), String> {
|
||||
if config.db_type != DatabaseType::Cassandra {
|
||||
return delete_secret_prefix(store, &config.id, CASSANDRA_TLS_SECRET_PREFIX);
|
||||
}
|
||||
@@ -574,17 +571,13 @@ fn persist_cassandra_tls_secrets(
|
||||
store,
|
||||
&config.id,
|
||||
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
tls.get("truststore_password")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or(""),
|
||||
tls.get("truststore_password").and_then(serde_json::Value::as_str).unwrap_or(""),
|
||||
)?;
|
||||
persist_secret(
|
||||
store,
|
||||
&config.id,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
tls.get("keystore_password")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or(""),
|
||||
tls.get("keystore_password").and_then(serde_json::Value::as_str).unwrap_or(""),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -608,14 +601,7 @@ fn hydrate_cassandra_tls_secrets(
|
||||
"truststore_password",
|
||||
needs_rewrite,
|
||||
)?;
|
||||
hydrate_json_secret(
|
||||
store,
|
||||
&connection_id,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
tls,
|
||||
"keystore_password",
|
||||
needs_rewrite,
|
||||
)
|
||||
hydrate_json_secret(store, &connection_id, CASSANDRA_KEYSTORE_PASSWORD_KEY, tls, "keystore_password", needs_rewrite)
|
||||
}
|
||||
|
||||
fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||
@@ -629,9 +615,7 @@ fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||
scrub_json_secret(tls, "keystore_password");
|
||||
}
|
||||
|
||||
fn cassandra_tls_object(
|
||||
value: Option<&serde_json::Value>,
|
||||
) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||
fn cassandra_tls_object(value: Option<&serde_json::Value>) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||
value?.get("tls")?.as_object()
|
||||
}
|
||||
|
||||
@@ -845,11 +829,10 @@ pub fn secret_account(connection_id: &str, key: &str) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
load_connections_from_file, save_connections_to_file, ConnectionSecretStore,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
CONNECTION_STRING_KEY, INIT_SCRIPT_KEY, MAIN_PASSWORD_KEY, MQTT_AUTH_PASSWORD_KEY,
|
||||
MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, REDIS_SENTINEL_PASSWORD_KEY,
|
||||
SSH_PASSWORD_KEY,
|
||||
load_connections_from_file, save_connections_to_file, ConnectionSecretStore, CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
CASSANDRA_TRUSTSTORE_PASSWORD_KEY, CONNECTION_STRING_KEY, INIT_SCRIPT_KEY, MAIN_PASSWORD_KEY,
|
||||
MQTT_AUTH_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY,
|
||||
REDIS_SENTINEL_PASSWORD_KEY, SSH_PASSWORD_KEY,
|
||||
};
|
||||
use crate::models::connection::{
|
||||
ConnectionConfig, DatabaseType, HttpTunnelConfig, SshTunnelConfig, TransportLayerConfig,
|
||||
@@ -1234,38 +1217,16 @@ mod tests {
|
||||
|
||||
save_connections_to_file(&path, &[config], &store).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
store
|
||||
.get_existing("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY)
|
||||
.as_deref(),
|
||||
Some("trust-secret")
|
||||
);
|
||||
assert_eq!(
|
||||
store
|
||||
.get_existing("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY)
|
||||
.as_deref(),
|
||||
Some("key-secret")
|
||||
);
|
||||
assert_eq!(store.get_existing("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY).as_deref(), Some("trust-secret"));
|
||||
assert_eq!(store.get_existing("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY).as_deref(), Some("key-secret"));
|
||||
let persisted_json = std::fs::read_to_string(&path).unwrap();
|
||||
assert!(!persisted_json.contains("trust-secret"));
|
||||
assert!(!persisted_json.contains("key-secret"));
|
||||
|
||||
let loaded = load_connections_from_file(&path, &store).unwrap();
|
||||
let tls = loaded[0]
|
||||
.external_config
|
||||
.as_ref()
|
||||
.and_then(|value| value.get("tls"))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
tls.get("truststore_password")
|
||||
.and_then(serde_json::Value::as_str),
|
||||
Some("trust-secret")
|
||||
);
|
||||
assert_eq!(
|
||||
tls.get("keystore_password")
|
||||
.and_then(serde_json::Value::as_str),
|
||||
Some("key-secret")
|
||||
);
|
||||
let tls = loaded[0].external_config.as_ref().and_then(|value| value.get("tls")).unwrap();
|
||||
assert_eq!(tls.get("truststore_password").and_then(serde_json::Value::as_str), Some("trust-secret"));
|
||||
assert_eq!(tls.get("keystore_password").and_then(serde_json::Value::as_str), Some("key-secret"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3869,22 +3869,12 @@ impl Storage {
|
||||
let Some(tls) = cassandra_tls_object_mut(config.external_config.as_mut()) else {
|
||||
return Ok(false);
|
||||
};
|
||||
let truststore_rewrite = hydrate_mq_json_secret(
|
||||
self,
|
||||
connection_id,
|
||||
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
tls,
|
||||
"truststore_password",
|
||||
)
|
||||
.await?;
|
||||
let keystore_rewrite = hydrate_mq_json_secret(
|
||||
self,
|
||||
connection_id,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
tls,
|
||||
"keystore_password",
|
||||
)
|
||||
.await?;
|
||||
let truststore_rewrite =
|
||||
hydrate_mq_json_secret(self, connection_id, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, tls, "truststore_password")
|
||||
.await?;
|
||||
let keystore_rewrite =
|
||||
hydrate_mq_json_secret(self, connection_id, CASSANDRA_KEYSTORE_PASSWORD_KEY, tls, "keystore_password")
|
||||
.await?;
|
||||
Ok(truststore_rewrite || keystore_rewrite)
|
||||
}
|
||||
}
|
||||
@@ -5169,17 +5159,13 @@ fn persist_cassandra_tls_secrets_in_tx(
|
||||
tx,
|
||||
&config.id,
|
||||
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
tls.get("truststore_password")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or(""),
|
||||
tls.get("truststore_password").and_then(serde_json::Value::as_str).unwrap_or(""),
|
||||
)?;
|
||||
persist_secret_in_tx(
|
||||
tx,
|
||||
&config.id,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||
tls.get("keystore_password")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or(""),
|
||||
tls.get("keystore_password").and_then(serde_json::Value::as_str).unwrap_or(""),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5244,9 +5230,7 @@ fn mq_token_signing_object_mut(
|
||||
value?.get_mut("tokenSigning")?.as_object_mut()
|
||||
}
|
||||
|
||||
fn cassandra_tls_object(
|
||||
value: Option<&serde_json::Value>,
|
||||
) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||
fn cassandra_tls_object(value: Option<&serde_json::Value>) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||
value?.get("tls")?.as_object()
|
||||
}
|
||||
|
||||
@@ -5315,8 +5299,8 @@ mod tests {
|
||||
};
|
||||
use crate::connection_secrets::NACOS_RNACOS_CONSOLE_PASSWORD_KEY;
|
||||
use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY,
|
||||
MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY,
|
||||
MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
};
|
||||
use crate::history::{HistoryConnectionFilter, HistoryDatabaseFilter, HistoryEntry, HistorySearchRequest};
|
||||
use crate::models::connection::{
|
||||
@@ -5962,19 +5946,11 @@ mod tests {
|
||||
assert!(!raw_json.contains("trust-secret"));
|
||||
assert!(!raw_json.contains("key-secret"));
|
||||
assert_eq!(
|
||||
storage
|
||||
.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY)
|
||||
.await
|
||||
.unwrap()
|
||||
.as_deref(),
|
||||
storage.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY).await.unwrap().as_deref(),
|
||||
Some("trust-secret")
|
||||
);
|
||||
assert_eq!(
|
||||
storage
|
||||
.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY)
|
||||
.await
|
||||
.unwrap()
|
||||
.as_deref(),
|
||||
storage.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY).await.unwrap().as_deref(),
|
||||
Some("key-secret")
|
||||
);
|
||||
|
||||
@@ -5987,14 +5963,8 @@ mod tests {
|
||||
disabled.ssl = false;
|
||||
disabled.external_config = None;
|
||||
storage.save_connections(&[disabled]).await.unwrap();
|
||||
assert_eq!(
|
||||
storage.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY).await.unwrap(),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
storage.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY).await.unwrap(),
|
||||
None
|
||||
);
|
||||
assert_eq!(storage.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY).await.unwrap(), None);
|
||||
assert_eq!(storage.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY).await.unwrap(), None);
|
||||
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user