Skip to content

Commit

Permalink
✨ Check if the authorities are online (#194)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/epi#36
  • Loading branch information
Findeton authored Apr 12, 2024
1 parent 127c056 commit 258dc15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/controllers/ElectionsApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,36 @@ object ElectionsApi
))
}}

def getAuthoritiesState = Action.async { request =>
Future.sequence(
authorities.keys.map { authorityId =>
val url = eoUrl(authorityId, "public_api/check_state")

WS.url(url).get().map { resp =>
if(resp.status == HTTP.ACCEPTED) {
authorityId -> Json.obj(
"state" -> "ok",
"message" -> ""
)
} else {
authorityId -> Json.obj(
"state" -> "error",
"message" -> s"Error: EO returned status ${resp.status} with body ${resp.body}"
)
}
}.recover {
case e: Exception => authorityId -> Json.obj(
"state" -> "error",
"message" -> s"Exception: ${e.getMessage}"
)
}
}.toSeq
).map { results =>
val res = results.toMap
Ok(response(res))
}
}

def checkAuthorityUser(authority_id: String, username: String, password: String): Boolean = {
if(!authorities.contains(authority_id)) {
Logger.info(s"Authority id not found")
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GET /api/election/:id/results controllers.Electi
GET /api/election/:id/voters controllers.ElectionsApi.getElectionVoters(id: Long)
GET /api/election/:id/stats controllers.ElectionsApi.getElectionStats(id: Long)
GET /api/authorities controllers.ElectionsApi.getAuthorities
GET /api/authorities-state controllers.ElectionsApi.getAuthoritiesState

# ballotbox
POST /api/election/:id/voter/:voterId controllers.BallotboxApi.vote(id: Long, voterId: String)
Expand Down

0 comments on commit 258dc15

Please sign in to comment.