feat(usable): integrate current dbtool implementation snapshot
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DatabaseKind {
|
||||
Postgres,
|
||||
Mysql,
|
||||
@@ -18,18 +20,20 @@ impl DatabaseKind {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum ConnectionTransport {
|
||||
Tcp { host: String, port: u16 },
|
||||
File { path: PathBuf },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ConnectionTarget {
|
||||
pub kind: DatabaseKind,
|
||||
pub transport: ConnectionTransport,
|
||||
pub database: Option<String>,
|
||||
pub username: Option<String>,
|
||||
#[serde(skip, default)]
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
@@ -142,9 +146,35 @@ impl InspectRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum SchemaAvailability {
|
||||
Ready,
|
||||
Restricted,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SchemaSummary {
|
||||
pub name: String,
|
||||
pub availability: SchemaAvailability,
|
||||
pub note: Option<String>,
|
||||
}
|
||||
|
||||
impl SchemaSummary {
|
||||
pub fn ready(name: impl Into<String>) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
availability: SchemaAvailability::Ready,
|
||||
note: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restricted(name: impl Into<String>, note: impl Into<String>) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
availability: SchemaAvailability::Restricted,
|
||||
note: Some(note.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -381,4 +411,30 @@ mod tests {
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn connection_target_serialization_omits_password() {
|
||||
let mut target = ConnectionTarget::new(
|
||||
DatabaseKind::Postgres,
|
||||
ConnectionTransport::Tcp {
|
||||
host: String::from("127.0.0.1"),
|
||||
port: 5432,
|
||||
},
|
||||
Some(String::from("qa_demo")),
|
||||
Some(String::from("dbtool")),
|
||||
)
|
||||
.expect("target should be valid");
|
||||
target.password = Some(String::from("secret"));
|
||||
|
||||
let json = serde_json::to_string(&target).expect("target should serialize");
|
||||
|
||||
assert!(!json.contains("secret"));
|
||||
assert!(!json.contains("password"));
|
||||
|
||||
let restored: ConnectionTarget =
|
||||
serde_json::from_str(&json).expect("target should deserialize");
|
||||
|
||||
assert_eq!(restored.password, None);
|
||||
assert_eq!(restored.kind, DatabaseKind::Postgres);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user