aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-25 21:58:18 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-25 21:58:18 -0500
commitd02d99dfa047bd8a55e8286098e386879683c869 (patch)
tree89a3c7a946240e7a4bd9069f7e4c5323f554cf2f
parent58bc401dab5d7eb3bc6cb07a22e0ee9c97ddf4bd (diff)
downloadslskd-d02d99dfa047bd8a55e8286098e386879683c869.tar.gz
split environment variable values by semicolon if backing prop is array
-rw-r--r--src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
index 9a09d4e1..6d2896c2 100644
--- a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
+++ b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
@@ -100,15 +100,32 @@ namespace slskd.Configuration
if (attribute != default)
{
+ // retrieve the envar name from the attribute
var name = (string)attribute.ConstructorArguments[0].Value;
if (!string.IsNullOrEmpty(name))
{
+ // retrieve the corresponding value from environment variables
var value = Environment.GetEnvironmentVariable(Prefix + name);
if (value != null)
{
- Data[key] = value.ToString();
+ // if the type of the backing property is an array,
+ // split the retrieved value by semicolon and add the parts to
+ // config as zero-based children of the prop
+ if (property.PropertyType.IsArray)
+ {
+ var elements = value.Split(';');
+
+ for (int i = 0; i < elements.Length; i++)
+ {
+ Data[ConfigurationPath.Combine(key, i.ToString())] = elements[i];
+ }
+ }
+ else
+ {
+ Data[key] = value.ToString();
+ }
}
}
}