@@ -26,7 +26,9 @@ import play.api.libs.ws.WSClient
26
26
import akka .stream .Materializer
27
27
import play .api .libs .streams .ActorFlow
28
28
import actors .{ClientSocketActor , PublishSocketMessageActor }
29
+ import akka .http .scaladsl .model .headers .{Authorization , BasicHttpCredentials }
29
30
import play .api .mvc ._
31
+
30
32
import scala .concurrent .ExecutionContext
31
33
import authorization .AuthProvider
32
34
import play .api .libs .json .Json
@@ -63,8 +65,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
63
65
64
66
val instanceRegistryUri = config.get[String ](" app.instanceRegistryUri" )
65
67
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))
66
71
67
- /** This method maps list of instances with specific componentType.
72
+ /** This method maps list of instances with specific componentType.
68
73
*
69
74
* @param componentType
70
75
* @return
@@ -87,7 +92,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
87
92
}
88
93
}
89
94
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
91
96
* currently registered.
92
97
*
93
98
* @return
@@ -154,21 +159,35 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
154
159
* @param name
155
160
*/
156
161
157
- def postInstance (compType : String , name : String ): Action [AnyContent ] = Action .async
158
- {
162
+ def postInstance (compType : String , name : String ): Action [AnyContent ] = Action .async {
159
163
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(" " )
163
185
.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)
171
190
}
172
- }(myExecutionContext)
191
+ }
173
192
}
174
193
}
0 commit comments