@@ -26,7 +26,9 @@ 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 }
2930import play .api .mvc ._
31+
3032import scala .concurrent .ExecutionContext
3133import authorization .AuthProvider
3234import play .api .libs .json .Json
@@ -63,8 +65,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
6365
6466 val instanceRegistryUri = config.get[String ](" app.instanceRegistryUri" )
6567 val instanceRegistryBasePath = config.get[String ](" app.instanceRegistryBasePath" )
68+ val username = config.get[String ](" play.http.user" )
69+ val password = config.get[String ](" play.http.password" )
70+ val authHeader = Authorization (BasicHttpCredentials (username, password))
6671
67- /** This method maps list of instances with specific componentType.
72+ /** This method maps list of instances with specific componentType.
6873 *
6974 * @param componentType
7075 * @return
@@ -87,7 +92,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
8792 }
8893 }
8994
90- /** Called to fetch network graph of current registry. Contains a list of all instances and all links
95+ /** Called to fetch network graph of current registry. Contains a list of all instances and all links
9196 * currently registered.
9297 *
9398 * @return
@@ -154,21 +159,35 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
154159 * @param name
155160 */
156161
157- def postInstance (compType : String , name : String ): Action [AnyContent ] = Action .async
158- {
162+ def postInstance (compType : String , name : String ): Action [AnyContent ] = Action .async {
159163 request =>
160- ws.url(instanceRegistryUri + " /instances/deploy" )
161- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
162- .post(Json .obj(" ComponentType" -> compType, " InstanceName" -> name))
164+ ws.url(instanceRegistryUri + " /instances/deploy" )
165+ .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
166+ .post(Json .obj(" ComponentType" -> compType, " InstanceName" -> name))
167+ .map { response =>
168+ response.status match {
169+ // scalastyle:off magic.number
170+ case 202 =>
171+ // scalastyle:on magic.number
172+ Ok (response.body)
173+ case x : Any =>
174+ new Status (x)
175+ }
176+ }(myExecutionContext)
177+ }
178+
179+ // This method might be helpful when User Authentication is implemented.
180+
181+ def authentication (): Action [AnyContent ] = Action .async {
182+ ws.url(instanceRegistryUri + " /users" + " /authenticate" )
183+ .withHttpHeaders((" Authorization" , s " ${authHeader}" ), (" Delphi-Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
184+ .post(" " )
163185 .map { response =>
164- response.status match {
165- // scalastyle:off magic.number
166- case 202 =>
167- // scalastyle:on magic.number
168- Ok (response.body)
169- case x : Any =>
170- new Status (x)
186+ if (response.status == 200 ) {
187+ Ok (response.body)
188+ } else {
189+ new Status (response.status)
171190 }
172- }(myExecutionContext)
191+ }
173192 }
174193}
0 commit comments