Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 202 HTTP code (for DID Comm) #162

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
REPORTS_DIR: "didcomm-v2-mediator-test-suite/target/site/serenity"
DIDCOMM_V2_TESTSUITE_VERSION: "v0.1.0"
DIDCOMM_V2_TESTSUITE_VERSION: "3ed43f8f864ef0ea1cd89a9f81d3f379e8c0c217" # old "v0.1.0"
MEDIATOR_DID: "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwIiwiciI6W10sImEiOlsiZGlkY29tbS92MiJdfQ"
steps:
- name: Checkout mediator
Expand All @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: input-output-hk/didcomm-v2-mediator-test-suite
path: './didcomm-v2-mediator-test-suite'
path: "./didcomm-v2-mediator-test-suite"
ref: ${{ env.DIDCOMM_V2_TESTSUITE_VERSION }}

- name: Setup Java and Scala
Expand All @@ -62,7 +62,7 @@ jobs:
uses: ndeloof/[email protected]
with:
version: v2.19.1 # defaults to 'latest'
legacy: true # will also install in PATH as `docker-compose`
legacy: true # will also install in PATH as `docker-compose`

- name: Build local version of Mediator Agent
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scala.util.Try
import scala.io.Source
import zio.http.Header.AccessControlAllowOrigin
import zio.http.Header.AccessControlAllowMethods
import zio.http.Header.HeaderType

case class MediatorAgent(
override val id: DID,
Expand Down Expand Up @@ -267,53 +268,62 @@ object MediatorAgent {
} yield (ret)
},
Method.POST / trailing -> handler { (req: Request) =>
{
if (
req.headers
.get("content-type")
.exists { h => h == MediaTypes.SIGNED.typ || h == MediaTypes.ENCRYPTED.typ }
) {
for {
agent <- ZIO.service[MediatorAgent]
data <- req.body.asString
.catchAll(ex => ZIO.fail(Response.badRequest("Unable to read the body of the request")))
ret <- agent
.receiveMessage(data)
.map {
case None => Response.ok
case Some(value: SignedMessage) => Response.json(value.toJson)
case Some(value: EncryptedMessage) => Response.json(value.toJson)
}
.catchAll {
case MediatorDidError(error) =>
ZIO.logError(s"Error MediatorDidError: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case MediatorThrowable(error) =>
ZIO.logError(s"Error MediatorThrowable: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case StorageCollection(error) =>
ZIO.logError(s"Error StorageCollection: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case StorageThrowable(error) =>
ZIO.logError(s"Error StorageThrowable: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case DuplicateMessage(error) =>
ZIO.logError(s"Error DuplicateKeyError: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case MissingProtocolError(piuri) =>
ZIO.logError(s"MissingProtocolError ('$piuri')") *>
ZIO.succeed(Response.status(Status.BadRequest)) // TODO
}
} yield ret
} else
ZIO
.logError(s"Request Headers: ${req.headers.mkString(",")}")
.as(
Response
.text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}")
.copy(status = Status.BadRequest)
)
}
if (
req.headers
.get("content-type")
.exists { h => h == MediaTypes.SIGNED.typ || h == MediaTypes.ENCRYPTED.typ }
) {
for {
agent <- ZIO.service[MediatorAgent]
data <- req.body.asString
.catchAll(ex => ZIO.fail(Response.badRequest("Unable to read the body of the request")))
ret <- agent
.receiveMessage(data)
.map {
case None => Response(status = Status.Accepted)
case Some(value: SignedMessage) =>
Response(
status = Status.Accepted,
headers = Headers(Header.ContentType(MediaType.apply("application", "didcomm-signed+json"))),
body = Body.fromCharSequence(value.toJson)
)
case Some(value: EncryptedMessage) =>
Response(
status = Status.Accepted,
headers = Headers(Header.ContentType(MediaType.apply("application", "didcomm-encrypted+json"))),
body = Body.fromCharSequence(value.toJson)
)
}
.catchAll {
case MediatorDidError(error) =>
ZIO.logError(s"Error MediatorDidError: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case MediatorThrowable(error) =>
ZIO.logError(s"Error MediatorThrowable: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case StorageCollection(error) =>
ZIO.logError(s"Error StorageCollection: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case StorageThrowable(error) =>
ZIO.logError(s"Error StorageThrowable: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case DuplicateMessage(error) =>
ZIO.logError(s"Error DuplicateKeyError: $error") *>
ZIO.succeed(Response.status(Status.BadRequest))
case MissingProtocolError(piuri) =>
ZIO.logError(s"MissingProtocolError ('$piuri')") *>
ZIO.succeed(Response.status(Status.BadRequest)) // TODO
}
} yield ret
} else
ZIO
.logError(s"Request Headers: ${req.headers.mkString(",")}")
.as(
Response
.text(s"The content-type must be ${MediaTypes.SIGNED.typ} or ${MediaTypes.ENCRYPTED.typ}")
.copy(status = Status.BadRequest)
)

},
Method.GET / trailing -> handler { (req: Request) =>
for {
Expand Down
Loading