diff --git a/ExampleApplication/FiksIO/FiksIOConfigurationBuilder.cs b/ExampleApplication/FiksIO/FiksIOConfigurationBuilder.cs index 6f382500..40510fea 100644 --- a/ExampleApplication/FiksIO/FiksIOConfigurationBuilder.cs +++ b/ExampleApplication/FiksIO/FiksIOConfigurationBuilder.cs @@ -10,7 +10,37 @@ namespace ExampleApplication.FiksIO public static class FiksIoConfigurationBuilder { - // Create a configuration for the test environment with the fluent builder + /* Create a configuration for the test environment with the fluent builder. + * API, AMQP and maskinporten host urls and endpoints for test-environment are set by the client. + * Use this for easy setup in a test-environment. + */ + public static FiksIOConfiguration CreateTestConfiguration(AppSettings appSettings) + { + var accountId = appSettings.FiksIOConfig.FiksIoAccountId; + var privateKeyPath = appSettings.FiksIOConfig.FiksIoPrivateKey; + var integrationId = appSettings.FiksIOConfig.FiksIoIntegrationId; + var integrationPassword = appSettings.FiksIOConfig.FiksIoIntegrationPassword; + var issuer = appSettings.FiksIOConfig.MaskinPortenIssuer; + var certPath = appSettings.FiksIOConfig.MaskinPortenCompanyCertificatePath; + var certPassword = appSettings.FiksIOConfig.MaskinPortenCompanyCertificatePassword; + var asiceSigningPublicKey = appSettings.FiksIOConfig.AsiceSigningPublicKey; + var asiceSigningPrivateKey = appSettings.FiksIOConfig.AsiceSigningPrivateKey; + + return FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("fiks-io-client-dotnet-example-application", 1, true,20 * 1000) + .WithMaskinportenConfiguration(new X509Certificate2(certPath, certPassword), issuer) + .WithFiksIntegrasjonConfiguration(integrationId, integrationPassword) + .WithFiksKontoConfiguration(accountId, ReadFromFile(privateKeyPath)) + .WithAsiceSigningConfiguration(asiceSigningPublicKey, asiceSigningPrivateKey) + .BuildTestConfiguration(); + } + + /* Create a configuration for any environment with the fluent builder. All required settings must be set from app settings. + * API, AMQP and maskinporten settings must be set by you. + * Use this for configuration that can be used in any environment and the environment holds the settings. + */ + public static FiksIOConfiguration CreateConfiguration(AppSettings appSettings) { var accountId = appSettings.FiksIOConfig.FiksIoAccountId; @@ -23,21 +53,26 @@ public static FiksIOConfiguration CreateConfiguration(AppSettings appSettings) var asiceSigningPublicKey = appSettings.FiksIOConfig.AsiceSigningPublicKey; var asiceSigningPrivateKey = appSettings.FiksIOConfig.AsiceSigningPrivateKey; var apiHost = appSettings.FiksIOConfig.ApiHost; + var apiScheme = appSettings.FiksIOConfig.ApiScheme; var apiPort = appSettings.FiksIOConfig.ApiPort; + var amqpHost = appSettings.FiksIOConfig.AmqpHost; + var amqpPort = appSettings.FiksIOConfig.AmqpPort; + var maskinportenAudience = appSettings.FiksIOConfig.MaskinPortenAudienceUrl; + var maskinportenTokenEndpoint = appSettings.FiksIOConfig.MaskinPortenTokenUrl; return FiksIOConfigurationBuilder .Init() - .WithAmqpConfiguration("fiks-io-client-dotnet-example-application", 1, true,20 * 1000) - .WithMaskinportenConfiguration(new X509Certificate2(certPath, certPassword), issuer) + .WithAmqpConfiguration("fiks-io-client-dotnet-example-application", 1, true,20 * 1000, amqpHost, amqpPort) + .WithMaskinportenConfiguration(new X509Certificate2(certPath, certPassword), issuer, maskinportenAudience, maskinportenTokenEndpoint) .WithFiksIntegrasjonConfiguration(integrationId, integrationPassword) .WithFiksKontoConfiguration(accountId, ReadFromFile(privateKeyPath)) .WithAsiceSigningConfiguration(asiceSigningPublicKey, asiceSigningPrivateKey) - .WithApiConfiguration(apiHost, apiPort) - .BuildTestConfiguration(); + .WithApiConfiguration(apiHost, apiScheme, apiPort) + .BuildConfiguration(); } - - // Create a FiksIOConfiguration manually. Use this if you want to use internal endpoints for testing, not Fiks-IO test or prod + + // Create a FiksIOConfiguration manually. public static FiksIOConfiguration CreateConfig(string issuer, string p12Filename, string p12Password, string fiksIoAccountId, string fiksIoPrivateKeyPath, string integrasjonId, string integrasjonPassword) { diff --git a/ExampleApplication/Program.cs b/ExampleApplication/Program.cs index 8e12b871..2afd102c 100644 --- a/ExampleApplication/Program.cs +++ b/ExampleApplication/Program.cs @@ -46,7 +46,7 @@ public static async Task Main(string[] args) var loggerFactory = InitSerilogConfiguration(); var appSettings = AppSettingsBuilder.CreateAppSettings(configurationRoot); - var configuration = FiksIoConfigurationBuilder.CreateConfiguration(appSettings); + var configuration = FiksIoConfigurationBuilder.CreateTestConfiguration(appSettings); var fiksIoClient = await FiksIOClient.CreateAsync(configuration, loggerFactory); // Creating messageSender as a local instance diff --git a/KS.Fiks.IO.Client.Tests/Configuration/FiksIOConfigurationBuilderTests.cs b/KS.Fiks.IO.Client.Tests/Configuration/FiksIOConfigurationBuilderTests.cs index dff79fd9..2b52d01c 100644 --- a/KS.Fiks.IO.Client.Tests/Configuration/FiksIOConfigurationBuilderTests.cs +++ b/KS.Fiks.IO.Client.Tests/Configuration/FiksIOConfigurationBuilderTests.cs @@ -26,6 +26,30 @@ public void TestConfigurationWithAllRequiredConfigurations() configuration.AmqpConfiguration.Host.Should().Be(AmqpConfiguration.TestHost); } + [Fact] + public void FullConfigurationWithAllRequiredConfigurations() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + var configuration = FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithApiConfiguration(apiHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", maskinportenAudience, maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .BuildConfiguration(); + + configuration.ApiConfiguration.Host.Should().Be(apiHost); + configuration.AmqpConfiguration.Host.Should().Be(amqpHost); + configuration.MaskinportenConfiguration.Audience.Should().Be(maskinportenAudience); + configuration.MaskinportenConfiguration.TokenEndpoint.Should().Be(maskinportenTokenEndpoint); + } + [Fact] public void ProdConfigurationWithAllRequiredConfigurations() { @@ -42,6 +66,54 @@ public void ProdConfigurationWithAllRequiredConfigurations() configuration.AmqpConfiguration.Host.Should().Be(AmqpConfiguration.ProdHost); } + [Fact] + public void TestConfigurationWithCustomConfigurations() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + var configuration = FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", maskinportenAudience, maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .WithApiConfiguration(apiHost) + .BuildTestConfiguration(); + + configuration.ApiConfiguration.Host.Should().Be(apiHost); + configuration.AmqpConfiguration.Host.Should().Be(amqpHost); + configuration.MaskinportenConfiguration.Audience.Should().Be(maskinportenAudience); + configuration.MaskinportenConfiguration.TokenEndpoint.Should().Be(maskinportenTokenEndpoint); + } + + [Fact] + public void ProdConfigurationWithCustomConfigurations() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + var configuration = FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", maskinportenAudience, maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .WithApiConfiguration(apiHost) + .BuildProdConfiguration(); + + configuration.ApiConfiguration.Host.Should().Be(apiHost); + configuration.AmqpConfiguration.Host.Should().Be(amqpHost); + configuration.MaskinportenConfiguration.Audience.Should().Be(maskinportenAudience); + configuration.MaskinportenConfiguration.TokenEndpoint.Should().Be(maskinportenTokenEndpoint); + } + [Fact] public void ConfigWithSinglPrivateKey() { @@ -75,7 +147,7 @@ public void ConfigWithMultiplePrivateKeys() } [Fact] - public void ConfigurationFailsWithoutCertificateInMaskinportenConfiguration() + public void ProdConfigurationFailsWithoutCertificateInMaskinportenConfiguration() { Assert.Throws(() => FiksIOConfigurationBuilder @@ -88,7 +160,7 @@ public void ConfigurationFailsWithoutCertificateInMaskinportenConfiguration() } [Fact] - public void ConfigurationFailsWithoutAsiceSigningConfiguration() + public void ProdConfigurationFailsWithoutAsiceSigningConfiguration() { Assert.Throws(() => FiksIOConfigurationBuilder @@ -101,7 +173,7 @@ public void ConfigurationFailsWithoutAsiceSigningConfiguration() } [Fact] - public void ConfigurationFailsWithoutMaskinportenConfiguration() + public void ProdConfigurationFailsWithoutMaskinportenConfiguration() { Assert.Throws(() => FiksIOConfigurationBuilder @@ -113,7 +185,7 @@ public void ConfigurationFailsWithoutMaskinportenConfiguration() } [Fact] - public void ConfigurationFailsWithoutFiksIntegrasjonConfiguration() + public void ProdConfigurationFailsWithoutFiksIntegrasjonConfiguration() { Assert.Throws(() => FiksIOConfigurationBuilder @@ -125,7 +197,7 @@ public void ConfigurationFailsWithoutFiksIntegrasjonConfiguration() } [Fact] - public void ConfigurationFailsWithoutFiksKontoConfiguration() + public void ProdConfigurationFailsWithoutFiksKontoConfiguration() { Assert.Throws(() => FiksIOConfigurationBuilder @@ -135,5 +207,84 @@ public void ConfigurationFailsWithoutFiksKontoConfiguration() .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") .BuildProdConfiguration()); } + + [Fact] + public void FullConfigurationFailsWithoutMaskinportenTokenEndpoint() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + Assert.Throws(() => + FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithApiConfiguration(apiHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", maskinportenAudience) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .BuildConfiguration()); + } + + [Fact] + public void FullConfigurationFailsWithoutMaskinportenAudience() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + Assert.Throws(() => + FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithApiConfiguration(apiHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", tokenEndpoint: maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .BuildConfiguration()); + } + + [Fact] + public void FullConfigurationFailsWithoutApiHost() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + Assert.Throws(() => + FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10, host: amqpHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", audience: maskinportenAudience, tokenEndpoint: maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .BuildConfiguration()); + } + + [Fact] + public void FullConfigurationFailsWithoutAmqpHost() + { + var amqpHost = "testAmqpHost"; + var apiHost = "testApiHost"; + var maskinportenAudience = "testMaskinportenAudience"; + var maskinportenTokenEndpoint = "testMaskinportenTokenEndpoint"; + + Assert.Throws(() => + FiksIOConfigurationBuilder + .Init() + .WithAmqpConfiguration("test_app", 10) + .WithApiConfiguration(apiHost) + .WithMaskinportenConfiguration(new X509Certificate2(), "test-issuer", audience: maskinportenAudience, tokenEndpoint: maskinportenTokenEndpoint) + .WithAsiceSigningConfiguration(new X509Certificate2()) + .WithFiksIntegrasjonConfiguration(Guid.NewGuid(), "passord") + .WithFiksKontoConfiguration(Guid.NewGuid(), "liksom-en-private-key") + .BuildConfiguration()); + } } } \ No newline at end of file diff --git a/KS.Fiks.IO.Client/Configuration/AmqpConfiguration.cs b/KS.Fiks.IO.Client/Configuration/AmqpConfiguration.cs index 6905e19b..30cf47a5 100644 --- a/KS.Fiks.IO.Client/Configuration/AmqpConfiguration.cs +++ b/KS.Fiks.IO.Client/Configuration/AmqpConfiguration.cs @@ -8,8 +8,9 @@ public class AmqpConfiguration public const string ProdHost = "io.fiks.ks.no"; public const string TestHost = "io.fiks.test.ks.no"; public const int DefaultKeepAliveHealthCheckInterval = 1 * 60 * 1000; + public const int DefaultPort = 5671; - public AmqpConfiguration(string host, int port = 5671, SslOption sslOption = null, string applicationName = "Fiks IO klient (dotnet)", ushort prefetchCount = 10, bool keepAlive = true, int keepAliveCheckInterval = DefaultKeepAliveHealthCheckInterval) + public AmqpConfiguration(string host, int port = DefaultPort, SslOption sslOption = null, string applicationName = "Fiks IO klient (dotnet)", ushort prefetchCount = 10, bool keepAlive = true, int keepAliveCheckInterval = DefaultKeepAliveHealthCheckInterval) { Host = host; Port = port; diff --git a/KS.Fiks.IO.Client/Configuration/ApiConfiguration.cs b/KS.Fiks.IO.Client/Configuration/ApiConfiguration.cs index a4fab686..b4030e11 100644 --- a/KS.Fiks.IO.Client/Configuration/ApiConfiguration.cs +++ b/KS.Fiks.IO.Client/Configuration/ApiConfiguration.cs @@ -4,9 +4,8 @@ public class ApiConfiguration { public const string ProdHost = "api.fiks.ks.no"; public const string TestHost = "api.fiks.test.ks.no"; - private const string DefaultScheme = "https"; - - private const int DefaultPort = 443; + public const string DefaultScheme = "https"; + public const int DefaultPort = 443; public ApiConfiguration(string scheme = null, string host = null, int? port = null) { diff --git a/KS.Fiks.IO.Client/Configuration/FiksIOConfiguration.cs b/KS.Fiks.IO.Client/Configuration/FiksIOConfiguration.cs index fdbdd1de..4452c18d 100644 --- a/KS.Fiks.IO.Client/Configuration/FiksIOConfiguration.cs +++ b/KS.Fiks.IO.Client/Configuration/FiksIOConfiguration.cs @@ -117,5 +117,15 @@ public static MaskinportenClientConfiguration CreateMaskinportenTestConfig(strin numberOfSecondsLeftBeforeExpire: 10, certificate: certificate); } + + public static MaskinportenClientConfiguration CreateMaskinportenConfig(string audience, string tokenEndpoint, string issuer, X509Certificate2 certificate) + { + return new MaskinportenClientConfiguration( + audience: audience, + tokenEndpoint: tokenEndpoint, + issuer: issuer, // KS issuer name + numberOfSecondsLeftBeforeExpire: 10, + certificate: certificate); + } } } \ No newline at end of file diff --git a/KS.Fiks.IO.Client/Configuration/FiksIOConfigurationBuilder.cs b/KS.Fiks.IO.Client/Configuration/FiksIOConfigurationBuilder.cs index c5f35629..1ccd8591 100644 --- a/KS.Fiks.IO.Client/Configuration/FiksIOConfigurationBuilder.cs +++ b/KS.Fiks.IO.Client/Configuration/FiksIOConfigurationBuilder.cs @@ -18,6 +18,13 @@ public class FiksIOConfigurationBuilder private int ampqKeepAliveHealthCheckInterval = AmqpConfiguration.DefaultKeepAliveHealthCheckInterval; private string amqpApplicationName = string.Empty; private ushort amqpPrefetchCount = 10; + private string amqpHost = string.Empty; + private int amqpPort = AmqpConfiguration.DefaultPort; + private string apiHost = string.Empty; + private int apiPort = ApiConfiguration.DefaultPort; + private string apiScheme = ApiConfiguration.DefaultScheme; + private string maskinportenAudience = string.Empty; + private string maskinportenTokenEndpoint = string.Empty; private string maskinportenIssuer = string.Empty; private X509Certificate2 maskinportenCertificate; @@ -28,34 +35,98 @@ public static FiksIOConfigurationBuilder Init() public FiksIOConfiguration BuildTestConfiguration() { - ValidateConfigurations(); + ValidateMinimumConfigurations(); + + if (string.IsNullOrEmpty(amqpHost)) + { + amqpHost = AmqpConfiguration.TestHost; + } + + if (string.IsNullOrEmpty(apiHost)) + { + apiHost = ApiConfiguration.TestHost; + } + + if (string.IsNullOrEmpty(maskinportenAudience)) + { + maskinportenAudience = FiksIOConfiguration.maskinportenTestAudience; + } + + if (string.IsNullOrEmpty(maskinportenTokenEndpoint)) + { + maskinportenTokenEndpoint = FiksIOConfiguration.maskinportenTestTokenEndpoint; + } return new FiksIOConfiguration( - amqpConfiguration: new AmqpConfiguration(AmqpConfiguration.TestHost, applicationName: amqpApplicationName, prefetchCount: amqpPrefetchCount, keepAlive: ampqKeepAlive, keepAliveCheckInterval: ampqKeepAliveHealthCheckInterval), - apiConfiguration: ApiConfiguration.CreateTestConfiguration(), + amqpConfiguration: new AmqpConfiguration(amqpHost, amqpPort, applicationName: amqpApplicationName, prefetchCount: amqpPrefetchCount, keepAlive: ampqKeepAlive, keepAliveCheckInterval: ampqKeepAliveHealthCheckInterval), + apiConfiguration: new ApiConfiguration(apiScheme, apiHost, apiPort), asiceSigningConfiguration: _asiceSigningConfiguration, integrasjonConfiguration: _integrasjonConfiguration, kontoConfiguration: _kontoConfiguration, - maskinportenConfiguration: FiksIOConfiguration.CreateMaskinportenTestConfig(maskinportenIssuer, maskinportenCertificate)); + maskinportenConfiguration: FiksIOConfiguration.CreateMaskinportenConfig(maskinportenAudience, maskinportenTokenEndpoint, maskinportenIssuer, maskinportenCertificate)); } public FiksIOConfiguration BuildProdConfiguration() { - ValidateConfigurations(); + ValidateMinimumConfigurations(); + + if (string.IsNullOrEmpty(amqpHost)) + { + amqpHost = AmqpConfiguration.ProdHost; + } + + if (string.IsNullOrEmpty(apiHost)) + { + apiHost = ApiConfiguration.ProdHost; + } + + if (string.IsNullOrEmpty(maskinportenAudience)) + { + maskinportenAudience = FiksIOConfiguration.maskinportenProdAudience; + } + + if (string.IsNullOrEmpty(maskinportenTokenEndpoint)) + { + maskinportenTokenEndpoint = FiksIOConfiguration.maskinportenProdTokenEndpoint; + } + + return new FiksIOConfiguration( + amqpConfiguration: new AmqpConfiguration(amqpHost, amqpPort, applicationName: amqpApplicationName, prefetchCount: amqpPrefetchCount, keepAlive: ampqKeepAlive), + apiConfiguration: new ApiConfiguration(apiScheme, apiHost, apiPort), + asiceSigningConfiguration: _asiceSigningConfiguration, + integrasjonConfiguration: _integrasjonConfiguration, + kontoConfiguration: _kontoConfiguration, + maskinportenConfiguration: FiksIOConfiguration.CreateMaskinportenConfig(maskinportenAudience, maskinportenTokenEndpoint, maskinportenIssuer, maskinportenCertificate)); + } + + public FiksIOConfiguration BuildConfiguration() + { + ValidateMinimumConfigurations(); + ValidateExtensiveConfiguration(); return new FiksIOConfiguration( - amqpConfiguration: new AmqpConfiguration(AmqpConfiguration.ProdHost, applicationName: amqpApplicationName, prefetchCount: amqpPrefetchCount, keepAlive: ampqKeepAlive), - apiConfiguration: ApiConfiguration.CreateProdConfiguration(), + amqpConfiguration: new AmqpConfiguration(amqpHost, amqpPort, applicationName: amqpApplicationName, prefetchCount: amqpPrefetchCount, keepAlive: ampqKeepAlive), + apiConfiguration: new ApiConfiguration(apiScheme, apiHost, apiPort), asiceSigningConfiguration: _asiceSigningConfiguration, integrasjonConfiguration: _integrasjonConfiguration, kontoConfiguration: _kontoConfiguration, - maskinportenConfiguration: FiksIOConfiguration.CreateMaskinportenProdConfig(maskinportenIssuer, maskinportenCertificate)); + maskinportenConfiguration: FiksIOConfiguration.CreateMaskinportenConfig(maskinportenAudience, maskinportenTokenEndpoint, maskinportenIssuer, maskinportenCertificate)); } - public FiksIOConfigurationBuilder WithMaskinportenConfiguration(X509Certificate2 certificate, string issuer) + public FiksIOConfigurationBuilder WithMaskinportenConfiguration(X509Certificate2 certificate, string issuer, string audience = null, string tokenEndpoint = null) { maskinportenIssuer = issuer; maskinportenCertificate = certificate; + maskinportenAudience = audience; + maskinportenTokenEndpoint = tokenEndpoint; + return this; + } + + public FiksIOConfigurationBuilder WithApiConfiguration(string host, string scheme = ApiConfiguration.DefaultScheme, int port = ApiConfiguration.DefaultPort) + { + apiHost = host; + apiScheme = scheme; + apiPort = port; return this; } @@ -95,26 +166,23 @@ public FiksIOConfigurationBuilder WithFiksKontoConfiguration(Guid fiksKontoId, I return this; } - public FiksIOConfigurationBuilder WithAmqpConfiguration(string applicationName, ushort prefetchCount, bool keepAlive = true, int keepAliveHealthCheckInterval = AmqpConfiguration.DefaultKeepAliveHealthCheckInterval) + public FiksIOConfigurationBuilder WithAmqpConfiguration(string applicationName, ushort prefetchCount, bool keepAlive = true, int keepAliveHealthCheckInterval = AmqpConfiguration.DefaultKeepAliveHealthCheckInterval, string host = null, int port = AmqpConfiguration.DefaultPort ) { ampqKeepAlive = keepAlive; amqpApplicationName = applicationName; amqpPrefetchCount = prefetchCount; ampqKeepAliveHealthCheckInterval = keepAliveHealthCheckInterval; + amqpHost = host; + amqpPort = port; return this; } - public FiksIOConfigurationBuilder WithApiConfiguration(string hostName, int hostPort) - { - return this; - } - - private void ValidateConfigurations() + private void ValidateMinimumConfigurations() { if (string.IsNullOrEmpty(maskinportenIssuer) || maskinportenCertificate == null) { throw new ArgumentException( - "MaskinportenConfiguration missing. Have you called the WithMaskinportenConfiguration( ... ) in this builder?"); + "MaskinportenConfiguration not correct. Have you called the WithMaskinportenConfiguration( ... ) in this builder?"); } if (_integrasjonConfiguration == null) @@ -135,5 +203,32 @@ private void ValidateConfigurations() "AsiceSigningConfiguration missing. Have you called the WithAsiceSigningConfiguration( ... ) in this builder?"); } } + + private void ValidateExtensiveConfiguration() + { + if (string.IsNullOrEmpty(amqpHost)) + { + throw new ArgumentException( + "Amqp setting 'amqpHost' not set. Have you called the WithAmqpConfiguration( ... ) and set 'amqpHost' in this builder?"); + } + + if (string.IsNullOrEmpty(apiHost)) + { + throw new ArgumentException( + "API setting 'apiHost' not set. Have you called the WithApiConfiguration( ... ) in this builder?"); + } + + if (string.IsNullOrEmpty(maskinportenAudience)) + { + throw new ArgumentException( + "Maskinporten setting 'maskinportenAudience' not set. Have you called the WithMaskinportenConfiguration( ... ) and set 'audience' in this builder?"); + } + + if (string.IsNullOrEmpty(maskinportenTokenEndpoint)) + { + throw new ArgumentException( + "Maskinporten setting 'maskinportenTokenEndpoint' not set. Have you called the WithMaskinportenConfiguration( ... ) and set 'tokenEndpoint' in this builder?"); + } + } } } \ No newline at end of file