diff options
Diffstat (limited to 'src')
6 files changed, 77 insertions, 78 deletions
diff --git a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs index 75ecadc4..088d5ea6 100644 --- a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs +++ b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs @@ -15,7 +15,6 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> -#pragma warning disable SA1649 // File name should match first type name namespace slskd.Configuration { using System; @@ -32,7 +31,7 @@ namespace slskd.Configuration /// <summary> /// Extension methods for adding <see cref="CommandLineConfigurationProvider"/>. /// </summary> - public static class CommandLineExtensions + public static class CommandLineConfigurationExtensions { /// <summary> /// Adds a command line argument configuration soruce to <paramref name="builder"/>. @@ -40,11 +39,8 @@ namespace slskd.Configuration /// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add.</param> /// <param name="map">A list of command line argument mappings.</param> /// <param name="commandLine">The command line string from which to parse arguments.</param> - /// <param name="normalizeKey"> - /// A value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). - /// </param> /// <returns>The updated <see cref="IConfigurationBuilder"/>.</returns> - public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, IEnumerable<CommandLineArgument> map, string commandLine = null, bool normalizeKey = true) + public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, IEnumerable<CommandLineArgument> map, string commandLine = null) { if (builder == null) { @@ -55,7 +51,6 @@ namespace slskd.Configuration { s.Map = map; s.CommandLine = commandLine ?? Environment.CommandLine; - s.NormalizeKey = normalizeKey; }); } @@ -82,12 +77,10 @@ namespace slskd.Configuration { Map = source.Map; CommandLine = source.CommandLine; - NormalizeKey = source.NormalizeKey; } private string CommandLine { get; set; } private IEnumerable<CommandLineArgument> Map { get; set; } - private bool NormalizeKey { get; set; } /// <summary> /// Parses command line arguments from the specified string and maps them to the specified keys. @@ -100,11 +93,6 @@ namespace slskd.Configuration { var (shortName, longName, type, key, _) = item; - if (NormalizeKey) - { - key = key?.Replace("-", string.Empty).Replace("_", string.Empty).ToLowerInvariant(); - } - if (string.IsNullOrEmpty(key)) { continue; @@ -146,16 +134,10 @@ namespace slskd.Configuration public IEnumerable<CommandLineArgument> Map { get; set; } /// <summary> - /// Gets or sets a value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). - /// </summary> - public bool NormalizeKey { get; set; } - - /// <summary> /// Builds the <see cref="CommandLineConfigurationProvider"/> for this source. /// </summary> /// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param> /// <returns>A <see cref="CommandLineConfigurationProvider"/>.</returns> public IConfigurationProvider Build(IConfigurationBuilder builder) => new CommandLineConfigurationProvider(this); } -} -#pragma warning restore SA1649 // File name should match first type name
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/slskd/Common/Configuration/ConfigurationExtensions.cs b/src/slskd/Common/Configuration/ConfigurationExtensions.cs index 77b59700..33385e0a 100644 --- a/src/slskd/Common/Configuration/ConfigurationExtensions.cs +++ b/src/slskd/Common/Configuration/ConfigurationExtensions.cs @@ -1,13 +1,48 @@ -namespace slskd.Configuration +// <copyright file="ConfigurationExtensions.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Configuration { + /// <summary> + /// Extension methods for the Configuration namespace. + /// </summary> public static class ConfigurationExtensions { + /// <summary> + /// Converts an <see cref="Option"/> mapping to a <see cref="CommandLineArgument"/> mapping. + /// </summary> + /// <param name="option">The option mapping to convert.</param> + /// <returns>The converted mapping.</returns> public static CommandLineArgument ToCommandLineArgument(this Option option) => new(option.ShortName, option.LongName, option.Type, option.Key, option.Description); + /// <summary> + /// Converts an <see cref="Option"/> mapping to a <see cref="EnvironmentVariable"/> mapping. + /// </summary> + /// <param name="option">The option mapping to convert.</param> + /// <returns>The converted mapping.</returns> public static EnvironmentVariable ToEnvironmentVariable(this Option option) => new(option.EnvironmentVariable, option.Type, option.Key, option.Description); + /// <summary> + /// Converts an <see cref="Option"/> mapping to a <see cref="DefaultValue"/> mapping. + /// </summary> + /// <param name="option">The option mapping to convert.</param> + /// <returns>The converted mapping.</returns> public static DefaultValue ToDefaultValue(this Option option) => new(option.Key, option.Type, option.Default); } diff --git a/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs b/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs index 5bbba10e..07e4f1b7 100644 --- a/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs +++ b/src/slskd/Common/Configuration/DefaultValueConfigurationSource.cs @@ -15,7 +15,6 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> -#pragma warning disable SA1649 // File name should match first type name namespace slskd.Configuration { using System; @@ -24,7 +23,7 @@ namespace slskd.Configuration using Microsoft.Extensions.Configuration; /// <summary> - /// Defines an default value mapping. + /// Defines a default value mapping. /// </summary> public record DefaultValue(string Key, Type Type, object Default); @@ -38,11 +37,8 @@ namespace slskd.Configuration /// </summary> /// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add.</param> /// <param name="map">A list of default value mappings.</param> - /// <param name="normalizeKey"> - /// A value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). - /// </param> /// <returns>The updated <see cref="IConfigurationBuilder"/>.</returns> - public static IConfigurationBuilder AddDefaultValues(this IConfigurationBuilder builder, IEnumerable<DefaultValue> map, bool normalizeKey = true) + public static IConfigurationBuilder AddDefaultValues(this IConfigurationBuilder builder, IEnumerable<DefaultValue> map) { if (builder == null) { @@ -52,7 +48,6 @@ namespace slskd.Configuration return builder.AddDefaultValues(s => { s.Map = map ?? Enumerable.Empty<DefaultValue>(); - s.NormalizeKey = normalizeKey; }); } @@ -78,11 +73,9 @@ namespace slskd.Configuration public DefaultValueConfigurationProvider(DefaultValueConfigurationSource source) { Map = source.Map; - NormalizeKey = source.NormalizeKey; } private IEnumerable<DefaultValue> Map { get; set; } - private bool NormalizeKey { get; set; } /// <summary> /// Sets the keys specified in the map to the specified default values. @@ -93,17 +86,7 @@ namespace slskd.Configuration { var (key, _, value) = item; - if (NormalizeKey) - { - key = key?.Replace("_", string.Empty).Replace("-", string.Empty).ToLowerInvariant(); - } - - if (string.IsNullOrEmpty(key)) - { - continue; - } - - if (value == null) + if (string.IsNullOrEmpty(key) || value == null) { continue; } @@ -124,11 +107,6 @@ namespace slskd.Configuration public IEnumerable<DefaultValue> Map { get; set; } /// <summary> - /// Gets or sets a value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). - /// </summary> - public bool NormalizeKey { get; set; } - - /// <summary> /// Builds the <see cref="DefaultValueConfigurationProvider"/> for this source. /// </summary> /// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param> @@ -138,5 +116,4 @@ namespace slskd.Configuration return new DefaultValueConfigurationProvider(this); } } -} -#pragma warning restore SA1649 // File name should match first type name
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs index 51ddf535..21775689 100644 --- a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs +++ b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs @@ -15,7 +15,6 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> -#pragma warning disable SA1649 // File name should match first type name namespace slskd.Configuration { using System; @@ -39,11 +38,8 @@ namespace slskd.Configuration /// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add.</param> /// <param name="map">A list of environment variable mappings.</param> /// <param name="prefix">A prefix to prepend to all variable names.</param> - /// <param name="normalizeKey"> - /// A value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). - /// </param> /// <returns>The updated <see cref="IConfigurationBuilder"/>.</returns> - public static IConfigurationBuilder AddEnvironmentVariables(this IConfigurationBuilder builder, IEnumerable<EnvironmentVariable> map, string prefix = null, bool normalizeKey = true) + public static IConfigurationBuilder AddEnvironmentVariables(this IConfigurationBuilder builder, IEnumerable<EnvironmentVariable> map, string prefix = null) { if (builder == null) { @@ -54,7 +50,6 @@ namespace slskd.Configuration { s.Map = map ?? Enumerable.Empty<EnvironmentVariable>(); s.Prefix = prefix ?? string.Empty; - s.NormalizeKey = normalizeKey; }); } @@ -81,11 +76,9 @@ namespace slskd.Configuration { Map = source.Map; Prefix = source.Prefix; - NormalizeKey = source.NormalizeKey; } private IEnumerable<EnvironmentVariable> Map { get; set; } - private bool NormalizeKey { get; set; } private string Prefix { get; set; } /// <summary> @@ -97,11 +90,6 @@ namespace slskd.Configuration { var (name, type, key, _) = item; - if (NormalizeKey) - { - key = key?.Replace("_", string.Empty).Replace("-", string.Empty).ToLowerInvariant(); - } - if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(name)) { continue; @@ -154,5 +142,4 @@ namespace slskd.Configuration return new EnvironmentVariableConfigurationProvider(this); } } -} -#pragma warning restore SA1649 // File name should match first type name
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/slskd/Common/Configuration/YamlConfigurationSource.cs b/src/slskd/Common/Configuration/YamlConfigurationSource.cs index 7766e14c..332df647 100644 --- a/src/slskd/Common/Configuration/YamlConfigurationSource.cs +++ b/src/slskd/Common/Configuration/YamlConfigurationSource.cs @@ -15,7 +15,6 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> -#pragma warning disable SA1649 // File name should match first type name namespace slskd.Configuration { using System; @@ -34,7 +33,7 @@ namespace slskd.Configuration /// <summary> /// Adds a YAML configuration source to <paramref name="builder"/>. /// </summary> - /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param> + /// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add .</param> /// <param name="path"> /// Path relative to the base path stored in <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>. /// </param> @@ -43,7 +42,7 @@ namespace slskd.Configuration /// <param name="normalizeKeys"> /// A value indicating whether configuration keys should be normalized (_, - removed, changed to lowercase). /// </param> - /// <param name="provider">The <see cref="IFileProvider"/> to use to access the file.</param> + /// <param name="provider">The updated <see cref="IFileProvider"/> to use to access the file.</param> /// <returns>The <see cref="IConfigurationBuilder"/>.</returns> public static IConfigurationBuilder AddYamlFile(this IConfigurationBuilder builder, string path, bool optional = true, bool reloadOnChange = false, bool normalizeKeys = true, IFileProvider provider = null) { @@ -71,9 +70,9 @@ namespace slskd.Configuration /// <summary> /// Adds a YAML configuration source to <paramref name="builder"/>. /// </summary> - /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param> + /// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add.</param> /// <param name="configureSource">Configures the source.</param> - /// <returns>The <see cref="IConfigurationBuilder"/>.</returns> + /// <returns>The updated <see cref="IConfigurationBuilder"/>.</returns> public static IConfigurationBuilder AddYamlFile(this IConfigurationBuilder builder, Action<YamlConfigurationSource> configureSource) => builder.Add(configureSource); } @@ -178,5 +177,4 @@ namespace slskd.Configuration return new YamlConfigurationProvider(this); } } -} -#pragma warning restore SA1649 // File name should match first type name
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index b48853ef..af78e68d 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -1,12 +1,32 @@ -namespace slskd +// <copyright file="Options.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd { - using slskd.Validation; - using Soulseek.Diagnostics; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics; + using slskd.Validation; + using Soulseek.Diagnostics; + /// <summary> + /// Defines an option mapping. + /// </summary> public record Option(char ShortName, string LongName, string EnvironmentVariable, string Key, Type Type, object Default = null, string Description = null); public class Options @@ -17,11 +37,11 @@ public bool NoLogo { get; private set; } = false; public string InstanceName { get; private set; } = "default"; [Validate] - public DirectoriesOptions Directories { get; private set; } = new DirectoriesOptions(); + public DirectoriesOptions Directories { get; private set; } = new DirectoriesOptions(); [Validate] - public WebOptions Web { get; private set; } = new WebOptions(); + public WebOptions Web { get; private set; } = new WebOptions(); [Validate] - public LoggerOptions Logger { get; private set; } = new LoggerOptions(); + public LoggerOptions Logger { get; private set; } = new LoggerOptions(); [Validate] public FeatureOptions Feature { get; private set; } = new FeatureOptions(); [Validate] @@ -336,7 +356,7 @@ ShortName: default, LongName: "prometheus", EnvironmentVariable: "PROMETHEUS", - Key: "slskd:feature:prometheus", + Key: "slskd:feature:prometheus", Type: typeof(bool), Default: Defaults.Feature.Prometheus, Description: "enable collection and publishing of prometheus metrics"), |
