Skip to content

Commit

Permalink
Fix authorization request handling issue
Browse files Browse the repository at this point in the history
This commit addresses an issue where the client sends an immediate
 authorization response upon receiving the authorization request, which
 might get ignored, causing the client to be stuck waiting for the
 authorization response.

Signed-off-by: Saeed Rezaee <saeed.rezaee@kynetics.it>
  • Loading branch information
SaeedRe committed May 20, 2024
1 parent e0969c9 commit 0d79c6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
LOG.info(message)
feedback(msg.info.id, proceeding, Progress(0, 0), none, message)
become(waitingDownloadAuthorization(state.copy(deplBaseResp = msg.info)))
notificationManager.send(MessageListener.Message.State
.WaitingDownloadAuthorization(false))
waitingAuthJob?.cancel()
waitingAuthJob = launch {
softRequest.onAuthorizationReceive {
softRequest.onAuthorizationReceive(onWaitForAuthorization = {
notificationManager.send(MessageListener.Message.State
.WaitingDownloadAuthorization(false))
}, onGrantAuthorization = {
channel.send(Message.DownloadGranted)
}
})
waitingAuthJob = null
}
}
Expand Down Expand Up @@ -127,8 +128,13 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
}

private suspend fun DeploymentPermitProvider.onAuthorizationReceive(
onWaitForAuthorization: (suspend ()-> Unit)? = null,
onGrantAuthorization: suspend ()-> Unit){
if(downloadAllowed().await()){
//Since downloadAllowed function might be a long-running operation,
// it is better to execute it first and then notify the user about the waiting process
val downloadAllowed = downloadAllowed()
onWaitForAuthorization?.invoke()
if(downloadAllowed.await()){
onGrantAuthorization.invoke()
} else {
LOG.info("Authorization denied for download files")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,28 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {

private suspend fun attemptUpdateDevice(state: State): String {
become(waitingUpdateAuthorization(state))
notificationManager.send(
MessageListener.Message.State.WaitingUpdateAuthorization(state.isUpdateForced))
waitingAuthJob = launch {
softRequest.onAuthorizationReceive {
channel.send(Message.UpdateGranted)
}
softRequest.onAuthorizationReceive(
onWaitForAuthorization = {
notificationManager.send(
MessageListener.Message.State.WaitingUpdateAuthorization(
state.isUpdateForced))
}, onGrantAuthorization = {
channel.send(Message.UpdateGranted)
})
waitingAuthJob = null
}
return "Waiting authorization to update"
}

private suspend fun DeploymentPermitProvider.onAuthorizationReceive(
onWaitForAuthorization: (suspend ()-> Unit)? = null,
onGrantAuthorization: suspend ()-> Unit){
if(updateAllowed().await()){
//Since updateAllowed function might be a long-running operation,
// it is better to execute it first and then notify the user about the waiting process
val updateAllowed = updateAllowed()
onWaitForAuthorization?.invoke()
if(updateAllowed.await()){
onGrantAuthorization.invoke()
} else {
LOG.info("Authorization denied for update")
Expand Down

0 comments on commit 0d79c6a

Please sign in to comment.