mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 16:44:09 +02:00
redis 0.21
This commit is contained in:
parent
0bf1ff020a
commit
2d2fa8a31e
3 changed files with 27 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "nextcloud-config-parser"
|
||||
description = "Rust parser for nextcloud config files"
|
||||
version = "0.2.3"
|
||||
version = "0.3.0"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
@ -9,7 +9,7 @@ repository = "https://github.com/icewind1991/nextcloud-config-parser"
|
|||
documentation = "https://docs.rs/nextcloud-config-parser"
|
||||
|
||||
[dependencies]
|
||||
redis = { version = "0.20", optional = true }
|
||||
redis = { version = "0.21", optional = true }
|
||||
thiserror = "1"
|
||||
php-literal-parser = { version = "0.2", default-features = false }
|
||||
sqlx = { version = "0.5", features = ["any", "mysql", "sqlite", "postgres"], optional = true }
|
||||
|
|
@ -21,4 +21,4 @@ sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "any", "mysql", "s
|
|||
default = ["span-colors"]
|
||||
span-colors = ["php-literal-parser/colors"]
|
||||
db-sqlx = ["sqlx"]
|
||||
redis-connect = ["redis"]
|
||||
redis-connect = ["redis"]
|
||||
|
|
|
|||
18
src/lib.rs
18
src/lib.rs
|
|
@ -30,35 +30,37 @@ pub enum RedisConfig {
|
|||
impl RedisConfig {
|
||||
pub fn addr(&self) -> impl Iterator<Item = &ConnectionAddr> {
|
||||
let boxed: Box<dyn Iterator<Item = &ConnectionAddr>> = match self {
|
||||
RedisConfig::Single(conn) => Box::new(once(conn.addr.as_ref())),
|
||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| conn.addr.as_ref())),
|
||||
RedisConfig::Single(conn) => Box::new(once(&conn.addr)),
|
||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| &conn.addr)),
|
||||
};
|
||||
boxed
|
||||
}
|
||||
|
||||
pub fn db(&self) -> i64 {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.db,
|
||||
RedisConfig::Cluster(conns) => conns.first().map(|conn| conn.db).unwrap_or_default(),
|
||||
RedisConfig::Single(conn) => conn.redis.db,
|
||||
RedisConfig::Cluster(conns) => {
|
||||
conns.first().map(|conn| conn.redis.db).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn username(&self) -> Option<&str> {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.username.as_deref(),
|
||||
RedisConfig::Single(conn) => conn.redis.username.as_deref(),
|
||||
RedisConfig::Cluster(conns) => conns
|
||||
.first()
|
||||
.map(|conn| conn.username.as_deref())
|
||||
.map(|conn| conn.redis.username.as_deref())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn passwd(&self) -> Option<&str> {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.passwd.as_deref(),
|
||||
RedisConfig::Single(conn) => conn.redis.password.as_deref(),
|
||||
RedisConfig::Cluster(conns) => conns
|
||||
.first()
|
||||
.map(|conn| conn.passwd.as_deref())
|
||||
.map(|conn| conn.redis.password.as_deref())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/nc.rs
23
src/nc.rs
|
|
@ -298,26 +298,30 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
|||
};
|
||||
|
||||
let db = redis_options["dbindex"].clone().into_int().unwrap_or(0);
|
||||
let passwd = redis_options["password"]
|
||||
let password = redis_options["password"]
|
||||
.as_str()
|
||||
.filter(|pass| !pass.is_empty())
|
||||
.map(String::from);
|
||||
|
||||
match address {
|
||||
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
|
||||
addr: Box::new(addr),
|
||||
db,
|
||||
username: None,
|
||||
passwd,
|
||||
addr,
|
||||
redis: RedisConnectionInfo {
|
||||
db,
|
||||
username: None,
|
||||
password,
|
||||
},
|
||||
}),
|
||||
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
||||
addresses
|
||||
.into_iter()
|
||||
.map(|addr| ConnectionInfo {
|
||||
addr: Box::new(addr),
|
||||
db,
|
||||
username: None,
|
||||
passwd: passwd.clone(),
|
||||
addr,
|
||||
redis: RedisConnectionInfo {
|
||||
db,
|
||||
username: None,
|
||||
password: password.clone(),
|
||||
},
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
|
|
@ -346,6 +350,7 @@ fn assert_debug_equal<T: Debug>(a: T, b: T) {
|
|||
assert_eq!(format!("{:?}", a), format!("{:?}", b),);
|
||||
}
|
||||
|
||||
use redis::RedisConnectionInfo;
|
||||
#[cfg(test)]
|
||||
#[allow(unused_imports)]
|
||||
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue