Skip to content

Commit 8363724

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/userAuth
2 parents 2607136 + 5b3db88 commit 8363724

File tree

57 files changed

+1531
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1531
-549
lines changed

app/authorization/AuthProvider.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim}
2020
import play.api.Configuration
2121

2222
object AuthProvider {
23-
var token = ""
23+
24+
var Token = "" // scalastyle:ignore
2425

2526
/** This method generates JWT token for registering Delphi-Management at the Instance-Registry
2627
*
@@ -30,16 +31,16 @@ import play.api.Configuration
3031

3132
def generateJwt(validFor: Long = 1)(implicit configuration: Configuration): String = {
3233
val jwtSecretKey = configuration.get[String]("play.http.secret.JWTkey")
33-
if (token == "" || !Jwt.isValid(token, jwtSecretKey, Seq(JwtAlgorithm.HS256))) {
34+
if (Token == "" || !Jwt.isValid(Token, jwtSecretKey, Seq(JwtAlgorithm.HS256))) {
3435
val claim = JwtClaim()
3536
.issuedNow
3637
.expiresIn(validFor * 300)
3738
.startsNow
3839
. +("user_id", configuration.get[String]("play.http.instance"))
3940
. +("user_type", "Admin")
4041

41-
token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256)
42+
Token = Jwt.encode(claim, jwtSecretKey, JwtAlgorithm.HS256)
4243
}
43-
token
44+
Token
4445
}
4546
}

app/controllers/ApiRouter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ class ApiRouter @Inject()(irController: InstanceRegistryController, sysControlle
4343
case POST(p"/pauseInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/pause", instanceID)
4444
case POST(p"/resumeInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/resume", instanceID)
4545
case POST(p"/deleteInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/delete", instanceID)
46-
46+
case POST(p"/reconnectInstance" ? q"from=$from"& q"to=$to") => irController.reconnect(from.toInt, to.toInt)
4747
}
4848
}

app/controllers/InstanceRegistryController.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
151151
}(myExecutionContext)
152152
}
153153

154+
def reconnect(from: Int, to: Int): Action[AnyContent] = Action.async { request =>
155+
156+
ws.url(instanceRegistryUri + "/instances/" + from + "/assignInstance"
157+
)
158+
.withHttpHeaders(("Authorization", s"Bearer ${AuthProvider.generateJwt()}"))
159+
.post(Json.obj("AssignedInstanceId" -> to))
160+
.map { response =>
161+
response.status match {
162+
case 200 =>
163+
Ok(response.body)
164+
case x =>
165+
new Status(x)
166+
}
167+
}(myExecutionContext)
168+
}
154169
/**
155170
* This function is for handling an POST request for adding an instance to the Scala web server
156171
* (E.g. .../instances/deploy
@@ -190,4 +205,4 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
190205
}
191206
}
192207
}
193-
}
208+
}

0 commit comments

Comments
 (0)