Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config support parse tls #446

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ sequentially if exists.
```
❯ cat ~/.bendsql/config.toml
[connection]
connect_timeout = "30s"
host = "127.0.0.1"
tls = false

[connection.args]
connect_timeout = "30"

[settings]
display_pretty_sql = true
Expand Down
2 changes: 2 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub struct ConnectionConfig {
pub port: Option<u16>,
pub user: String,
pub database: Option<String>,
pub tls: Option<bool>,
pub args: BTreeMap<String, String>,
}

Expand Down Expand Up @@ -261,6 +262,7 @@ impl Default for ConnectionConfig {
port: Some(8000),
user: "root".to_string(),
database: None,
tls: None,
args: BTreeMap::new(),
}
}
Expand Down
28 changes: 24 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct Args {
flight: bool,

#[clap(long, help = "Enable TLS, ignored when --dsn is set")]
tls: bool,
tls: Option<bool>,

#[clap(
short = 'h',
Expand Down Expand Up @@ -254,9 +254,16 @@ pub async fn main() -> Result<()> {
if !args.set.is_empty() {
eprintln!("warning: --set is ignored when --dsn is set");
}
if args.tls {
eprintln!("warning: --tls is ignored when --dsn is set");
if let Some(tls) = args.tls {
if tls {
eprintln!("warning: --tls is ignored when --dsn is set");
}
} else if let Some(tls) = config.connection.tls {
if tls {
eprintln!("warning: --tls is ignored when --dsn is set")
}
}

if args.flight {
eprintln!("warning: --flight is ignored when --dsn is set");
}
Expand Down Expand Up @@ -292,7 +299,20 @@ pub async fn main() -> Result<()> {

// override only if args.dsn is none
if args.dsn.is_none() {
if !args.tls {
if let Some(tls) = args.tls {
if !tls {
conn_args
.args
.insert("sslmode".to_string(), "disable".to_string());
}
} else if let Some(tls) = config.connection.tls {
if !tls {
conn_args
.args
.insert("sslmode".to_string(), "disable".to_string());
}
} else if config.connection.tls.is_none() {
// means arg.tls is none and not config in config.toml
conn_args
.args
.insert("sslmode".to_string(), "disable".to_string());
Expand Down
Loading