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