• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-cloud-agent / 10793991050

10 Sep 2024 01:56PM CUT coverage: 48.504% (-4.5%) from 52.962%
10793991050

push

web-flow
build: sbt and plugins dependency update (#1337)

Signed-off-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Co-authored-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Co-authored-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>

7406 of 15269 relevant lines covered (48.5%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDEndpoints.scala
1
package org.hyperledger.identus.castor.controller
2

3
import org.hyperledger.identus.api.http.codec.DIDCodec.{didJsonLD, didResolutionJsonLD, emptyDidJsonLD}
4
import org.hyperledger.identus.api.http.RequestContext
5
import org.hyperledger.identus.castor.controller.http.{DIDInput, DIDResolutionResult}
6
import sttp.apispec.Tag
7
import sttp.model.StatusCode
8
import sttp.tapir.*
9

10
object DIDEndpoints {
11

12
  private val tagName = "DID"
13
  private val tagDescription =
14
    s"""
×
15
       |The __${tagName}__ endpoints expose publicly available DID operations.
16
       |
17
       |The key distinction from the __DID Registrar__ endpoints is that it directly exposes the DID resources interfacing with the [VDR](https://www.w3.org/TR/did-core/#dfn-verifiable-data-registry).
18
       |It is independent of the key management and the exposed operations are not part of the tenancy within the Agent.
19
       |It serves as a proxy for interacting with the VDR, facilitating actions like resolving DIDs.
20
       |""".stripMargin
×
21

22
  val tag = Tag(tagName, Some(tagDescription))
×
23

24
  private def matchStatus(sc: StatusCode): PartialFunction[Any, Boolean] = { case result: DIDResolutionResult =>
×
25
    val maybeError = result.didResolutionMetadata.error
26
    val isDeactivated = result.didDocumentMetadata.deactivated.getOrElse(false)
×
27
    maybeError match {
28
      case None if !isDeactivated             => sc == StatusCode.Ok
×
29
      case None                               => sc == StatusCode.Gone
×
30
      case Some("invalidDid")                 => sc == StatusCode.BadRequest
×
31
      case Some("invalidDidUrl")              => sc == StatusCode.BadRequest
×
32
      case Some("notFound")                   => sc == StatusCode.NotFound
×
33
      case Some("representationNotSupported") => sc == StatusCode.NotAcceptable
×
34
      case Some("internalError")              => sc == StatusCode.InternalServerError
×
35
      case Some(_)                            => false
×
36
    }
37
  }
38

39
  val resolutionEndpointOutput = oneOf[DIDResolutionResult](
×
40
    oneOfVariantValueMatcher(
41
      StatusCode.Ok,
42
      oneOf[DIDResolutionResult](
×
43
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
44
        oneOfVariant(stringBodyUtf8AnyFormat(didJsonLD))
×
45
      )
46
    )(matchStatus(StatusCode.Ok)),
×
47
    oneOfVariantValueMatcher(
48
      StatusCode.BadRequest,
49
      oneOf[DIDResolutionResult](
×
50
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
51
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
52
      )
53
    )(matchStatus(StatusCode.BadRequest)),
×
54
    oneOfVariantValueMatcher(
55
      StatusCode.NotFound,
56
      oneOf[DIDResolutionResult](
×
57
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
58
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
59
      )
60
    )(matchStatus(StatusCode.NotFound)),
×
61
    oneOfVariantValueMatcher(
62
      StatusCode.NotAcceptable,
63
      oneOf[DIDResolutionResult](
×
64
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
65
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
66
      )
67
    )(matchStatus(StatusCode.NotAcceptable)),
×
68
    oneOfVariantValueMatcher(
69
      StatusCode.Gone,
70
      oneOf[DIDResolutionResult](
×
71
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
72
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
73
      )
74
    )(matchStatus(StatusCode.Gone)),
×
75
    oneOfVariantValueMatcher(
76
      StatusCode.NotImplemented,
77
      oneOf[DIDResolutionResult](
×
78
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
79
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
80
      )
81
    )(matchStatus(StatusCode.NotImplemented)),
×
82
    oneOfVariantValueMatcher(
83
      StatusCode.InternalServerError,
84
      oneOf[DIDResolutionResult](
×
85
        oneOfVariant(stringBodyUtf8AnyFormat(didResolutionJsonLD)),
×
86
        oneOfVariant(stringBodyUtf8AnyFormat(emptyDidJsonLD))
×
87
      )
88
    )(_ => true),
×
89
  )
90

91
  // MUST conform to https://w3c-ccg.github.io/did-resolution/#bindings-https
92
  val getDID: PublicEndpoint[
93
    (RequestContext, String),
94
    Nothing,
95
    DIDResolutionResult,
96
    Any
97
  ] = infallibleEndpoint.get
×
98
    .in(extractFromRequest[RequestContext](RequestContext.apply))
×
99
    .in("dids" / DIDInput.didRefPathSegment)
×
100
    .out(resolutionEndpointOutput)
101
    .name("getDID")
×
102
    .summary("Resolve Prism DID to a W3C representation")
×
103
    .description(
×
104
      """Resolve Prism DID to a W3C DID document representation.
×
105
        |The response can be the [DID resolution result](https://w3c-ccg.github.io/did-resolution/#did-resolution-result)
106
        |or [DID document representation](https://www.w3.org/TR/did-core/#representations) depending on the `Accept` request header.
107
        |The response is implemented according to [resolver HTTP binding](https://w3c-ccg.github.io/did-resolution/#bindings-https) in the DID resolution spec.
108
        |""".stripMargin
×
109
    )
110
    .tag(tagName)
×
111

112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc