mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 16:44:09 +02:00
better handling of postgres options
This commit is contained in:
parent
484af6a8e7
commit
a8f4622c1a
5 changed files with 86 additions and 37 deletions
25
src/lib.rs
25
src/lib.rs
|
|
@ -1,6 +1,7 @@
|
|||
mod nc;
|
||||
|
||||
use form_urlencoded::Serializer;
|
||||
use indexmap::IndexMap;
|
||||
use itertools::Either;
|
||||
use miette::Diagnostic;
|
||||
use std::iter::once;
|
||||
|
|
@ -192,7 +193,7 @@ pub enum NotAConfigError {
|
|||
NotAnArray(PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SslOptions {
|
||||
Enabled {
|
||||
key: String,
|
||||
|
|
@ -204,7 +205,7 @@ pub enum SslOptions {
|
|||
Default,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Database {
|
||||
Sqlite {
|
||||
database: PathBuf,
|
||||
|
|
@ -221,11 +222,11 @@ pub enum Database {
|
|||
username: String,
|
||||
password: String,
|
||||
connect: DbConnect,
|
||||
ssl_options: SslOptions,
|
||||
options: IndexMap<String, String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DbConnect {
|
||||
Tcp { host: String, port: u16 },
|
||||
Socket(PathBuf),
|
||||
|
|
@ -300,21 +301,11 @@ impl Database {
|
|||
username,
|
||||
password,
|
||||
connect,
|
||||
ssl_options,
|
||||
options,
|
||||
} => {
|
||||
let mut params = Serializer::new(String::new());
|
||||
match ssl_options {
|
||||
SslOptions::Default => {}
|
||||
SslOptions::Disabled => {
|
||||
params.append_pair("sslmode", "disable");
|
||||
}
|
||||
SslOptions::Enabled { ca, verify, .. } => {
|
||||
params.append_pair(
|
||||
"ssl-mode",
|
||||
if *verify { "verify-full" } else { "verify-ca" },
|
||||
);
|
||||
params.append_pair("sslrootcert", ca.as_str());
|
||||
}
|
||||
for (key, value) in options {
|
||||
params.append_pair(key.as_str(), value.as_str());
|
||||
}
|
||||
let (host, port) = match connect {
|
||||
DbConnect::Socket(socket) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue