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]
name = "nextcloud-config-parser"
description = "Rust parser for nextcloud config files"
version = "0.6.0"
version = "0.6.1"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2021"
license = "MIT OR Apache-2.0"

View file

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

View file

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