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

hyperledger / identus-cloud-agent / 11908762205

19 Nov 2024 08:09AM UTC coverage: 48.809% (-0.04%) from 48.848%
11908762205

Pull #1441

web-flow
Merge branch 'main' into fix/kafka-consumer-not-picking-messages
Pull Request #1441: fix: Kafka consumer not picking messages

0 of 1 new or added line in 1 file covered. (0.0%)

6 existing lines in 5 files now uncovered.

8054 of 16501 relevant lines covered (48.81%)

0.49 hits per line

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

33.33
/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, PrismEnvelopeData, StatusCode}
5
import org.hyperledger.identus.shared.utils.Base64Utils
6
import zio.*
7
import zio.json.*
8

9
import scala.util
10
import scala.util.Try
11

12
trait UriResolver {
13

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

16
}
17

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

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

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

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

48
  }
49

50
}
51

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

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

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

70
case class UnsupportedUriSchema(schema: String)
71
    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