@@ -26,13 +26,13 @@ import play.api.libs.ws.WSClient
2626import akka .stream .Materializer
2727import play .api .libs .streams .ActorFlow
2828import actors .{ClientSocketActor , PublishSocketMessageActor }
29- import akka .http .scaladsl .model .headers .{Authorization , BasicHttpCredentials }
3029import play .api .mvc ._
3130import scala .concurrent .ExecutionContext
3231import authorization .AuthProvider
3332import play .api .libs .json .Json
3433
3534
35+
3636trait MyExecutionContext extends ExecutionContext
3737
3838/**
@@ -63,17 +63,15 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
6363
6464 val instanceRegistryUri = config.get[String ](" app.instanceRegistryUri" )
6565 val instanceRegistryBasePath = config.get[String ](" app.instanceRegistryBasePath" )
66- val authheader = (" Authorization" ,s " Bearer ${AuthProvider .generateJwt()}" )
6766
6867 /** This method maps list of instances with specific componentType.
6968 *
7069 * @param componentType
7170 * @return
7271 */
7372 def instances (componentType : String ): Action [AnyContent ] = Action .async {
74-
7573 ws.url(instanceRegistryUri).addQueryStringParameters(" ComponentType" -> componentType)
76- .withHttpHeaders(authheader )
74+ .withHttpHeaders(( " Authorization " , s " Bearer ${ AuthProvider .generateJwt()} " ) )
7775 .get().map { response =>
7876 // TODO: possible handling of parsing the data can be done here
7977
@@ -96,8 +94,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
9694 */
9795
9896 def getNetwork (): Action [AnyContent ] = Action .async {
99-
100- ws.url(instanceRegistryUri + " /instances/network" ).withHttpHeaders(authheader)
97+ ws.url(instanceRegistryUri + " /instances/network" ).withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
10198 .get().map { response =>
10299 // TODO: possible handling of parsing the data can be done here
103100 Logger .debug(response.body)
@@ -121,7 +118,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
121118 // TODO: handle what should happen if the instance registry is not reachable.
122119 // TODO: create constants for the urls
123120 ws.url(instanceRegistryUri + " /count" ).addQueryStringParameters(" ComponentType" -> componentType)
124- .withHttpHeaders(authheader )
121+ .withHttpHeaders(( " Authorization " , s " Bearer ${ AuthProvider .generateJwt()} " ) )
125122 .get().map { response =>
126123 // TODO: possible handling of parsing the data can be done here
127124 if (response.status == 200 ) {
@@ -142,7 +139,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
142139
143140 def handleRequest (action : String , instanceID : String ): Action [AnyContent ] = Action .async { request =>
144141 ws.url(instanceRegistryUri + " /instances/" + instanceID + action)
145- .withHttpHeaders(authheader )
142+ .withHttpHeaders(( " Authorization " , s " Bearer ${ AuthProvider .generateJwt()} " ) )
146143 .post(" " )
147144 .map { response =>
148145 new Status (response.status)
@@ -176,7 +173,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
176173 {
177174 request =>
178175 ws.url(instanceRegistryUri + " /instances/deploy" )
179- .withHttpHeaders(authheader )
176+ .withHttpHeaders(( " Authorization " , s " Bearer ${ AuthProvider .generateJwt()} " ) )
180177 .post(Json .obj(" ComponentType" -> compType, " InstanceName" -> name))
181178 .map { response =>
182179 response.status match {
@@ -189,28 +186,4 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
189186 }
190187 }(myExecutionContext)
191188 }
192-
193- /**
194- * This function is to authenticate Delphi-Management at the Instance Registry
195- *
196- */
197- // This method might be helpful when User Authentication is implemented.
198- def authentication ()(implicit configuration : Configuration ): Action [AnyContent ] = Action .async {
199-
200- val username = configuration.get[String ](" play.http.user" )
201- val password = configuration.get[String ](" play.http.pass" )
202- val authHeader = Authorization (BasicHttpCredentials (username, password))
203- ws.url(instanceRegistryUri + " /authenticate" )
204- .withHttpHeaders((" Authorization" , s " ${authHeader}" ), (" Delphi-Authorization" ,s " ${AuthProvider .generateJwt()}" ))
205- .post(" " )
206- .map { response =>
207- if (response.status == 200 )
208- {
209- Ok
210- } else
211- {
212- new Status (response.status)
213- }
214- }
215- }
216- }
189+ }
0 commit comments