Skip to content

Commit

Permalink
feat(prism-agent): migrate DID endpoint to tapir (#511)
Browse files Browse the repository at this point in the history
* feat(prism-agent): migrate dids endpoint to tapir

Squashed commit of the following:

commit e9cdac9
Author: Pat Losoponkul <pat.losoponkul@iohk.io>
Date:   Fri Apr 21 18:58:33 2023 +0700

    test

commit 0eddc94
Author: Pat Losoponkul <pat.losoponkul@iohk.io>
Date:   Fri Apr 21 16:50:01 2023 +0700

    pr cleanup

commit 177442b
Author: Pat Losoponkul <pat.losoponkul@iohk.io>
Date:   Fri Apr 21 16:49:31 2023 +0700

    fix: bring back mistakenly removed files

commit 9bc15ce
Author: Pat Losoponkul <pat.losoponkul@iohk.io>
Date:   Fri Apr 21 16:46:18 2023 +0700

    feat(prism-agent): migrate DID endpoints to tapir

    Squashed commit of the following:

    commit fc3226d
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Fri Apr 21 16:40:02 2023 +0700

        docs: add linting doc

    commit 968e71a
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Fri Apr 21 16:34:13 2023 +0700

        chore: include tapir-generated oas

    commit 7b8bae6
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Fri Apr 21 15:03:37 2023 +0700

        chore(prism-agent): remove unused OpenAPI generated classes

    commit 8d36a2e
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Fri Apr 21 13:19:04 2023 +0700

        fix: make test pass

    commit 48f5bba
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Fri Apr 21 12:29:54 2023 +0700

        infra: update apisic route in local deployment

    commit 58656ae
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Mon Apr 17 23:19:51 2023 +0700

        feat(prism-agent): inject contentType value to body

    commit c6da28b
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Mon Apr 17 12:45:13 2023 +0700

        wip: tapir doc & annotations

    commit 2764198
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 23:34:16 2023 +0700

        feat(prism-agent): content-type negotiation on did resolution

    commit 152d326
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 23:05:30 2023 +0700

        fix(prism-agent): allow on did-resolution to be returned

    commit 06c344c
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 21:35:07 2023 +0700

        fix codec response and schema

    commit dabc9dc
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 19:44:44 2023 +0700

        feat(prism-agent): did representation codec

    commit 8716290
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 17:31:30 2023 +0700

        feat(prism-agent): perform actual resolution

    commit 823f3af
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Wed Apr 12 15:18:06 2023 +0700

        feat(prism-agent): align tapir statuscode with the spec

    commit 1e56c61
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Tue Apr 11 19:52:09 2023 +0700

        wip: dynamic status code

    commit b2212c1
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Tue Apr 11 18:51:58 2023 +0700

        wip: add http statuscode binding

    commit e3e7a4c
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Tue Apr 11 18:14:15 2023 +0700

        feat(prism-agent): wire new endpoint to the server

    commit 2c66fdf
    Author: Pat Losoponkul <pat.losoponkul@iohk.io>
    Date:   Tue Apr 11 17:54:38 2023 +0700

        feat(prism-agent): migrate /dids to tapir

* docs(prism-agent): reformat tapir-oas multiline string

* revert linting docs

* feat(prism-agent): customize service tapir schema

* fix: apisix config lint

* remove comment
  • Loading branch information
patlo-iog committed Apr 25, 2023
1 parent b128292 commit 9d587ff
Show file tree
Hide file tree
Showing 34 changed files with 2,101 additions and 553 deletions.
8 changes: 7 additions & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ DISABLE_LINTERS:
SCALA_SCALAFIX,
SQL_TSQLLINT,
]
DISABLE_ERRORS_LINTERS: [KOTLIN_KTLINT, PROTOBUF_PROTOLINT, OPENAPI_SPECTRAL, MARKDOWN_MARKDOWN_LINK_CHECK]
DISABLE_ERRORS_LINTERS:
[
KOTLIN_KTLINT,
PROTOBUF_PROTOLINT,
OPENAPI_SPECTRAL,
MARKDOWN_MARKDOWN_LINK_CHECK,
]

DISABLE: [COPYPASTE, SPELL, CREDENTIALS]
SHOW_ELAPSED_TIME: false
Expand Down
3 changes: 2 additions & 1 deletion .yamllint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
###########################################
# These are the rules used for #
# linting all the yaml files in the stack #
Expand All @@ -15,3 +14,5 @@ rules:
max: 600
comments:
min-spaces-from-content: 1 # Used to follow prettier standard: https://github.com/prettier/prettier/pull/10926
level: warning
document-start: disable
7 changes: 1 addition & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,7 @@ lazy val prismAgentServer = project
Compile / sourceGenerators += openApiGenerateClasses,
openApiGeneratorSpec := baseDirectory.value / ".." / "api" / "http/prism-agent-openapi-spec.yaml",
openApiGeneratorConfig := baseDirectory.value / "openapi/generator-config/config.yaml",
openApiGeneratorImportMapping := Seq(
"DIDDocument",
"DIDResolutionResult"
)
.map(model => (model, s"io.iohk.atala.agent.server.http.model.OASModelPatches.$model"))
.toMap,
openApiGeneratorImportMapping := Map.empty,
Docker / maintainer := "atala-coredid@iohk.io",
Docker / dockerUsername := Some("input-output-hk"),
Docker / dockerRepository := Some("ghcr.io"),
Expand Down
15 changes: 10 additions & 5 deletions infrastructure/shared/apisix/conf/apisix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ routes:
plugins:
proxy-rewrite:
regex_uri: ["^/prism-agent/(.*)", "/$1"]
- uri: /prism-agent/dids*
upstream_id: 4
plugins:
proxy-rewrite:
regex_uri: ["^/prism-agent/dids(/.*)?", "/dids$1"]
- uri: /prism-agent/connections*
upstream_id: 4
plugins:
Expand All @@ -21,7 +26,7 @@ routes:
upstream_id: 4
plugins:
proxy-rewrite:
regex_uri: ["^/prism-agent/connection-invitations", "/connection-invitations"]
uri: "/connection-invitations"
- uri: /didcomm
upstream_id: 3
plugins:
Expand Down Expand Up @@ -66,22 +71,22 @@ upstreams:
type: roundrobin
- id: 2
nodes:
"prism-agent:8080": 1 #api
"prism-agent:8080": 1 # api
type: roundrobin
- id: 3
nodes:
"prism-agent:8090": 1 #didcom
"prism-agent:8090": 1 # didcom
type: roundrobin
- id: 4
nodes:
"prism-agent:8085": 1 #tapir
"prism-agent:8085": 1 # tapir
type: roundrobin
- id: 5
nodes:
"swagger-ui:8080": 1
type: roundrobin
- id: 6
nodes:
"prism-agent:8082": 1 #_system
"prism-agent:8082": 1 # _system
type: roundrobin
#END
18 changes: 0 additions & 18 deletions prism-agent/service/api/http/castor/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,3 @@ components:
schema:
type: string
example: did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff
resolutionAcceptOption:
in: header
name: Accept
required: false
description: |
Represents [accept resolution option](https://www.w3.org/TR/did-core/#did-resolution-options).
For [DID resolution result](https://w3c-ccg.github.io/did-resolution/#did-resolution-result), `application/ld+json;profile="https://w3id.org/did-resolution"` can be used.
For [DID document representation](https://www.w3.org/TR/did-core/#representations), `application/<format>` can be used.
Default to `application/ld+json;profile="https://w3id.org/did-resolution"` if not specified.
schema:
type: string
enum:
- application/did+ld+json
- application/ld+json;profile="https://w3id.org/did-resolution"
example: application/ld+json;profile="https://w3id.org/did-resolution"
188 changes: 2 additions & 186 deletions prism-agent/service/api/http/castor/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,138 +8,6 @@ components:
scheduledOperation:
$ref: "#/components/schemas/DidOperationSubmission"

DIDResolutionResult:
type: object
required:
- "@context"
- didDocumentMetadata
- didResolutionMetadata
properties:
"@context":
type: string
example: "https://w3id.org/did-resolution/v1"
didDocument:
$ref: "#/components/schemas/DIDDocument"
didDocumentMetadata:
$ref: "#/components/schemas/DIDDocumentMetadata"
didResolutionMetadata:
$ref: "#/components/schemas/DIDResolutionMetadata"

DIDDocument:
type: object
description: A W3C compliant Prism DID document representation.
required:
- "@context"
- id
properties:
"@context":
type: array
items:
type: string
example: "https://www.w3.org/ns/did/v1"
id:
type: string
description: |
[DID subject](https://www.w3.org/TR/did-core/#did-subject).
The value must match the DID that was given to the resolver.
example: "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff"
controller:
type: string
description: |
[DID controller](https://www.w3.org/TR/did-core/#did-controller)
example: "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff"
verificationMethod:
type: array
items:
$ref: "#/components/schemas/VerificationMethod"
authentication:
type: array
items:
$ref: "#/components/schemas/VerificationMethodRef"
assertionMethod:
type: array
items:
$ref: "#/components/schemas/VerificationMethodRef"
keyAgreement:
type: array
items:
$ref: "#/components/schemas/VerificationMethodRef"
capabilityInvocation:
type: array
items:
$ref: "#/components/schemas/VerificationMethodRef"
capabilityDelegation:
type: array
items:
$ref: "#/components/schemas/VerificationMethodRef"
service:
type: array
items:
$ref: "#/components/schemas/Service"

DIDDocumentMetadata:
type: object
description: |
[DID document metadata](https://www.w3.org/TR/did-core/#did-document-metadata)
properties:
deactivated:
type: boolean
description: If a DID has been deactivated, DID document metadata MUST include this property with the boolean value true. If a DID has not been deactivated, this property is OPTIONAL, but if included, MUST have the boolean value false.
canonicalId:
type: string
description: |
A DID in canonical form.
If a DID is in long form and has been published, DID document metadata MUST contain a `canonicalId`` property with the short form DID as its value.
If a DID in short form or has not been published, DID document metadata MUST NOT contain a `canonicalId` property.
DIDResolutionMetadata:
type: object
description: |
[DID resolution metadata](https://www.w3.org/TR/did-core/#did-resolution-metadata)
properties:
error:
type: string
description: Resolution error constant according to [DID spec registries](https://www.w3.org/TR/did-spec-registries/#error)
example: invalidDid
errorMessage:
type: string
description: Resolution error message
example: The initialState does not match the suffix
contentType:
type: string
description: The media type of the returned DID document
example: application/did+ld+json

VerificationMethod:
type: object
description: |
A cryptographic public key expressed in the DID document.
https://www.w3.org/TR/did-core/#verification-methods
required:
- id
- type
- controller
- publicKeyJwk
properties:
id:
type: string
example: "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff#key-1"
type:
type: string
example: "EcdsaSecp256k1VerificationKey2019"
controller:
type: string
example: "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff"
publicKeyJwk:
$ref: "#/components/schemas/PublicKeyJwk"

VerificationMethodRef:
type: string
description: A reference to a `verificationMethod`
example: did:prism:c7bd808e8e135236d7262ecf5e639b8f9d22bd886f59a4e6c909486846ca8319#key-1

CreateManagedDidRequest:
type: object
required:
Expand All @@ -159,7 +27,7 @@ components:
services:
type: array
items:
$ref: "#/components/schemas/Service"
$ref: "../tapir-generated.yaml#/components/schemas/Service"

CreateManagedDIDResponse:
type: object
Expand Down Expand Up @@ -209,7 +77,7 @@ components:
description: ID of key to remove from DID document
example: key-1
addService:
$ref: "#/components/schemas/Service"
$ref: "../tapir-generated.yaml#/components/schemas/Service"
removeService:
type: object
required:
Expand Down Expand Up @@ -274,58 +142,6 @@ components:
- PUBLICATION_PENDING
- PUBLISHED

PublicKeyJwk:
type: object
required:
- kty
properties:
crv:
type: string
example: "secp256k1"
x:
type: string
example: "38M1FDts7Oea7urmseiugGW7tWc3mLpJh6rKe7xINZ8"
y:
type: string
example: "nDQW6XZ7b_u2Sy9slofYLlG03sOEoug3I0aAPQ0exs4"
kty:
type: string
example: "EC"

Service:
type: object
description: |
A service expressed in the DID document.
https://www.w3.org/TR/did-core/#services
required:
- id
- type
- serviceEndpoint
properties:
id:
type: string
example: "service-1"
type:
type: string
description: |
Service type.
Can contain multiple possible values as described in the [Create DID operation](https://github.com/input-output-hk/prism-did-method-spec/blob/main/w3c-spec/PRISM-method.md#create-did) under the construction section.
*Known issue: This is currently misaligned with Prism DID method. This will be fixed in the future version of Prism Agent*
enum:
- LinkedDomains
example: LinkedDomains
serviceEndpoint:
type: array
description: |
Application service endpoints.
Can contain multiple possible values as described in the [Create DID operation](https://github.com/input-output-hk/prism-did-method-spec/blob/main/w3c-spec/PRISM-method.md#create-did) under the construction section.
*Known issue: This is currently misaligned with Prism DID method. This will be fixed in the future version of Prism Agent*
items:
type: string
example: "https://bar.example.com/"

ManagedDIDKeyTemplate:
type: object
description: key-pair template to add to DID document.
Expand Down
59 changes: 1 addition & 58 deletions prism-agent/service/api/http/prism-agent-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,64 +40,7 @@ paths:
# Castor
# ----------------------------------
/dids/{didRef}:
get:
operationId: getDid
tags: ["DID"]
summary: Resolve Prism DID to a W3C representation
description: |
Resolve Prism DID to a W3C DID document representation.
The response can be the [DID resolution result](https://w3c-ccg.github.io/did-resolution/#did-resolution-result)
or [DID document representation](https://www.w3.org/TR/did-core/#representations) depending on the `Accept` request header.
The response is implemented according to [resolver HTTP binding](https://w3c-ccg.github.io/did-resolution/#bindings-https) in the DID resolution spec.
parameters:
- $ref: "./castor/parameters.yaml#/components/parameters/didRefInPath"
- $ref: "./castor/parameters.yaml#/components/parameters/resolutionAcceptOption"
responses:
"200":
description: The resolution result or W3C DID document representation
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
application/did+ld+json:
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDDocument"
"400":
description: Invalid input
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
"404":
description: Not found
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
"406":
description: Representation not supported
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
"410":
description: DID Deactivated
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
"500":
description: Internal error
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
"501":
description: Method not supported
content:
application/ld+json;profile="https://w3id.org/did-resolution":
schema:
$ref: "./castor/schemas.yaml#/components/schemas/DIDResolutionResult"
$ref: "./tapir-generated.yaml#/paths/~1dids~1{didRef}"

/did-registrar/dids:
get:
Expand Down

0 comments on commit 9d587ff

Please sign in to comment.