mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
remove redis-connect feature
This commit is contained in:
parent
10b7d8eb56
commit
88db1d1d86
5 changed files with 151 additions and 104 deletions
65
Cargo.lock
generated
65
Cargo.lock
generated
|
|
@ -681,9 +681,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.169"
|
version = "0.2.172"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
|
|
@ -1103,9 +1103,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redis"
|
name = "redis"
|
||||||
version = "0.28.1"
|
version = "0.30.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f89727cba9cec05cc579942321ff6dd09fe57a8b3217f52f952301efa010da5"
|
checksum = "438a4e5f8e9aa246d6f3666d6978441bf1b37d5f417b50c4dd220be09f5fcc17"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
"combine",
|
"combine",
|
||||||
|
|
@ -1113,6 +1113,8 @@ dependencies = [
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
"sha1_smol",
|
||||||
|
"socket2",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1273,6 +1275,12 @@ dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1_smol"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.8"
|
version = "0.10.8"
|
||||||
|
|
@ -1318,6 +1326,16 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.5.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "spin"
|
||||||
version = "0.9.8"
|
version = "0.9.8"
|
||||||
|
|
@ -1339,9 +1357,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx"
|
name = "sqlx"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3c3a85280daca669cfd3bcb68a337882a8bc57ec882f72c5d13a430613a738e"
|
checksum = "4410e73b3c0d8442c5f99b425d7a435b5ee0ae4167b3196771dd3f7a01be745f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"sqlx-macros",
|
"sqlx-macros",
|
||||||
|
|
@ -1352,11 +1370,10 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-core"
|
name = "sqlx-core"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f743f2a3cea30a58cd479013f75550e879009e3a02f616f18ca699335aa248c3"
|
checksum = "6a007b6936676aa9ab40207cde35daab0a04b823be8ae004368c0793b96a61e0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
|
||||||
"bytes",
|
"bytes",
|
||||||
"crc",
|
"crc",
|
||||||
"crossbeam-queue",
|
"crossbeam-queue",
|
||||||
|
|
@ -1384,9 +1401,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-macros"
|
name = "sqlx-macros"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f4200e0fde19834956d4252347c12a083bdcb237d7a1a1446bffd8768417dce"
|
checksum = "3112e2ad78643fef903618d78cf0aec1cb3134b019730edb039b69eaf531f310"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -1397,9 +1414,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-macros-core"
|
name = "sqlx-macros-core"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "882ceaa29cade31beca7129b6beeb05737f44f82dbe2a9806ecea5a7093d00b7"
|
checksum = "4e9f90acc5ab146a99bf5061a7eb4976b573f560bc898ef3bf8435448dd5e7ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"either",
|
"either",
|
||||||
|
|
@ -1422,9 +1439,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-mysql"
|
name = "sqlx-mysql"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0afdd3aa7a629683c2d750c2df343025545087081ab5942593a5288855b1b7a7"
|
checksum = "4560278f0e00ce64938540546f59f590d60beee33fffbd3b9cd47851e5fff233"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atoi",
|
"atoi",
|
||||||
"base64",
|
"base64",
|
||||||
|
|
@ -1464,9 +1481,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-postgres"
|
name = "sqlx-postgres"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a0bedbe1bbb5e2615ef347a5e9d8cd7680fb63e77d9dafc0f29be15e53f1ebe6"
|
checksum = "c5b98a57f363ed6764d5b3a12bfedf62f07aa16e1856a7ddc2a0bb190a959613"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atoi",
|
"atoi",
|
||||||
"base64",
|
"base64",
|
||||||
|
|
@ -1501,9 +1518,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sqlx-sqlite"
|
name = "sqlx-sqlite"
|
||||||
version = "0.8.5"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c26083e9a520e8eb87a06b12347679b142dc2ea29e6e409f805644a7a979a5bc"
|
checksum = "f85ca71d3a5b24e64e1d08dd8fe36c6c95c339a896cc33068148906784620540"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atoi",
|
"atoi",
|
||||||
"flume",
|
"flume",
|
||||||
|
|
@ -1518,7 +1535,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"thiserror 2.0.11",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
@ -1868,6 +1884,15 @@ dependencies = [
|
||||||
"windows-targets 0.48.5",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.59.0"
|
version = "0.59.0"
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,9 @@ edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/icewind1991/nextcloud-config-parser"
|
repository = "https://github.com/icewind1991/nextcloud-config-parser"
|
||||||
documentation = "https://docs.rs/nextcloud-config-parser"
|
documentation = "https://docs.rs/nextcloud-config-parser"
|
||||||
rust-version = "1.77.0"
|
rust-version = "1.81.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
redis = { version = "0.28.1", optional = true, default-features = false }
|
|
||||||
thiserror = "2.0.11"
|
thiserror = "2.0.11"
|
||||||
php-literal-parser = "0.6.2"
|
php-literal-parser = "0.6.2"
|
||||||
miette = "7.4.0"
|
miette = "7.4.0"
|
||||||
|
|
@ -20,6 +19,4 @@ form_urlencoded = "1.2.1"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
miette = { version = "7.4.0", features = ["fancy"] }
|
miette = { version = "7.4.0", features = ["fancy"] }
|
||||||
sqlx = { version = "0.8.3", default-features = false, features = ["any", "mysql", "sqlite", "postgres"] }
|
sqlx = { version = "0.8.3", default-features = false, features = ["any", "mysql", "sqlite", "postgres"] }
|
||||||
|
redis = "0.30.0"
|
||||||
[features]
|
|
||||||
redis-connect = ["redis"]
|
|
||||||
|
|
|
||||||
55
src/lib.rs
55
src/lib.rs
|
|
@ -2,9 +2,6 @@ mod nc;
|
||||||
|
|
||||||
use form_urlencoded::Serializer;
|
use form_urlencoded::Serializer;
|
||||||
use miette::Diagnostic;
|
use miette::Diagnostic;
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
use redis::{ConnectionAddr, ConnectionInfo};
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -15,22 +12,44 @@ pub use nc::{parse, parse_glob};
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
pub database_prefix: String,
|
pub database_prefix: String,
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
pub redis: RedisConfig,
|
pub redis: RedisConfig,
|
||||||
pub nextcloud_url: String,
|
pub nextcloud_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RedisConfig {
|
pub enum RedisConfig {
|
||||||
Single(ConnectionInfo),
|
Single(RedisConnectionInfo),
|
||||||
Cluster(Vec<ConnectionInfo>),
|
Cluster(Vec<RedisConnectionInfo>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum RedisConnectionAddr {
|
||||||
|
Tcp {
|
||||||
|
host: String,
|
||||||
|
port: u16,
|
||||||
|
},
|
||||||
|
TcpTls {
|
||||||
|
host: String,
|
||||||
|
port: u16,
|
||||||
|
insecure: bool,
|
||||||
|
tls_params: Option<String>,
|
||||||
|
},
|
||||||
|
Unix {
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct RedisConnectionInfo {
|
||||||
|
pub addr: RedisConnectionAddr,
|
||||||
|
pub db: i64,
|
||||||
|
pub username: Option<String>,
|
||||||
|
pub password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
impl RedisConfig {
|
impl RedisConfig {
|
||||||
pub fn addr(&self) -> impl Iterator<Item = &ConnectionAddr> {
|
pub fn addr(&self) -> impl Iterator<Item = &RedisConnectionAddr> {
|
||||||
let boxed: Box<dyn Iterator<Item = &ConnectionAddr>> = match self {
|
let boxed: Box<dyn Iterator<Item = &RedisConnectionAddr>> = match self {
|
||||||
RedisConfig::Single(conn) => Box::new(once(&conn.addr)),
|
RedisConfig::Single(conn) => Box::new(once(&conn.addr)),
|
||||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| &conn.addr)),
|
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| &conn.addr)),
|
||||||
};
|
};
|
||||||
|
|
@ -39,34 +58,32 @@ impl RedisConfig {
|
||||||
|
|
||||||
pub fn db(&self) -> i64 {
|
pub fn db(&self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
RedisConfig::Single(conn) => conn.redis.db,
|
RedisConfig::Single(conn) => conn.db,
|
||||||
RedisConfig::Cluster(conns) => {
|
RedisConfig::Cluster(conns) => conns.first().map(|conn| conn.db).unwrap_or_default(),
|
||||||
conns.first().map(|conn| conn.redis.db).unwrap_or_default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn username(&self) -> Option<&str> {
|
pub fn username(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
RedisConfig::Single(conn) => conn.redis.username.as_deref(),
|
RedisConfig::Single(conn) => conn.username.as_deref(),
|
||||||
RedisConfig::Cluster(conns) => conns
|
RedisConfig::Cluster(conns) => conns
|
||||||
.first()
|
.first()
|
||||||
.map(|conn| conn.redis.username.as_deref())
|
.map(|conn| conn.username.as_deref())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn passwd(&self) -> Option<&str> {
|
pub fn passwd(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
RedisConfig::Single(conn) => conn.redis.password.as_deref(),
|
RedisConfig::Single(conn) => conn.password.as_deref(),
|
||||||
RedisConfig::Cluster(conns) => conns
|
RedisConfig::Cluster(conns) => conns
|
||||||
.first()
|
.first()
|
||||||
.map(|conn| conn.redis.password.as_deref())
|
.map(|conn| conn.password.as_deref())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_vec(self) -> Vec<ConnectionInfo> {
|
pub fn into_vec(self) -> Vec<RedisConnectionInfo> {
|
||||||
match self {
|
match self {
|
||||||
RedisConfig::Single(conn) => vec![conn],
|
RedisConfig::Single(conn) => vec![conn],
|
||||||
RedisConfig::Cluster(vec) => vec,
|
RedisConfig::Cluster(vec) => vec,
|
||||||
|
|
|
||||||
55
src/nc.rs
55
src/nc.rs
|
|
@ -1,11 +1,9 @@
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
use crate::RedisConfig;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Config, Database, DbConnect, DbError, Error, NotAConfigError, PhpParseError, Result, SslOptions,
|
Config, Database, DbConnect, DbError, Error, NotAConfigError, PhpParseError,
|
||||||
|
RedisConnectionInfo, Result, SslOptions,
|
||||||
};
|
};
|
||||||
|
use crate::{RedisConfig, RedisConnectionAddr};
|
||||||
use php_literal_parser::Value;
|
use php_literal_parser::Value;
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
use redis::{ConnectionAddr, ConnectionInfo, RedisConnectionInfo};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::DirEntry;
|
use std::fs::DirEntry;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
|
|
@ -111,14 +109,12 @@ fn parse_files(files: impl IntoIterator<Item = PathBuf>) -> Result<Config> {
|
||||||
.clone()
|
.clone()
|
||||||
.into_string()
|
.into_string()
|
||||||
.ok_or(Error::NoUrl)?;
|
.ok_or(Error::NoUrl)?;
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
let redis = parse_redis_options(&parsed);
|
let redis = parse_redis_options(&parsed);
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
database,
|
database,
|
||||||
database_prefix,
|
database_prefix,
|
||||||
nextcloud_url,
|
nextcloud_url,
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
redis,
|
redis,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -299,30 +295,31 @@ fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
enum RedisAddress {
|
enum RedisAddress {
|
||||||
Single(ConnectionAddr),
|
Single(RedisConnectionAddr),
|
||||||
Cluster(Vec<ConnectionAddr>),
|
Cluster(Vec<RedisConnectionAddr>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
||||||
use redis::ProtocolVersion;
|
|
||||||
|
|
||||||
let (redis_options, address) = if parsed["redis.cluster"].is_array() {
|
let (redis_options, address) = if parsed["redis.cluster"].is_array() {
|
||||||
let redis_options = &parsed["redis.cluster"];
|
let redis_options = &parsed["redis.cluster"];
|
||||||
let seeds = redis_options["seeds"].values();
|
let seeds = redis_options["seeds"].values();
|
||||||
let addresses = seeds
|
let addresses = seeds
|
||||||
.filter_map(|seed| seed.as_str())
|
.filter_map(|seed| seed.as_str())
|
||||||
.map(split_host)
|
.map(split_host)
|
||||||
.filter_map(|(host, port, _)| Some(ConnectionAddr::Tcp(host.into(), port?)))
|
.filter_map(|(host, port, _)| {
|
||||||
|
Some(RedisConnectionAddr::Tcp {
|
||||||
|
host: host.into(),
|
||||||
|
port: port?,
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
(redis_options, RedisAddress::Cluster(addresses))
|
(redis_options, RedisAddress::Cluster(addresses))
|
||||||
} else {
|
} else {
|
||||||
let redis_options = &parsed["redis"];
|
let redis_options = &parsed["redis"];
|
||||||
let mut host = redis_options["host"].as_str().unwrap_or("127.0.0.1");
|
let mut host = redis_options["host"].as_str().unwrap_or("127.0.0.1");
|
||||||
let address = if host.starts_with('/') {
|
let address = if host.starts_with('/') {
|
||||||
RedisAddress::Single(ConnectionAddr::Unix(host.into()))
|
RedisAddress::Single(RedisConnectionAddr::Unix { path: host.into() })
|
||||||
} else {
|
} else {
|
||||||
if host == "localhost" {
|
if host == "localhost" {
|
||||||
host = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
|
|
@ -332,7 +329,10 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
||||||
} else {
|
} else {
|
||||||
split_host(host)
|
split_host(host)
|
||||||
};
|
};
|
||||||
RedisAddress::Single(ConnectionAddr::Tcp(host.into(), port.unwrap_or(6379)))
|
RedisAddress::Single(RedisConnectionAddr::Tcp {
|
||||||
|
host: host.into(),
|
||||||
|
port: port.unwrap_or(6379),
|
||||||
|
})
|
||||||
};
|
};
|
||||||
(redis_options, address)
|
(redis_options, address)
|
||||||
};
|
};
|
||||||
|
|
@ -348,26 +348,20 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
|
|
||||||
match address {
|
match address {
|
||||||
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
|
RedisAddress::Single(addr) => RedisConfig::Single(RedisConnectionInfo {
|
||||||
addr,
|
addr,
|
||||||
redis: RedisConnectionInfo {
|
db,
|
||||||
db,
|
username,
|
||||||
username,
|
password,
|
||||||
password,
|
|
||||||
protocol: ProtocolVersion::default(),
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
||||||
addresses
|
addresses
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|addr| ConnectionInfo {
|
.map(|addr| RedisConnectionInfo {
|
||||||
addr,
|
addr,
|
||||||
redis: RedisConnectionInfo {
|
db,
|
||||||
db,
|
username: username.clone(),
|
||||||
username: username.clone(),
|
password: password.clone(),
|
||||||
password: password.clone(),
|
|
||||||
protocol: ProtocolVersion::default(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
|
|
@ -375,7 +369,6 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn test_redis_empty_password_none() {
|
fn test_redis_empty_password_none() {
|
||||||
let config =
|
let config =
|
||||||
php_literal_parser::from_str(r#"["redis" => ["host" => "redis", "password" => "pass"]]"#)
|
php_literal_parser::from_str(r#"["redis" => ["host" => "redis", "password" => "pass"]]"#)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
use nextcloud_config_parser::{parse, parse_glob, Config, Database, DbConnect, SslOptions};
|
use nextcloud_config_parser::{
|
||||||
|
parse, parse_glob, Config, Database, DbConnect, RedisConfig, RedisConnectionAddr,
|
||||||
|
RedisConnectionInfo, SslOptions,
|
||||||
|
};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
use redis::{ConnectionAddr, ConnectionInfo};
|
||||||
use nextcloud_config_parser::RedisConfig;
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
use redis::ConnectionInfo;
|
|
||||||
use sqlx::mysql::{MySqlConnectOptions, MySqlSslMode};
|
use sqlx::mysql::{MySqlConnectOptions, MySqlSslMode};
|
||||||
use sqlx::sqlite::SqliteConnectOptions;
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
||||||
|
|
@ -21,6 +21,31 @@ fn config_from_file(path: &str) -> Config {
|
||||||
parse(path).unwrap()
|
parse(path).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_redis(cfg: &str) -> RedisConnectionInfo {
|
||||||
|
let redis = ConnectionInfo::from_str(cfg).unwrap();
|
||||||
|
let addr = match redis.addr {
|
||||||
|
ConnectionAddr::Tcp(host, port) => RedisConnectionAddr::Tcp { host, port },
|
||||||
|
ConnectionAddr::TcpTls {
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
insecure,
|
||||||
|
..
|
||||||
|
} => RedisConnectionAddr::TcpTls {
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
insecure,
|
||||||
|
tls_params: None,
|
||||||
|
},
|
||||||
|
ConnectionAddr::Unix(path) => RedisConnectionAddr::Unix { path },
|
||||||
|
};
|
||||||
|
RedisConnectionInfo {
|
||||||
|
addr,
|
||||||
|
db: redis.redis.db,
|
||||||
|
username: redis.redis.username,
|
||||||
|
password: redis.redis.password,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_config_basic() {
|
fn test_parse_config_basic() {
|
||||||
let config = config_from_file("tests/configs/basic.php");
|
let config = config_from_file("tests/configs/basic.php");
|
||||||
|
|
@ -45,9 +70,8 @@ fn test_parse_config_basic() {
|
||||||
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis://127.0.0.1").unwrap()),
|
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -59,33 +83,28 @@ fn test_parse_implicit_prefix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn test_parse_empty_redis_password() {
|
fn test_parse_empty_redis_password() {
|
||||||
let config = config_from_file("tests/configs/empty_redis_password.php");
|
let config = config_from_file("tests/configs/empty_redis_password.php");
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis://127.0.0.1").unwrap()),
|
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn test_parse_full_redis() {
|
fn test_parse_full_redis() {
|
||||||
let config = config_from_file("tests/configs/full_redis.php");
|
let config = config_from_file("tests/configs/full_redis.php");
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(
|
RedisConfig::Single(parse_redis("redis://name:moresecret@redis:1234/1")),
|
||||||
ConnectionInfo::from_str("redis://name:moresecret@redis:1234/1").unwrap(),
|
|
||||||
),
|
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn test_parse_redis_socket() {
|
fn test_parse_redis_socket() {
|
||||||
let config = config_from_file("tests/configs/redis_socket.php");
|
let config = config_from_file("tests/configs/redis_socket.php");
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis+unix:///redis").unwrap()),
|
RedisConfig::Single(parse_redis("redis+unix:///redis")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -114,9 +133,8 @@ fn test_parse_comment_whitespace() {
|
||||||
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis://127.0.0.1").unwrap()),
|
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -263,19 +281,18 @@ fn test_parse_postgres_socket_folder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
fn test_parse_redis_cluster() {
|
fn test_parse_redis_cluster() {
|
||||||
let config = config_from_file("tests/configs/redis.cluster.php");
|
let config = config_from_file("tests/configs/redis.cluster.php");
|
||||||
let mut conns = config.redis.into_vec();
|
let mut conns = config.redis.into_vec();
|
||||||
conns.sort_by(|a, b| a.addr.to_string().cmp(&b.addr.to_string()));
|
conns.sort_by(|a, b| format!("{:?}", a.addr).cmp(&format!("{:?}", b.addr)));
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
vec![
|
vec![
|
||||||
ConnectionInfo::from_str("redis://:xxx@db1:6380").unwrap(),
|
parse_redis("redis://:xxx@db1:6380"),
|
||||||
ConnectionInfo::from_str("redis://:xxx@db1:6381").unwrap(),
|
parse_redis("redis://:xxx@db1:6381"),
|
||||||
ConnectionInfo::from_str("redis://:xxx@db1:6382").unwrap(),
|
parse_redis("redis://:xxx@db1:6382"),
|
||||||
ConnectionInfo::from_str("redis://:xxx@db2:6380").unwrap(),
|
parse_redis("redis://:xxx@db2:6380"),
|
||||||
ConnectionInfo::from_str("redis://:xxx@db2:6381").unwrap(),
|
parse_redis("redis://:xxx@db2:6381"),
|
||||||
ConnectionInfo::from_str("redis://:xxx@db2:6382").unwrap(),
|
parse_redis("redis://:xxx@db2:6382"),
|
||||||
],
|
],
|
||||||
conns,
|
conns,
|
||||||
);
|
);
|
||||||
|
|
@ -305,9 +322,8 @@ fn test_parse_config_multiple() {
|
||||||
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis://127.0.0.1").unwrap()),
|
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -327,9 +343,8 @@ fn test_parse_config_multiple_no_glob() {
|
||||||
AnyConnectOptions::from_str("sqlite:///nc/nextcloud.db").unwrap(),
|
AnyConnectOptions::from_str("sqlite:///nc/nextcloud.db").unwrap(),
|
||||||
AnyConnectOptions::from_str(&config.database.url()).unwrap(),
|
AnyConnectOptions::from_str(&config.database.url()).unwrap(),
|
||||||
);
|
);
|
||||||
#[cfg(feature = "redis-connect")]
|
|
||||||
assert_debug_equal(
|
assert_debug_equal(
|
||||||
RedisConfig::Single(ConnectionInfo::from_str("redis://127.0.0.1").unwrap()),
|
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||||
config.redis,
|
config.redis,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue