@@ -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
@@ -92,14 +93,14 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
92
93
*/
93
94
94
95
def users (): Action [AnyContent ] = authAction.async{
95
- ws.url(instanceRegistryUri + " /users " ).withHttpHeaders(( " Authorization " , s " Bearer ${ AuthProvider .generateJwt()} " ))
96
- .get().map { response =>
97
- Logger .debug(response.body)
98
- if (response.status == 200 ) {
99
- Ok (response.body)
100
- } else {
101
- new Status (response.status)
102
- }
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
+ }
103
104
}(myExecutionContext)
104
105
}
105
106
@@ -110,15 +111,16 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
110
111
*/
111
112
112
113
def getNetwork (): Action [AnyContent ] = authAction.async {
113
- ws.url(instanceRegistryUri + " /instances/network" ).withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
114
- .get().map { response =>
115
- // TODO: possible handling of parsing the data can be done here
116
- Logger .debug(response.body)
117
- if (response.status == 200 ) {
118
- Ok (response.body)
119
- } else {
120
- new Status (response.status)
121
- }
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
+ }
122
124
}(myExecutionContext)
123
125
}
124
126
@@ -133,15 +135,16 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
133
135
def numberOfInstances (componentType : String ): Action [AnyContent ] = authAction.async {
134
136
// TODO: handle what should happen if the instance registry is not reachable.
135
137
// TODO: create constants for the urls
136
- ws.url(instanceRegistryUri + " /count" ).addQueryStringParameters(" ComponentType" -> componentType)
137
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt()}" ))
138
- .get().map { response =>
139
- // TODO: possible handling of parsing the data can be done here
140
- if (response.status == 200 ) {
141
- Ok (response.body)
142
- } else {
143
- new Status (response.status)
144
- }
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
+ }
145
148
}(myExecutionContext)
146
149
}
147
150
@@ -155,7 +158,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
155
158
156
159
def handleRequest (action : String , instanceID : String ): Action [AnyContent ] = authAction.async { request =>
157
160
ws.url(instanceRegistryUri + " /instances/" + instanceID + action)
158
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
161
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
159
162
.post(" " )
160
163
.map { response =>
161
164
new Status (response.status)
@@ -173,7 +176,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
173
176
174
177
ws.url(instanceRegistryUri + " /instances/" + from + " /assignInstance"
175
178
)
176
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
179
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
177
180
.post(Json .obj(" AssignedInstanceId" -> to))
178
181
.map { response =>
179
182
response.status match {
@@ -196,7 +199,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
196
199
def postInstance (compType : String , name : String ): Action [AnyContent ] = authAction.async {
197
200
request =>
198
201
ws.url(instanceRegistryUri + " /instances/deploy" )
199
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
202
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
200
203
.post(Json .obj(" ComponentType" -> compType, " InstanceName" -> name))
201
204
.map { response =>
202
205
response.status match {
@@ -233,7 +236,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
233
236
.post(" " )
234
237
.map { response =>
235
238
if (response.status == 200 ) {
236
- Ok (Json .obj( " token " -> response.body, " refreshToken " -> " " ) )
239
+ Ok (response.body)
237
240
} else {
238
241
new Status (response.status)
239
242
}
@@ -253,7 +256,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
253
256
{
254
257
request =>
255
258
ws.url(instanceRegistryUri + " /instances/" + instanceID + " /label" )
256
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
259
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
257
260
.post(Json .obj(" Label" -> label))
258
261
.map { response =>
259
262
response.status match {
@@ -282,11 +285,11 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
282
285
val secret = (json \ " secret" ).as[String ]
283
286
val userType = (json \ " userType" ).as[String ]
284
287
ws.url(instanceRegistryUri + " /users" + " /add" )
285
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
288
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
286
289
.post(json)
287
290
.map { response =>
288
291
if (response.status == 200 ) {
289
- Ok (Json .obj( " token " -> response.body, " refreshToken " -> " " ) )
292
+ Ok (response.body)
290
293
} else {
291
294
Logger .info(s " $ws" )
292
295
Logger .debug(s " $ws" )
@@ -304,7 +307,7 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
304
307
def deleteUser ( userID : String ): Action [AnyContent ] = authAction.async {
305
308
request =>
306
309
ws.url(instanceRegistryUri + " /users/" + userID + " /remove" )
307
- .withHttpHeaders((" Authorization" , s " Bearer ${AuthProvider .generateJwt() }" ))
310
+ .withHttpHeaders((" Authorization" , s " Bearer ${request.token }" ))
308
311
.post(" " )
309
312
.map { response =>
310
313
response.status match {
@@ -318,5 +321,22 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
318
321
}(myExecutionContext)
319
322
}
320
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
+ }
321
341
}
322
342
0 commit comments