|
2 | 2 | using System; |
3 | 3 | using System.Diagnostics.CodeAnalysis; |
4 | 4 |
|
5 | | -namespace Extensions.Configuration.GitLab |
| 5 | +namespace Extensions.Configuration.GitLab; |
| 6 | + |
| 7 | +public class GitLabConfigurationOptions |
6 | 8 | { |
7 | | - public class GitLabConfigurationOptions |
| 9 | + public GitLabConfigurationOptions() |
8 | 10 | { |
9 | | - public GitLabConfigurationOptions() |
10 | | - { |
11 | | - } |
| 11 | + } |
12 | 12 |
|
13 | | - public GitLabConfigurationOptions( |
14 | | - [NotNull] string hostUrl, |
15 | | - [NotNull] string projectId, |
16 | | - [NotNull] string authenticationToken, |
17 | | - [NotNull] string environmentName) |
18 | | - { |
19 | | - HostUrl = hostUrl ?? throw new ArgumentNullException(nameof(hostUrl)); |
20 | | - ProjectId = projectId ?? throw new ArgumentNullException(nameof(projectId)); |
21 | | - AuthenticationToken = authenticationToken ?? throw new ArgumentNullException(nameof(authenticationToken)); |
22 | | - EnvironmentName = environmentName ?? throw new ArgumentNullException(nameof(environmentName)); |
23 | | - } |
| 13 | + public GitLabConfigurationOptions( |
| 14 | + [NotNull] string hostUrl, |
| 15 | + [NotNull] string projectId, |
| 16 | + [NotNull] string authenticationToken, |
| 17 | + [NotNull] string environmentName) |
| 18 | + { |
| 19 | + HostUrl = hostUrl ?? throw new ArgumentNullException(nameof(hostUrl)); |
| 20 | + ProjectId = projectId ?? throw new ArgumentNullException(nameof(projectId)); |
| 21 | + AuthenticationToken = authenticationToken ?? throw new ArgumentNullException(nameof(authenticationToken)); |
| 22 | + EnvironmentName = environmentName ?? throw new ArgumentNullException(nameof(environmentName)); |
| 23 | + } |
24 | 24 |
|
25 | | - public TimeSpan ReloadInterval { get; set; } = TimeSpan.FromSeconds(3); |
| 25 | + public TimeSpan ReloadInterval { get; set; } = TimeSpan.FromSeconds(3); |
26 | 26 |
|
27 | | - public string HostUrl { get; set; } |
| 27 | + public string HostUrl { get; set; } |
28 | 28 |
|
29 | | - public string AuthenticationToken { get; set; } |
| 29 | + public string AuthenticationToken { get; set; } |
30 | 30 |
|
31 | | - public string ProjectId { get; set; } |
| 31 | + public string ProjectId { get; set; } |
32 | 32 |
|
33 | | - public string EnvironmentName { get; set; } = "*"; |
| 33 | + public string EnvironmentName { get; set; } = "*"; |
34 | 34 |
|
35 | | - public Func<string, string> KeyNormalizer { get; set; } = NormalizeKey; |
| 35 | + public Func<string, string> KeyNormalizer { get; set; } = NormalizeKey; |
36 | 36 |
|
37 | | - public GitLabConfigurationOptions WithReloadInterval(TimeSpan reloadInterval) |
38 | | - { |
39 | | - ReloadInterval = reloadInterval; |
40 | | - return this; |
41 | | - } |
| 37 | + public GitLabConfigurationOptions WithReloadInterval(TimeSpan reloadInterval) |
| 38 | + { |
| 39 | + ReloadInterval = reloadInterval; |
| 40 | + return this; |
| 41 | + } |
42 | 42 |
|
43 | | - public GitLabConfigurationOptions WithHostUrl([NotNull] string hostUrl) |
44 | | - { |
45 | | - HostUrl = hostUrl ?? throw new ArgumentNullException(nameof(hostUrl)); |
46 | | - return this; |
47 | | - } |
| 43 | + public GitLabConfigurationOptions WithHostUrl([NotNull] string hostUrl) |
| 44 | + { |
| 45 | + HostUrl = hostUrl ?? throw new ArgumentNullException(nameof(hostUrl)); |
| 46 | + return this; |
| 47 | + } |
48 | 48 |
|
49 | | - public GitLabConfigurationOptions WithAuthenticationToken([NotNull] string authenticationToken) |
50 | | - { |
51 | | - AuthenticationToken = authenticationToken ?? throw new ArgumentNullException(nameof(authenticationToken)); |
52 | | - return this; |
53 | | - } |
| 49 | + public GitLabConfigurationOptions WithAuthenticationToken([NotNull] string authenticationToken) |
| 50 | + { |
| 51 | + AuthenticationToken = authenticationToken ?? throw new ArgumentNullException(nameof(authenticationToken)); |
| 52 | + return this; |
| 53 | + } |
54 | 54 |
|
55 | | - public GitLabConfigurationOptions WithProjectId([NotNull] string projectId) |
56 | | - { |
57 | | - ProjectId = projectId ?? throw new ArgumentNullException(nameof(projectId)); |
58 | | - return this; |
59 | | - } |
| 55 | + public GitLabConfigurationOptions WithProjectId([NotNull] string projectId) |
| 56 | + { |
| 57 | + ProjectId = projectId ?? throw new ArgumentNullException(nameof(projectId)); |
| 58 | + return this; |
| 59 | + } |
60 | 60 |
|
61 | | - public GitLabConfigurationOptions WithEnvironmentName([NotNull] string environmentName) |
62 | | - { |
63 | | - EnvironmentName = environmentName ?? throw new ArgumentNullException(nameof(environmentName)); |
64 | | - return this; |
65 | | - } |
| 61 | + public GitLabConfigurationOptions WithEnvironmentName([NotNull] string environmentName) |
| 62 | + { |
| 63 | + EnvironmentName = environmentName ?? throw new ArgumentNullException(nameof(environmentName)); |
| 64 | + return this; |
| 65 | + } |
66 | 66 |
|
67 | | - public GitLabConfigurationOptions WithKeyNormalizer([NotNull] Func<string, string> keyNormalizer) |
68 | | - { |
69 | | - KeyNormalizer = keyNormalizer ?? throw new ArgumentNullException(nameof(keyNormalizer)); |
70 | | - return this; |
71 | | - } |
| 67 | + public GitLabConfigurationOptions WithKeyNormalizer([NotNull] Func<string, string> keyNormalizer) |
| 68 | + { |
| 69 | + KeyNormalizer = keyNormalizer ?? throw new ArgumentNullException(nameof(keyNormalizer)); |
| 70 | + return this; |
| 71 | + } |
72 | 72 |
|
73 | | - private static string NormalizeKey(string key) |
| 73 | + private static string NormalizeKey(string key) |
| 74 | + { |
| 75 | + if (string.IsNullOrEmpty(key)) |
74 | 76 | { |
75 | | - if (string.IsNullOrEmpty(key)) |
76 | | - { |
77 | | - return key; |
78 | | - } |
| 77 | + return key; |
| 78 | + } |
79 | 79 |
|
80 | | - var segments = Array.ConvertAll(key.Split('_'), e => |
81 | | - { |
82 | | - e = e.ToLower(); |
83 | | - return e.Length <= 1 ? e : char.ToUpper(e[0]) + e.Substring(1); |
84 | | - }); |
| 80 | + var segments = Array.ConvertAll(key.Split('_'), e => |
| 81 | + { |
| 82 | + e = e.ToLower(); |
| 83 | + return e.Length <= 1 ? e : char.ToUpper(e[0]) + e.Substring(1); |
| 84 | + }); |
85 | 85 |
|
86 | | - return string.Join(ConfigurationPath.KeyDelimiter, segments); |
87 | | - } |
| 86 | + return string.Join(ConfigurationPath.KeyDelimiter, segments); |
88 | 87 | } |
89 | 88 | } |
0 commit comments