@@ -70,12 +70,13 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
70
70
* @return
71
71
*/
72
72
def instances (componentType : String ): Action [AnyContent ] = authAction.async {
73
- ws.url(instanceRegistryUri).addQueryStringParameters(" ComponentType" -> componentType)
74
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
75
- .get().map { response =>
76
- // TODO: possible handling of parsing the data can be done here
73
+ request =>
74
+ ws.url(instanceRegistryUri).addQueryStringParameters(" ComponentType" -> componentType)
75
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
76
+ .get().map { response =>
77
+ // TODO: possible handling of parsing the data can be done here
77
78
78
- Ok (response.body)
79
+ Ok (response.body)
79
80
}(myExecutionContext)
80
81
}
81
82
@@ -87,22 +88,39 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
87
88
}
88
89
}
89
90
91
+ /** This method lists all Users.
92
+ * @return
93
+ */
94
+
95
+ def users (): Action [AnyContent ] = authAction.async{
96
+ request =>
97
+ ws.url(instanceRegistryUri + " /users" ).withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
98
+ .get().map { response =>
99
+ if (response.status == 200 ) {
100
+ Ok (response.body)
101
+ } else {
102
+ new Status (response.status)
103
+ }
104
+ }(myExecutionContext)
105
+ }
106
+
90
107
/** Called to fetch network graph of current registry. Contains a list of all instances and all links
91
108
* currently registered.
92
109
*
93
110
* @return
94
111
*/
95
112
96
113
def getNetwork (): Action [AnyContent ] = authAction.async {
97
- ws.url(instanceRegistryUri + " /instances/network" ).withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
98
- .get().map { response =>
99
- // TODO: possible handling of parsing the data can be done here
100
- Logger .debug(response.body)
101
- if (response.status == 200 ) {
102
- Ok (response.body)
103
- } else {
104
- new Status (response.status)
105
- }
114
+ request =>
115
+ ws.url(instanceRegistryUri + " /instances/network" ).withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
116
+ .get().map { response =>
117
+ // TODO: possible handling of parsing the data can be done here
118
+ Logger .debug(response.body)
119
+ if (response.status == 200 ) {
120
+ Ok (response.body)
121
+ } else {
122
+ new Status (response.status)
123
+ }
106
124
}(myExecutionContext)
107
125
}
108
126
@@ -117,15 +135,16 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
117
135
def numberOfInstances (componentType : String ): Action [AnyContent ] = authAction.async {
118
136
// TODO: handle what should happen if the instance registry is not reachable.
119
137
// TODO: create constants for the urls
120
- ws.url(instanceRegistryUri + " /count" ).addQueryStringParameters(" ComponentType" -> componentType)
121
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
122
- .get().map { response =>
123
- // TODO: possible handling of parsing the data can be done here
124
- if (response.status == 200 ) {
125
- Ok (response.body)
126
- } else {
127
- new Status (response.status)
128
- }
138
+ request =>
139
+ ws.url(instanceRegistryUri + " /count" ).addQueryStringParameters(" ComponentType" -> componentType)
140
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
141
+ .get().map { response =>
142
+ // TODO: possible handling of parsing the data can be done here
143
+ if (response.status == 200 ) {
144
+ Ok (response.body)
145
+ } else {
146
+ new Status (response.status)
147
+ }
129
148
}(myExecutionContext)
130
149
}
131
150
@@ -139,7 +158,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
139
158
140
159
def handleRequest (action : String , instanceID : String ): Action [AnyContent ] = authAction.async { request =>
141
160
ws.url(instanceRegistryUri + " /instances/" + instanceID + action)
142
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
161
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
143
162
.post(" " )
144
163
.map { response =>
145
164
new Status (response.status)
@@ -157,7 +176,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
157
176
158
177
ws.url(instanceRegistryUri + " /instances/" + from + " /assignInstance"
159
178
)
160
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
179
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
161
180
.post(Json .obj(" AssignedInstanceId" -> to))
162
181
.map { response =>
163
182
response.status match {
@@ -180,7 +199,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
180
199
def postInstance (compType : String , name : String ): Action [AnyContent ] = authAction.async {
181
200
request =>
182
201
ws.url(instanceRegistryUri + " /instances/deploy" )
183
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
202
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
184
203
.post(Json .obj(" ComponentType" -> compType, " InstanceName" -> name))
185
204
.map { response =>
186
205
response.status match {
@@ -203,8 +222,6 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
203
222
204
223
def authentication (): Action [AnyContent ] = Action .async {
205
224
request =>
206
- // val json = request.body.asJson.get
207
-
208
225
209
226
val jsonBody : Option [JsValue ] = request.body.asJson
210
227
@@ -219,7 +236,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
219
236
.post(" " )
220
237
.map { response =>
221
238
if (response.status == 200 ) {
222
- Ok (Json .obj( " token " -> response.body, " refreshToken " -> " " ) )
239
+ Ok (response.body)
223
240
} else {
224
241
new Status (response.status)
225
242
}
@@ -239,7 +256,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
239
256
{
240
257
request =>
241
258
ws.url(instanceRegistryUri + " /instances/" + instanceID + " /label" )
242
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
259
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
243
260
.post(Json .obj(" Label" -> label))
244
261
.map { response =>
245
262
response.status match {
@@ -252,4 +269,74 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
252
269
}
253
270
}(myExecutionContext)
254
271
}
272
+
273
+ /**
274
+ * This function is used to add a User.
275
+ * Username, Secret and UserType are sent in the body post
276
+ * Instance registry returns a valid userID
277
+ * @return
278
+ */
279
+
280
+ def postUser (): Action [AnyContent ] = authAction.async {
281
+ request =>
282
+ val jsonBody : Option [JsValue ] = request.body.asJson
283
+ jsonBody.map { json =>
284
+ val userName = (json \ " userName" ).as[String ]
285
+ val secret = (json \ " secret" ).as[String ]
286
+ val userType = (json \ " userType" ).as[String ]
287
+ ws.url(instanceRegistryUri + " /users" + " /add" )
288
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
289
+ .post(json)
290
+ .map { response =>
291
+ if (response.status == 200 ) {
292
+ Ok (response.body)
293
+ } else {
294
+ Logger .info(s " $ws" )
295
+ Logger .debug(s " $ws" )
296
+ new Status (response.status)
297
+ }
298
+ }
299
+ }.getOrElse{ Future (BadRequest (" Invalid body" ))}
300
+ }
301
+
302
+ /**
303
+ * This function is used to delete a user.
304
+ * @param userID ID of the user that is to be deleted
305
+ * @return
306
+ */
307
+ def deleteUser ( userID : String ): Action [AnyContent ] = authAction.async {
308
+ request =>
309
+ ws.url(instanceRegistryUri + " /users/" + userID + " /remove" )
310
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
311
+ .post(" " )
312
+ .map { response =>
313
+ response.status match {
314
+ // scalastyle:off magic.number
315
+ case 202 =>
316
+ // scalastyle:on magic.number
317
+ Ok (Json .obj(" msg" -> response.body))
318
+ case x : Any =>
319
+ new Status (x)
320
+ }
321
+ }(myExecutionContext)
322
+ }
323
+
324
+ def deleteLabel (instanceID : String , label : String ): Action [AnyContent ] = authAction.async
325
+ {
326
+ request =>
327
+ ws.url(instanceRegistryUri + " /instances/" + instanceID + " /label/" + label + " /delete" )
328
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token}" ))
329
+ .post(" " )
330
+ .map { response =>
331
+ response.status match {
332
+ // scalastyle:off magic.number
333
+ case 202 =>
334
+ // scalastyle:on magic.number
335
+ Ok (response.body)
336
+ case x : Any =>
337
+ new Status (x)
338
+ }
339
+ }(myExecutionContext)
340
+ }
255
341
}
342
+
0 commit comments