diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-07-25 21:58:18 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-07-25 21:58:18 -0500 |
| commit | d02d99dfa047bd8a55e8286098e386879683c869 (patch) | |
| tree | 89a3c7a946240e7a4bd9069f7e4c5323f554cf2f /src | |
| parent | 58bc401dab5d7eb3bc6cb07a22e0ee9c97ddf4bd (diff) | |
| download | slskd-d02d99dfa047bd8a55e8286098e386879683c869.tar.gz | |
split environment variable values by semicolon if backing prop is array
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs | 19 |
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(); + } } } } |
