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

hyperledger / identus-cloud-agent / 11056380298

26 Sep 2024 04:28PM UTC coverage: 48.66% (+0.05%) from 48.609%
11056380298

Pull #1375

yshyn-iohk
fix: migration to a new eudi.openid4vci library

Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Pull Request #1375: fix: OAS and http clients for Kotliln and TypeScript

34 of 81 new or added lines in 25 files covered. (41.98%)

182 existing lines in 53 files now uncovered.

7860 of 16153 relevant lines covered (48.66%)

0.49 hits per line

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

29.17
/shared/core/src/main/scala/org/hyperledger/identus/shared/http/GenericUriResolver.scala
1
package org.hyperledger.identus.shared.http
2

3
import io.lemonlabs.uri.{Uri, Url, Urn}
4
import org.hyperledger.identus.shared.models.{Failure, StatusCode}
5
import org.hyperledger.identus.shared.models.PrismEnvelopeData
6
import org.hyperledger.identus.shared.utils.Base64Utils
7
import zio.*
8
import zio.json.*
9

10
import scala.util
11
import scala.util.Try
12

13
trait UriResolver {
14

15
  def resolve(uri: String): IO[GenericUriResolverError, String]
16

17
}
18

19
class GenericUriResolver(resolvers: Map[String, UriResolver]) extends UriResolver {
20

21
  override def resolve(uri: String): IO[GenericUriResolverError, String] = {
1✔
22
    val parsedUri = Uri.parseTry(uri)
1✔
23

24
    ZIO.debug(s"Resolving resource from uri: $uri") *>
1✔
25
      ZIO.fromTry(parsedUri).mapError(_ => InvalidUri(uri)).flatMap {
1✔
26
        case url: Url =>
1✔
NEW
27
          url.schemeOption.fold(ZIO.fail(InvalidUri(uri)))(schema =>
×
NEW
28
            resolvers.get(schema).fold(ZIO.fail(UnsupportedUriSchema(schema))) { resolver =>
×
29
              resolver.resolve(uri).flatMap { res =>
1✔
30
                schema match
NEW
31
                  case "did" =>
×
NEW
32
                    res.fromJson[PrismEnvelopeData] match
×
NEW
33
                      case Right(env) =>
×
NEW
34
                        ZIO
×
NEW
35
                          .fromTry(Try(Base64Utils.decodeUrlToString(env.resource)))
×
36
                          .mapError(_ => DidUriResponseNotEnvelope(uri))
NEW
37
                      case Left(err) =>
×
NEW
38
                        ZIO.debug(s"Failed to parse response as PrismEnvelope: $err") *>
×
NEW
39
                          ZIO.debug("Falling back to returning the response as is") *>
×
40
                          ZIO.succeed(res)
41
                  case _ => ZIO.succeed(res)
1✔
42
              }
43
            }
44
          )
45

NEW
46
        case Urn(path) => ZIO.fail(InvalidUri(uri)) // Must be a URL
×
47
      }
48

49
  }
50

51
}
52

53
trait GenericUriResolverError(val statusCode: StatusCode, val userFacingMessage: String) extends Failure {
54
  override val namespace: String = "UriResolver"
55
  def toThrowable: Throwable = {
×
56
    this match
57
      case InvalidUri(uri)              => new RuntimeException(s"Invalid URI: $uri")
×
58
      case UnsupportedUriSchema(schema) => new RuntimeException(s"Unsupported URI schema: $schema")
×
59
  }
60
}
61

62
case class DidUriResponseNotEnvelope(uri: String)
63
    extends GenericUriResolverError(
64
      StatusCode.UnprocessableContent,
65
      s"The response of DID uri resolution was not prism envelope: uri=[$uri]"
×
66
    )
67

68
case class InvalidUri(uri: String)
69
    extends GenericUriResolverError(StatusCode.UnprocessableContent, s"The URI to dereference is invalid: uri=[$uri]")
×
70

71
case class UnsupportedUriSchema(schema: String)
72
    extends GenericUriResolverError(StatusCode.UnprocessableContent, s"Unsupported URI schema: $schema")
×
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