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]
|
[package]
|
||||||
name = "nextcloud-config-parser"
|
name = "nextcloud-config-parser"
|
||||||
description = "Rust parser for nextcloud config files"
|
description = "Rust parser for nextcloud config files"
|
||||||
version = "0.2.3"
|
version = "0.3.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
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"
|
documentation = "https://docs.rs/nextcloud-config-parser"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
redis = { version = "0.20", optional = true }
|
redis = { version = "0.21", optional = true }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
php-literal-parser = { version = "0.2", default-features = false }
|
php-literal-parser = { version = "0.2", default-features = false }
|
||||||
sqlx = { version = "0.5", features = ["any", "mysql", "sqlite", "postgres"], optional = true }
|
sqlx = { version = "0.5", features = ["any", "mysql", "sqlite", "postgres"], optional = true }
|
||||||
|
|
|
||||||
18
src/lib.rs
18
src/lib.rs
|
|
@ -30,35 +30,37 @@ pub enum RedisConfig {
|
||||||
impl RedisConfig {
|
impl RedisConfig {
|
||||||
pub fn addr(&self) -> impl Iterator<Item = &ConnectionAddr> {
|
pub fn addr(&self) -> impl Iterator<Item = &ConnectionAddr> {
|
||||||
let boxed: Box<dyn Iterator<Item = &ConnectionAddr>> = match self {
|
let boxed: Box<dyn Iterator<Item = &ConnectionAddr>> = match self {
|
||||||
RedisConfig::Single(conn) => Box::new(once(conn.addr.as_ref())),
|
RedisConfig::Single(conn) => Box::new(once(&conn.addr)),
|
||||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| conn.addr.as_ref())),
|
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| &conn.addr)),
|
||||||
};
|
};
|
||||||
boxed
|
boxed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn db(&self) -> i64 {
|
pub fn db(&self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
RedisConfig::Single(conn) => conn.db,
|
RedisConfig::Single(conn) => conn.redis.db,
|
||||||
RedisConfig::Cluster(conns) => conns.first().map(|conn| conn.db).unwrap_or_default(),
|
RedisConfig::Cluster(conns) => {
|
||||||
|
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.username.as_deref(),
|
RedisConfig::Single(conn) => conn.redis.username.as_deref(),
|
||||||
RedisConfig::Cluster(conns) => conns
|
RedisConfig::Cluster(conns) => conns
|
||||||
.first()
|
.first()
|
||||||
.map(|conn| conn.username.as_deref())
|
.map(|conn| conn.redis.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.passwd.as_deref(),
|
RedisConfig::Single(conn) => conn.redis.password.as_deref(),
|
||||||
RedisConfig::Cluster(conns) => conns
|
RedisConfig::Cluster(conns) => conns
|
||||||
.first()
|
.first()
|
||||||
.map(|conn| conn.passwd.as_deref())
|
.map(|conn| conn.redis.password.as_deref())
|
||||||
.unwrap_or_default(),
|
.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 db = redis_options["dbindex"].clone().into_int().unwrap_or(0);
|
||||||
let passwd = redis_options["password"]
|
let password = redis_options["password"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.filter(|pass| !pass.is_empty())
|
.filter(|pass| !pass.is_empty())
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
|
|
||||||
match address {
|
match address {
|
||||||
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
|
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
|
||||||
addr: Box::new(addr),
|
addr,
|
||||||
db,
|
redis: RedisConnectionInfo {
|
||||||
username: None,
|
db,
|
||||||
passwd,
|
username: None,
|
||||||
|
password,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
||||||
addresses
|
addresses
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|addr| ConnectionInfo {
|
.map(|addr| ConnectionInfo {
|
||||||
addr: Box::new(addr),
|
addr,
|
||||||
db,
|
redis: RedisConnectionInfo {
|
||||||
username: None,
|
db,
|
||||||
passwd: passwd.clone(),
|
username: None,
|
||||||
|
password: password.clone(),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
),
|
),
|
||||||
|
|
@ -346,6 +350,7 @@ fn assert_debug_equal<T: Debug>(a: T, b: T) {
|
||||||
assert_eq!(format!("{:?}", a), format!("{:?}", b),);
|
assert_eq!(format!("{:?}", a), format!("{:?}", b),);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use redis::RedisConnectionInfo;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue