Skip to content

Commit

Permalink
Merge branch 'master' into CON-2087-Api
Browse files Browse the repository at this point in the history
  • Loading branch information
hkf-tech committed Jul 29, 2020
2 parents cc91bd3 + 7705a9b commit b8c3ded
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;

namespace SFA.DAS.CommitmentPayments.WebJob.Configuration
Expand All @@ -24,10 +23,10 @@ public class CommitmentPaymentsConfiguration : IConfiguration
public class PaymentEventsApi : IPaymentsEventsApiConfiguration
{
public string ApiBaseUrl { get; set; }
public string Tenant { get; }
public string ClientId { get; }
public string ClientSecret { get; }
public string IdentifierUri { get; }
public string Tenant { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string IdentifierUri { get; set; }

public string ClientToken { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
using SFA.DAS.Configuration;
using SFA.DAS.Configuration.AzureTableStorage;
using SFA.DAS.NLog.Logger;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;
using StructureMap;
using IConfiguration = SFA.DAS.Commitments.Domain.Interfaces.IConfiguration;

Expand All @@ -32,9 +30,6 @@ public DefaultRegistry()

var config = GetConfiguration("SFA.DAS.CommitmentPayments");

For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>()
.Ctor<IPaymentsEventsApiConfiguration>().Is(config.PaymentEventsApi);

For<IConfiguration>().Use(config);
For<CommitmentPaymentsConfiguration>().Use(config);
For<ICurrentDateTime>().Use(x => new CurrentDateTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static IContainer Initialize()
return new Container(c =>
{
c.AddRegistry<DefaultRegistry>();
c.AddRegistry<PaymentsRegistry>();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Net.Http;
using SFA.DAS.CommitmentPayments.WebJob.Configuration;
using SFA.DAS.Http;
using SFA.DAS.Http.TokenGenerators;
using SFA.DAS.NLog.Logger.Web.MessageHandlers;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;
using StructureMap;

namespace SFA.DAS.CommitmentPayments.WebJob.DependencyResolution
{
internal class PaymentsRegistry : Registry
{
public PaymentsRegistry()
{
For<PaymentEventsApi>().Use(c => c.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi);
For<IPaymentsEventsApiConfiguration>().Use(c => c.GetInstance<PaymentEventsApi>());
For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>().Ctor<HttpClient>().Is(c => CreateClient(c));
}

private HttpClient CreateClient(IContext context)
{
var config = context.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi;

HttpClient httpClient = new HttpClientBuilder()
.WithBearerAuthorisationHeader(new AzureActiveDirectoryBearerTokenGenerator(config))
.WithHandler(new RequestIdMessageRequestHandler())
.WithHandler(new SessionIdMessageRequestHandler())
.WithDefaultHeaders()
.Build();

httpClient.DefaultRequestHeaders.Add("api-version", "2");

return httpClient;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
<Compile Include="Configuration\CommitmentPaymentsConfiguration.cs" />
<Compile Include="DependencyResolution\DefaultRegistry.cs" />
<Compile Include="DependencyResolution\IoC.cs" />
<Compile Include="DependencyResolution\PaymentsRegistry.cs" />
<Compile Include="Updater\AcademicYearFilterException.cs" />
<Compile Include="Updater\FilterOutAcademicYearRollOverDataLocks.cs" />
<Compile Include="Updater\IFilterOutAcademicYearRollOverDataLocks.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;

namespace SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.Configuration
Expand All @@ -23,10 +22,10 @@ public class AddEpaToApprenticeshipsConfiguration : IConfiguration // is this th
public class PaymentEventsApi : IPaymentsEventsApiConfiguration
{
public string ApiBaseUrl { get; set; }
public string Tenant { get; }
public string ClientId { get; }
public string ClientSecret { get; }
public string IdentifierUri { get; }
public string Tenant { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string IdentifierUri { get; set; }

public string ClientToken { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public DefaultRegistry()
// ms fake would be preferable
For<ICurrentDateTime>().Use(x => new CurrentDateTime());

For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>()
.Ctor<IPaymentsEventsApiConfiguration>().Is(config.PaymentEventsApi);

For<IAssessmentOrgsApiClient>().Use<AssessmentOrgsApiClient>()
.Ctor<string>().Is(config.AssessmentOrgsApiBaseUri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static IContainer Initialize()
var container = new Container(c =>
{
c.AddRegistry<DefaultRegistry>();
c.AddRegistry<PaymentsRegistry>();
});

//Debug.WriteLine(container.WhatDidIScan());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Net.Http;
using SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.Configuration;
using SFA.DAS.Http;
using SFA.DAS.Http.TokenGenerators;
using SFA.DAS.NLog.Logger.Web.MessageHandlers;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;
using StructureMap;

namespace SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.DependencyResolution
{
internal class PaymentsRegistry : Registry
{
public PaymentsRegistry()
{
For<PaymentEventsApi>().Use(c => c.GetInstance<AddEpaToApprenticeshipsConfiguration>().PaymentEventsApi);
For<IPaymentsEventsApiConfiguration>().Use(c => c.GetInstance<PaymentEventsApi>());
For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>().Ctor<HttpClient>().Is(c => CreateClient(c));
}

private HttpClient CreateClient(IContext context)
{
var config = context.GetInstance<AddEpaToApprenticeshipsConfiguration>().PaymentEventsApi;

HttpClient httpClient = new HttpClientBuilder()
.WithBearerAuthorisationHeader(new AzureActiveDirectoryBearerTokenGenerator(config))
.WithHandler(new RequestIdMessageRequestHandler())
.WithHandler(new SessionIdMessageRequestHandler())
.WithDefaultHeaders()
.Build();


return httpClient;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<Compile Include="Configuration\AddEpaToApprenticeshipsConfiguration.cs" />
<Compile Include="DependencyResolution\DefaultRegistry.cs" />
<Compile Include="DependencyResolution\IoC.cs" />
<Compile Include="DependencyResolution\PaymentsRegistry.cs" />
<Compile Include="IAddEpaToApprenticeships.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit b8c3ded

Please sign in to comment.