add support for redis username

This commit is contained in:
Robin Appelman 2022-12-28 14:59:54 +01:00
commit 07af6dccd0
3 changed files with 11 additions and 4 deletions

View file

@ -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.6.0" version = "0.6.1"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

@ -337,13 +337,17 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
.as_str() .as_str()
.filter(|pass| !pass.is_empty()) .filter(|pass| !pass.is_empty())
.map(String::from); .map(String::from);
let username = redis_options["user"]
.as_str()
.filter(|user| !user.is_empty())
.map(String::from);
match address { match address {
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo { RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
addr, addr,
redis: RedisConnectionInfo { redis: RedisConnectionInfo {
db, db,
username: None, username,
password, password,
}, },
}), }),
@ -354,7 +358,7 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
addr, addr,
redis: RedisConnectionInfo { redis: RedisConnectionInfo {
db, db,
username: None, username: username.clone(),
password: password.clone(), password: password.clone(),
}, },
}) })
@ -450,7 +454,9 @@ fn test_parse_empty_redis_password() {
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(ConnectionInfo::from_str("redis://:moresecret@redis:1234/1").unwrap()), RedisConfig::Single(
ConnectionInfo::from_str("redis://name:moresecret@redis:1234/1").unwrap(),
),
config.redis, config.redis,
); );
} }

View file

@ -12,6 +12,7 @@ $CONFIG = [
'host' => 'redis', 'host' => 'redis',
'dbindex' => 1, 'dbindex' => 1,
'port' => 1234, 'port' => 1234,
'user' => 'name',
'password' => 'moresecret' 'password' => 'moresecret'
] ]
]; ];