33 using System ;
44 using System . Collections . Generic ;
55 using System . Net . Http ;
6+ using System . Threading ;
67 using System . Threading . Tasks ;
78 using Client ;
89 using Ductus . FluentDocker . Builders ;
1213 using Ductus . FluentDocker . Services ;
1314 using Ductus . FluentDocker . Services . Extensions ;
1415 using EstateManagement . Client ;
16+ using global ::Shared . Logger ;
17+ using SecurityService . Client ;
1518
1619 public class DockerHelper
1720 {
21+ private readonly NlogLogger Logger ;
22+
1823 protected INetworkService TestNetwork ;
19-
24+
25+ public Int32 SecurityServicePort ;
2026 protected Int32 EstateManagementPort ;
2127 protected Int32 TransactionProcessorPort ;
2228 protected Int32 EventStorePort ;
2329
30+ public IContainerService SecurityServiceContainer ;
2431 public IContainerService EstateManagementContainer ;
2532 public IContainerService TransactionProcessorContainer ;
2633 protected IContainerService EventStoreContainer ;
2734
2835 public IEstateClient EstateClient ;
2936 public ITransactionProcessorClient TransactionProcessorClient ;
30- // public HttpClient HttpClient ;
37+ public ISecurityServiceClient SecurityServiceClient ;
3138
3239 protected String EventStoreConnectionString ;
3340
41+ public String SecurityServiceContainerName ;
3442 protected String EstateManagementContainerName ;
3543 protected String TransactionProcessorContainerName ;
3644 protected String EventStoreContainerName ;
3745
46+ public DockerHelper ( NlogLogger logger )
47+ {
48+ this . Logger = logger ;
49+ }
50+
3851 private void SetupTestNetwork ( )
3952 {
4053 // Build a network
@@ -67,6 +80,7 @@ public async Task StartContainersForScenarioRun(String scenarioName)
6780 this . TestId = testGuid ;
6881
6982 // Setup the container names
83+ this . SecurityServiceContainerName = $ "securityservice{ testGuid : N} ";
7084 this . EstateManagementContainerName = $ "estate{ testGuid : N} ";
7185 this . TransactionProcessorContainerName = $ "txnprocessor{ testGuid : N} ";
7286 this . EventStoreContainerName = $ "eventstore{ testGuid : N} ";
@@ -75,6 +89,7 @@ public async Task StartContainersForScenarioRun(String scenarioName)
7589 $ "EventStoreSettings:ConnectionString=ConnectTo=tcp://admin:changeit@{ this . EventStoreContainerName } :1113;VerboseLogging=true;";
7690
7791 this . SetupTestNetwork ( ) ;
92+ this . SetupSecurityServiceContainer ( traceFolder ) ;
7893 this . SetupEventStoreContainer ( traceFolder ) ;
7994 this . SetupEstateManagementContainer ( traceFolder ) ;
8095 this . SetupTransactionProcessorContainer ( traceFolder ) ;
@@ -83,14 +98,17 @@ public async Task StartContainersForScenarioRun(String scenarioName)
8398 this . EstateManagementPort = this . EstateManagementContainer . ToHostExposedEndpoint ( "5000/tcp" ) . Port ;
8499 this . TransactionProcessorPort = this . TransactionProcessorContainer . ToHostExposedEndpoint ( "5002/tcp" ) . Port ;
85100 this . EventStorePort = this . EventStoreContainer . ToHostExposedEndpoint ( "2113/tcp" ) . Port ;
101+ this . SecurityServicePort = this . SecurityServiceContainer . ToHostExposedEndpoint ( "5001/tcp" ) . Port ;
86102
87103 // Setup the base address resolver
88104 Func < String , String > estateManagementBaseAddressResolver = api => $ "http://127.0.0.1:{ this . EstateManagementPort } ";
89105 Func < String , String > transactionProcessorBaseAddressResolver = api => $ "http://127.0.0.1:{ this . TransactionProcessorPort } ";
106+ Func < String , String > securityServiceBaseAddressResolver = api => $ "http://127.0.0.1:{ this . SecurityServicePort } ";
90107
91- this . EstateClient = new EstateClient ( estateManagementBaseAddressResolver , new HttpClient ( ) ) ;
92- this . TransactionProcessorClient = new TransactionProcessorClient ( transactionProcessorBaseAddressResolver , new HttpClient ( ) ) ;
93-
108+ HttpClient httpClient = new HttpClient ( ) ;
109+ this . EstateClient = new EstateClient ( estateManagementBaseAddressResolver , httpClient ) ;
110+ this . TransactionProcessorClient = new TransactionProcessorClient ( transactionProcessorBaseAddressResolver , httpClient ) ;
111+ this . SecurityServiceClient = new SecurityServiceClient ( securityServiceBaseAddressResolver , httpClient ) ;
94112 // TODO: Use this to talk to txn processor until we have a client
95113 //this.HttpClient = new HttpClient();
96114 //this.HttpClient.BaseAddress = new Uri(transactionProcessorBaseAddressResolver(String.Empty));
@@ -100,6 +118,13 @@ public async Task StopContainersForScenarioRun()
100118 {
101119 try
102120 {
121+ if ( this . SecurityServiceContainer != null )
122+ {
123+ this . SecurityServiceContainer . StopOnDispose = true ;
124+ this . SecurityServiceContainer . RemoveOnDispose = true ;
125+ this . SecurityServiceContainer . Dispose ( ) ;
126+ }
127+
103128 if ( this . TransactionProcessorContainer != null )
104129 {
105130 this . TransactionProcessorContainer . StopOnDispose = true ;
@@ -133,13 +158,36 @@ public async Task StopContainersForScenarioRun()
133158 }
134159 }
135160
161+ private void SetupSecurityServiceContainer ( String traceFolder )
162+ {
163+ this . Logger . LogInformation ( "About to Start Security Container" ) ;
164+
165+ this . SecurityServiceContainer = new Builder ( ) . UseContainer ( ) . WithName ( this . SecurityServiceContainerName )
166+ . WithEnvironment ( $ "ServiceOptions:PublicOrigin=http://{ this . SecurityServiceContainerName } :5001",
167+ $ "ServiceOptions:IssuerUrl=http://{ this . SecurityServiceContainerName } :5001",
168+ "ASPNETCORE_ENVIRONMENT=IntegrationTest" ,
169+ "urls=http://*:5001" )
170+ . WithCredential ( "https://www.docker.com" , "stuartferguson" , "Sc0tland" )
171+ . UseImage ( "stuartferguson/securityservice" ) . ExposePort ( 5001 ) . UseNetwork ( new List < INetworkService >
172+ {
173+ this . TestNetwork
174+ } . ToArray ( ) )
175+ . Mount ( traceFolder , "/home/txnproc/trace" , MountType . ReadWrite ) . Build ( ) . Start ( ) . WaitForPort ( "5001/tcp" , 30000 ) ;
176+ Thread . Sleep ( 20000 ) ;
177+
178+ this . Logger . LogInformation ( "Security Service Container Started" ) ;
179+
180+ }
181+
136182 private void SetupEstateManagementContainer ( String traceFolder )
137183 {
138184 // Management API Container
139185 this . EstateManagementContainer = new Builder ( )
140186 . UseContainer ( )
141187 . WithName ( this . EstateManagementContainerName )
142188 . WithEnvironment ( this . EventStoreConnectionString ,
189+ $ "AppSettings:SecurityService=http://{ this . SecurityServiceContainerName } :5001",
190+ $ "SecurityConfiguration:Authority=http://{ this . SecurityServiceContainerName } :5001",
143191 "urls=http://*:5000" ) //,
144192 //"AppSettings:MigrateDatabase=true",
145193 //"EventStoreSettings:START_PROJECTIONS=true",
@@ -159,7 +207,9 @@ private void SetupTransactionProcessorContainer(String traceFolder)
159207 this . TransactionProcessorContainer = new Builder ( )
160208 . UseContainer ( )
161209 . WithName ( this . TransactionProcessorContainerName )
162- . WithEnvironment ( this . EventStoreConnectionString ) //,
210+ . WithEnvironment ( this . EventStoreConnectionString ,
211+ $ "AppSettings:SecurityService=http://{ this . SecurityServiceContainerName } :5001",
212+ $ "SecurityConfiguration:Authority=http://{ this . SecurityServiceContainerName } :5001") //,
163213 //"AppSettings:MigrateDatabase=true",
164214 //"EventStoreSettings:START_PROJECTIONS=true",
165215 //"EventStoreSettings:ContinuousProjectionsFolder=/app/projections/continuous")
0 commit comments