Skip to content

Commit

Permalink
chore(*): declare IConfigurationOptions and Configuration convenience…
Browse files Browse the repository at this point in the history
… constructor

adjust according to code review
#136 (comment)
#136 (comment)

closes #135
  • Loading branch information
ostridm committed Dec 14, 2022
1 parent 8e8e7f4 commit 8194c82
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/SecTester.Core/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -31,7 +32,8 @@ public class Configuration
public string Version { get; } = "0.0.1";
public string RepeaterVersion { get; } = "9.0.0";

public Configuration(string? hostname, Credentials? credentials = null, List<ICredentialProvider>? credentialProviders = null, LogLevel logLevel = LogLevel.Error)
public Configuration(string? hostname, Credentials? credentials = null, IEnumerable<ICredentialProvider>? credentialProviders = null,
LogLevel logLevel = LogLevel.Error)
{
LogLevel = logLevel;
credentialProviders ??= new List<ICredentialProvider> { new EnvCredentialProvider() };
Expand All @@ -48,7 +50,12 @@ public Configuration(string? hostname, Credentials? credentials = null, List<ICr
}

Credentials = credentials;
_credentialProviders = credentialProviders;
_credentialProviders = credentialProviders.ToList();
}

public Configuration(IConfigurationOptions options)
: this(options.Hostname, options.Credentials, options.CredentialProviders, options.LogLevel)
{
}

public async Task LoadCredentials()
Expand Down Expand Up @@ -79,6 +86,7 @@ private void ResolveUrls(string hostname)
private void ResolveUrls(Uri uri)
{
var host = uri.Host;

if (_loopbackAddresses.Any(address => address == host))
{
Bus = $"amqp://{host}:5672";
Expand Down
12 changes: 12 additions & 0 deletions src/SecTester.Core/IConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace SecTester.Core;

public interface IConfigurationOptions
{
string Hostname { get; }
Credentials? Credentials { get; }
IEnumerable<ICredentialProvider>? CredentialProviders { get; }
LogLevel LogLevel { get; }
}
11 changes: 7 additions & 4 deletions src/SecTester.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ public void ConfigureServices(IServiceCollection services)
Configuration can be customized using the following options:

```csharp
public interface IConfigurationOptions {
string hostname
public interface IConfiguration {
string Hostname
{
get;
}
Credentials? credentials
Credentials? Credentials
{
get;
}
List<ICredentialProvider>? credentialProviders
IEnumerable<ICredentialProvider>? CredentialProviders
{
get;
}
LogLevel LogLevel {
get;
}
}
```

Expand Down

0 comments on commit 8194c82

Please sign in to comment.