Skip to content

Commit

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

closes #135
  • Loading branch information
ostridm committed Dec 14, 2022
1 parent 8e8e7f4 commit dfa799c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 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/IConfigurationOptions.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; }
}
9 changes: 6 additions & 3 deletions src/SecTester.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ Configuration can be customized using the following options:

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

Expand Down
14 changes: 7 additions & 7 deletions src/SecTester.Core/SecTester.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
</PropertyGroup>

<ItemGroup>
<Folder Include="Bus"/>
<Folder Include="CredentialProviders"/>
<Folder Include="Extensions"/>
<Folder Include="Internal"/>
<Folder Include="Bus" />
<Folder Include="CredentialProviders" />
<Folder Include="Extensions" />
<Folder Include="Internal" />
</ItemGroup>

<ItemGroup>
<Compile Remove="IsExternalInit.cs" Condition="'$(TargetFramework)' == 'net5.0'"/>
<Compile Remove="IsExternalInit.cs" Condition="'$(TargetFramework)' == 'net5.0'" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>
</Project>

0 comments on commit dfa799c

Please sign in to comment.