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

input-output-hk / atala-prism-building-blocks / 8898614027

30 Apr 2024 04:48PM UTC coverage: 49.277% (-0.3%) from 49.553%
8898614027

Pull #993

FabioPinheiro
ci: fix scala-steward after moving repo to hyperledger

Signed-off-by: FabioPinheiro <fabiomgpinheiro@gmail.com>

Update logback-classic to 1.4.14 in main

Update testcontainers-scala-postgresql to 0.41.3 in main

Update sbt-buildinfo to 0.12.0 in main

Update jwt-circe to 9.4.6 in main

Update munit-zio to 0.2.0 in main

Update sbt-native-packager to 1.9.16 in main

Update sbt-release to 1.4.0 in main

Update json-schema-validator to 1.3.3 in main

Update zio-json to 3.8.16 in main

Update tapir-http4s-server-zio to 1.10.5 in main

Update sbt-protoc to 1.0.7 in main

Update compilerplugin to 0.11.15 in main

Update typesafe:config to 1.4.3 in main

Update monocle-core to 3.2.0 in main

Update zio to 2.0.22 in main

Update zio-http to 3.0.0-RC6 in main

Update zio-interop-cats to 23.1.0.2 in main

Update zio-json to 0.6.2 in main

Update zio-logging to 2.1.17 in main

Update zio-metrics-connectors-micrometer to 2.3.1 in main

Update zio-mock to 1.0.0-RC12 in main

Update zio-prelude to 1.0.0-RC24 in main

Update circe-core to 0.14.7 in main

Update quill-doobie to 4.8.3 in main

Update micrometer-core to 1.11.11 in main

Update circe-json-schema to 0.4.1 in main

Update bcpkix-jdk15on to 1.78.1 in main

Update bcprov-jdk15on to 1.78.1 in main

Update didcomm to 0.3.2 in main

Update flyway-core to 9.22.3 in main

Update http4s-blaze-server to 0.23.16 in main

Update keycloak-authz-client to 24.0.3 in main

Update postgresql to 42.2.29 in main

Update sbt to 1.9.9 in main

Update munit to 1.0.0-RC1 in main

Update sbt-scalafmt to 2.5.2 in main

Update scalafmt-core to 3.7.17 in main

Reformat with scalafmt 3.7.17

Executed command: scalafmt --non-interactive

Add 'Reformat with scalafmt 3.7.17' to .git-blame-ignore-revs

Update scalatest to 3.2.18 in main

Update mockito-4-11 to 3.2.18.0 in main

Update sbt-coveralls to 1.3.11 in main

Update sbt-scoverage to 2.0.11 in main

Update slf4j-api to 2.0.13 in main

Update doobie-hikari to 1.0.0-RC5 in main
... (continued)
Pull Request #993: ci: fix scala-steward after moving repo to hyperledger

7 of 29 new or added lines in 3 files covered. (24.14%)

255 existing lines in 77 files now uncovered.

7296 of 14806 relevant lines covered (49.28%)

0.49 hits per line

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

33.9
/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/PrismAgentApp.scala
1
package org.hyperledger.identus.agent.server
2

3
import org.hyperledger.identus.agent.notification.WebhookPublisher
4
import org.hyperledger.identus.agent.server.config.AppConfig
5
import org.hyperledger.identus.agent.server.http.{ZHttp4sBlazeServer, ZHttpEndpoints}
6
import org.hyperledger.identus.agent.server.jobs.*
7
import org.hyperledger.identus.agent.walletapi.model.{Entity, Wallet, WalletSeed}
8
import org.hyperledger.identus.agent.walletapi.service.{EntityService, ManagedDIDService, WalletManagementService}
9
import org.hyperledger.identus.agent.walletapi.storage.DIDNonSecretStorage
10
import org.hyperledger.identus.castor.controller.{DIDRegistrarServerEndpoints, DIDServerEndpoints}
11
import org.hyperledger.identus.castor.core.service.DIDService
12
import org.hyperledger.identus.connect.controller.ConnectionServerEndpoints
13
import org.hyperledger.identus.connect.core.service.ConnectionService
14
import org.hyperledger.identus.credential.status.controller.CredentialStatusServiceEndpoints
15
import org.hyperledger.identus.event.controller.EventServerEndpoints
16
import org.hyperledger.identus.event.notification.EventNotificationConfig
17
import org.hyperledger.identus.iam.authentication.apikey.ApiKeyAuthenticator
18
import org.hyperledger.identus.iam.entity.http.EntityServerEndpoints
19
import org.hyperledger.identus.iam.wallet.http.WalletManagementServerEndpoints
20
import org.hyperledger.identus.issue.controller.IssueServerEndpoints
21
import org.hyperledger.identus.mercury.{DidOps, HttpClient}
22
import org.hyperledger.identus.pollux.core.service.{CredentialService, PresentationService}
23
import org.hyperledger.identus.pollux.credentialdefinition.CredentialDefinitionRegistryServerEndpoints
24
import org.hyperledger.identus.pollux.credentialschema.{
25
  SchemaRegistryServerEndpoints,
26
  VerificationPolicyServerEndpoints
27
}
28
import org.hyperledger.identus.pollux.vc.jwt.DidResolver as JwtDidResolver
29
import org.hyperledger.identus.presentproof.controller.PresentProofServerEndpoints
30
import org.hyperledger.identus.shared.models.{HexString, WalletAccessContext, WalletAdministrationContext, WalletId}
31
import org.hyperledger.identus.resolvers.DIDResolver
32
import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds
33
import org.hyperledger.identus.system.controller.SystemServerEndpoints
34
import org.hyperledger.identus.verification.controller.VcVerificationServerEndpoints
35
import zio.*
36
import zio.metrics.*
37

38
object PrismAgentApp {
39

40
  def run = for {
×
41
    _ <- AgentInitialization.run
×
42
    _ <- issueCredentialDidCommExchangesJob.debug.fork
×
43
    _ <- presentProofExchangeJob.debug.fork
×
44
    _ <- connectDidCommExchangesJob.debug.fork
×
45
    _ <- syncDIDPublicationStateFromDltJob.debug.fork
×
46
    _ <- syncRevocationStatusListsJob.debug.fork
×
47
    _ <- AgentHttpServer.run.fork
×
48
    fiber <- DidCommHttpServer.run.fork
×
49
    _ <- WebhookPublisher.layer.build.map(_.get[WebhookPublisher]).flatMap(_.run.debug.fork)
×
50
    _ <- fiber.join *> ZIO.log(s"Server End")
×
51
    _ <- ZIO.never
×
52
  } yield ()
×
53

54
  private val issueCredentialDidCommExchangesJob: RIO[
55
    AppConfig & DidOps & DIDResolver & JwtDidResolver & HttpClient & CredentialService & DIDNonSecretStorage &
56
      DIDService & ManagedDIDService & PresentationService & WalletManagementService,
57
    Unit
58
  ] =
59
    for {
×
60
      config <- ZIO.service[AppConfig]
×
61
      _ <- (IssueBackgroundJobs.issueCredentialDidCommExchanges @@ Metric
×
62
        .gauge("issuance_flow_did_com_exchange_job_ms_gauge")
×
63
        .trackDurationWith(_.toMetricsSeconds))
×
64
        .repeat(Schedule.spaced(config.pollux.issueBgJobRecurrenceDelay))
×
65
        .unit
66
    } yield ()
×
67

68
  private val presentProofExchangeJob: RIO[
69
    AppConfig & DidOps & DIDResolver & JwtDidResolver & HttpClient & PresentationService & CredentialService &
70
      DIDNonSecretStorage & DIDService & ManagedDIDService & WalletManagementService,
71
    Unit
72
  ] =
73
    for {
×
74
      config <- ZIO.service[AppConfig]
×
75
      _ <- (PresentBackgroundJobs.presentProofExchanges @@ Metric
×
76
        .gauge("present_proof_flow_did_com_exchange_job_ms_gauge")
×
77
        .trackDurationWith(_.toMetricsSeconds))
×
78
        .repeat(Schedule.spaced(config.pollux.presentationBgJobRecurrenceDelay))
×
79
        .unit
80
    } yield ()
×
81

82
  private val connectDidCommExchangesJob: RIO[
83
    AppConfig & DidOps & DIDResolver & HttpClient & ConnectionService & ManagedDIDService & DIDNonSecretStorage &
84
      WalletManagementService,
85
    Unit
86
  ] =
87
    for {
×
88
      config <- ZIO.service[AppConfig]
×
89
      _ <- (ConnectBackgroundJobs.didCommExchanges @@ Metric
×
90
        .gauge("connection_flow_did_com_exchange_job_ms_gauge")
×
91
        .trackDurationWith(_.toMetricsSeconds))
×
92
        .repeat(Schedule.spaced(config.connect.connectBgJobRecurrenceDelay))
×
93
        .unit
94
    } yield ()
×
95

96
  private val syncRevocationStatusListsJob = {
97
    for {
×
98
      config <- ZIO.service[AppConfig]
×
99
      _ <- (StatusListJobs.syncRevocationStatuses @@ Metric
×
100
        .gauge("revocation_status_list_sync_job_ms_gauge")
×
101
        .trackDurationWith(_.toMetricsSeconds))
×
102
        .repeat(Schedule.spaced(config.pollux.syncRevocationStatusesBgJobRecurrenceDelay))
×
103
    } yield ()
×
104
  }
105

106
  private val syncDIDPublicationStateFromDltJob: URIO[ManagedDIDService & WalletManagementService, Unit] =
107
    ZIO
×
108
      .serviceWithZIO[WalletManagementService](_.listWallets().map(_._1))
×
109
      .flatMap { wallets =>
110
        ZIO.foreach(wallets) { wallet =>
×
111
          DIDStateSyncBackgroundJobs.syncDIDPublicationStateFromDlt
×
112
            .provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id)))
×
113
        }
114
      }
115
      .catchAll(e => ZIO.logError(s"error while syncing DID publication state: $e"))
×
116
      .repeat(Schedule.spaced(10.seconds))
×
117
      .unit
118
      .provideSomeLayer(ZLayer.succeed(WalletAdministrationContext.Admin()))
×
119

120
}
121

122
object AgentHttpServer {
123
  val agentRESTServiceEndpoints = for {
×
124
    allCredentialDefinitionRegistryEndpoints <- CredentialDefinitionRegistryServerEndpoints.all
×
125
    allSchemaRegistryEndpoints <- SchemaRegistryServerEndpoints.all
×
126
    allVerificationPolicyEndpoints <- VerificationPolicyServerEndpoints.all
×
127
    allConnectionEndpoints <- ConnectionServerEndpoints.all
×
128
    allIssueEndpoints <- IssueServerEndpoints.all
×
129
    allStatusListEndpoints <- CredentialStatusServiceEndpoints.all
×
130
    allDIDEndpoints <- DIDServerEndpoints.all
×
131
    allDIDRegistrarEndpoints <- DIDRegistrarServerEndpoints.all
×
132
    allPresentProofEndpoints <- PresentProofServerEndpoints.all
×
133
    allVcVerificationEndpoints <- VcVerificationServerEndpoints.all
×
134
    allSystemEndpoints <- SystemServerEndpoints.all
×
135
    allEntityEndpoints <- EntityServerEndpoints.all
×
136
    allWalletManagementEndpoints <- WalletManagementServerEndpoints.all
×
137
    allEventEndpoints <- EventServerEndpoints.all
×
138
  } yield allCredentialDefinitionRegistryEndpoints ++
×
139
    allSchemaRegistryEndpoints ++
140
    allVerificationPolicyEndpoints ++
141
    allConnectionEndpoints ++
142
    allDIDEndpoints ++
143
    allDIDRegistrarEndpoints ++
144
    allIssueEndpoints ++
145
    allStatusListEndpoints ++
146
    allPresentProofEndpoints ++
147
    allVcVerificationEndpoints ++
148
    allSystemEndpoints ++
149
    allEntityEndpoints ++
150
    allWalletManagementEndpoints ++
151
    allEventEndpoints
152
  def run =
×
153
    for {
×
154
      allEndpoints <- agentRESTServiceEndpoints
×
155
      allEndpointsWithDocumentation = ZHttpEndpoints.withDocumentations[Task](allEndpoints)
×
156
      server <- ZHttp4sBlazeServer.make
×
157
      appConfig <- ZIO.service[AppConfig]
×
158
      _ <- server.start(allEndpointsWithDocumentation, port = appConfig.agent.httpEndpoint.http.port).debug
×
159
    } yield ()
×
160
}
161

162
object AgentInitialization {
163

164
  private val defaultWalletId = WalletId.default
1✔
165
  private val defaultWallet = Wallet("default", defaultWalletId)
1✔
166
  private val defaultEntity = Entity.Default
167

168
  def run: RIO[AppConfig & WalletManagementService & EntityService & ApiKeyAuthenticator, Unit] =
1✔
169
    for {
1✔
170
      _ <- validateAppConfig
171
      _ <- initializeDefaultWallet
1✔
172
        .provideSomeLayer(ZLayer.succeed(WalletAdministrationContext.Admin()))
1✔
173
    } yield ()
1✔
174

175
  private val validateAppConfig =
176
    ZIO.serviceWithZIO[AppConfig](conf =>
1✔
177
      ZIO
1✔
178
        .fromEither(conf.validate)
1✔
179
        .mapError(msg => RuntimeException(s"Application configuration is invalid. $msg"))
1✔
180
    )
181

182
  private val initializeDefaultWallet =
183
    for {
1✔
184
      _ <- ZIO.logInfo("Initializing default wallet.")
1✔
185
      config <- ZIO.serviceWith[AppConfig](_.agent.defaultWallet)
1✔
186
      walletService <- ZIO.service[WalletManagementService]
1✔
187
      isDefaultWalletEnabled = config.enabled
188
      isDefaultWalletExist <- walletService
1✔
189
        .getWallet(defaultWalletId)
1✔
190
        .map(_.isDefined)
1✔
191
        .mapError(_.toThrowable)
×
192
      _ <- ZIO.logInfo(s"Default wallet not enabled.").when(!isDefaultWalletEnabled)
1✔
193
      _ <- ZIO.logInfo(s"Default wallet already exist.").when(isDefaultWalletExist)
1✔
194
      _ <- createDefaultWallet.when(isDefaultWalletEnabled && !isDefaultWalletExist)
1✔
195
    } yield ()
1✔
196

197
  private val createDefaultWallet =
198
    for {
1✔
199
      walletService <- ZIO.service[WalletManagementService]
1✔
200
      entityService <- ZIO.service[EntityService]
1✔
201
      apiKeyAuth <- ZIO.service[ApiKeyAuthenticator]
1✔
202
      config <- ZIO.serviceWith[AppConfig](_.agent.defaultWallet)
1✔
203
      seed <- config.seed.fold(ZIO.none) { seedHex =>
1✔
204
        ZIO
1✔
205
          .fromTry(HexString.fromString(seedHex))
1✔
206
          .map(bytes => WalletSeed.fromByteArray(bytes.toByteArray).left.map(Exception(_)))
1✔
207
          .absolve
208
          .asSome
209
      }
210
      _ <- ZIO.logInfo(s"Default wallet seed is not provided. New seed will be generated.").when(seed.isEmpty)
1✔
211
      _ <- walletService
1✔
212
        .createWallet(defaultWallet, seed)
1✔
213
        .mapError(_.toThrowable)
×
214
      _ <- entityService.create(defaultEntity).mapError(e => Exception(e.message))
×
UNCOV
215
      _ <- apiKeyAuth.add(defaultEntity.id, config.authApiKey).mapError(e => Exception(e.message))
×
216
      _ <- config.webhookUrl.fold(ZIO.unit) { url =>
1✔
217
        val customHeaders = config.webhookApiKey.fold(Map.empty)(apiKey => Map("Authorization" -> s"Bearer $apiKey"))
1✔
218
        walletService
1✔
219
          .createWalletNotification(EventNotificationConfig(defaultWalletId, url, customHeaders))
1✔
220
          .mapError(_.toThrowable)
×
221
          .provide(ZLayer.succeed(WalletAccessContext(defaultWalletId)))
1✔
222
      }
223
    } yield ()
1✔
224

225
}
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