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

hyperledger / identus-cloud-agent / 8967352761

06 May 2024 09:58AM UTC coverage: 47.583% (-1.7%) from 49.29%
8967352761

Pull #909

patlo-iog
Merge branch 'main' into oidc
Pull Request #909: feat(agent): define the OAS for CredentialIssuerEndpoints [WIP]

48 of 618 new or added lines in 31 files covered. (7.77%)

194 existing lines in 65 files now uncovered.

7362 of 15472 relevant lines covered (47.58%)

0.48 hits per line

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

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

3
import zio.*
4
import io.lemonlabs.uri.{DataUrl, Uri, Url, Urn}
5

6
trait UriResolver {
7

8
  def resolve(uri: String): IO[GenericUriResolverError, String]
9

10
}
11

12
class GenericUriResolver(resolvers: Map[String, UriResolver]) extends UriResolver {
13

14
  override def resolve(uri: String): IO[GenericUriResolverError, String] = {
1✔
15
    val parsedUri = Uri.parse(uri)
1✔
16
    parsedUri match
17
      case url: Url =>
1✔
18
        url.schemeOption.fold(ZIO.fail(InvalidUri(uri)))(schema =>
1✔
UNCOV
19
          resolvers.get(schema).fold(ZIO.fail(UnsupportedUriSchema(schema)))(resolver => resolver.resolve(uri))
×
20
        )
21

22
      case Urn(path) => ZIO.fail(InvalidUri(uri)) // Must be a URL
×
23
  }
24

25
}
26

27
class DataUrlResolver extends UriResolver {
28
  override def resolve(dataUrl: String): IO[GenericUriResolverError, String] = {
1✔
29

30
    DataUrl.parseOption(dataUrl).fold(ZIO.fail(InvalidUri(dataUrl))) { url =>
1✔
31
      ZIO.succeed(String(url.data, url.mediaType.charset))
1✔
32
    }
33

34
  }
35

36
}
37

38
sealed trait GenericUriResolverError {
39
  def toThrowable: Throwable = {
×
40
    this match
41
      case InvalidUri(uri)              => new RuntimeException(s"Invalid URI: $uri")
×
42
      case UnsupportedUriSchema(schema) => new RuntimeException(s"Unsupported URI schema: $schema")
×
43
      case SchemaSpecificResolutionError(schema, error) =>
×
44
        new RuntimeException(s"Error resolving ${schema} URL: ${error.getMessage}")
×
45
  }
46
}
47

48
case class InvalidUri(uri: String) extends GenericUriResolverError
49

50
case class UnsupportedUriSchema(schema: String) extends GenericUriResolverError
51

52
case class SchemaSpecificResolutionError(schema: String, error: Throwable) extends GenericUriResolverError
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