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

hyperledger / identus-cloud-agent / 11407164708

18 Oct 2024 04:02PM CUT coverage: 48.619% (-0.1%) from 48.741%
11407164708

Pull #1400

FabioPinheiro
build: add job Update Dependency Graph

Signed-off-by: FabioPinheiro <fabiomgpinheiro@gmail.com>
Pull Request #1400: build: add job Update Dependency Graph

7867 of 16181 relevant lines covered (48.62%)

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/agent/server/MainApp.scala
1
package org.hyperledger.identus.agent.server
2

3
import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton
4
import io.micrometer.prometheus.{PrometheusConfig, PrometheusMeterRegistry}
5
import org.hyperledger.identus.agent.server.config.AppConfig
6
import org.hyperledger.identus.agent.server.http.ZioHttpClient
7
import org.hyperledger.identus.agent.server.sql.Migrations as AgentMigrations
8
import org.hyperledger.identus.agent.walletapi.service.{
9
  EntityServiceImpl,
10
  ManagedDIDService,
11
  ManagedDIDServiceWithEventNotificationImpl,
12
  WalletManagementServiceImpl
13
}
14
import org.hyperledger.identus.agent.walletapi.sql.{
15
  JdbcDIDNonSecretStorage,
16
  JdbcEntityRepository,
17
  JdbcWalletNonSecretStorage
18
}
19
import org.hyperledger.identus.agent.walletapi.storage.GenericSecretStorage
20
import org.hyperledger.identus.castor.controller.{DIDControllerImpl, DIDRegistrarControllerImpl}
21
import org.hyperledger.identus.castor.core.model.did.{
22
  Service as DidDocumentService,
23
  ServiceEndpoint as DidDocumentServiceEndpoint,
24
  ServiceType as DidDocumentServiceType
25
}
26
import org.hyperledger.identus.castor.core.service.DIDServiceImpl
27
import org.hyperledger.identus.castor.core.util.DIDOperationValidator
28
import org.hyperledger.identus.connect.controller.ConnectionControllerImpl
29
import org.hyperledger.identus.connect.core.service.{ConnectionServiceImpl, ConnectionServiceNotifier}
30
import org.hyperledger.identus.connect.sql.repository.{JdbcConnectionRepository, Migrations as ConnectMigrations}
31
import org.hyperledger.identus.credentialstatus.controller.CredentialStatusControllerImpl
32
import org.hyperledger.identus.didcomm.controller.DIDCommControllerImpl
33
import org.hyperledger.identus.event.controller.EventControllerImpl
34
import org.hyperledger.identus.event.notification.EventNotificationServiceImpl
35
import org.hyperledger.identus.iam.authentication.{DefaultAuthenticator, Oid4vciAuthenticatorFactory}
36
import org.hyperledger.identus.iam.authentication.apikey.JdbcAuthenticationRepository
37
import org.hyperledger.identus.iam.authorization.core.EntityPermissionManagementService
38
import org.hyperledger.identus.iam.authorization.DefaultPermissionManagementService
39
import org.hyperledger.identus.iam.entity.http.controller.{EntityController, EntityControllerImpl}
40
import org.hyperledger.identus.iam.wallet.http.controller.WalletManagementControllerImpl
41
import org.hyperledger.identus.issue.controller.IssueControllerImpl
42
import org.hyperledger.identus.mercury.*
43
import org.hyperledger.identus.oid4vci.controller.CredentialIssuerControllerImpl
44
import org.hyperledger.identus.oid4vci.service.OIDCCredentialIssuerServiceImpl
45
import org.hyperledger.identus.oid4vci.storage.InMemoryIssuanceSessionService
46
import org.hyperledger.identus.pollux.core.service.*
47
import org.hyperledger.identus.pollux.core.service.verification.VcVerificationServiceImpl
48
import org.hyperledger.identus.pollux.credentialdefinition.controller.CredentialDefinitionControllerImpl
49
import org.hyperledger.identus.pollux.credentialschema.controller.{
50
  CredentialSchemaController,
51
  CredentialSchemaControllerImpl,
52
  VerificationPolicyControllerImpl
53
}
54
import org.hyperledger.identus.pollux.prex.controller.PresentationExchangeControllerImpl
55
import org.hyperledger.identus.pollux.prex.PresentationDefinitionValidatorImpl
56
import org.hyperledger.identus.pollux.sql.repository.{
57
  JdbcCredentialDefinitionRepository,
58
  JdbcCredentialRepository,
59
  JdbcCredentialSchemaRepository,
60
  JdbcCredentialStatusListRepository,
61
  JdbcOID4VCIIssuerMetadataRepository,
62
  JdbcPresentationExchangeRepository,
63
  JdbcPresentationRepository,
64
  JdbcVerificationPolicyRepository,
65
  Migrations as PolluxMigrations
66
}
67
import org.hyperledger.identus.presentproof.controller.PresentProofControllerImpl
68
import org.hyperledger.identus.resolvers.DIDResolver
69
import org.hyperledger.identus.system.controller.SystemControllerImpl
70
import org.hyperledger.identus.verification.controller.VcVerificationControllerImpl
71
import zio.*
72
import zio.logging.*
73
import zio.logging.backend.SLF4J
74
import zio.logging.LogFormat.*
75
import zio.metrics.connectors.micrometer
76
import zio.metrics.connectors.micrometer.MicrometerConfig
77
import zio.metrics.jvm.DefaultJvmMetrics
78

79
import java.security.Security
80

81
object MainApp extends ZIOAppDefault {
82

83
  val colorFormat: LogFormat =
84
    fiberId.color(LogColor.YELLOW) |-|
×
85
      line.highlight |-|
×
86
      allAnnotations |-|
87
      cause.highlight
×
88

89
  override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] =
90
    Runtime.removeDefaultLoggers >>> SLF4J.slf4j(colorFormat)
×
91

92
  Security.insertProviderAt(BouncyCastleProviderSingleton.getInstance(), 2)
×
93

94
  // FIXME: remove this when db app user have correct privileges provisioned by k8s operator.
95
  // This should be executed before migration to have correct privilege for new objects.
96
  private val preMigrations = for {
×
97
    _ <- ZIO.logInfo("running pre-migration steps.")
×
98
    appConfig <- ZIO.service[AppConfig].provide(SystemModule.configLayer)
×
99
    _ <- PolluxMigrations
×
100
      .initDbPrivileges(appConfig.pollux.database.appUsername)
×
101
      .provide(RepoModule.polluxTransactorLayer)
×
102
    _ <- ConnectMigrations
×
103
      .initDbPrivileges(appConfig.connect.database.appUsername)
×
104
      .provide(RepoModule.connectTransactorLayer)
×
105
    _ <- AgentMigrations
×
106
      .initDbPrivileges(appConfig.agent.database.appUsername)
×
107
      .provide(RepoModule.agentTransactorLayer)
×
108
  } yield ()
×
109

110
  private val migrations = for {
×
111
    _ <- ZIO.serviceWithZIO[PolluxMigrations](_.migrateAndRepair)
×
112
    _ <- ZIO.serviceWithZIO[ConnectMigrations](_.migrateAndRepair)
×
113
    _ <- ZIO.serviceWithZIO[AgentMigrations](_.migrateAndRepair)
×
114
    _ <- ZIO.logInfo("Running post-migration RLS checks for DB application users")
×
115
    _ <- PolluxMigrations.validateRLS.provide(RepoModule.polluxContextAwareTransactorLayer)
×
116
    _ <- ConnectMigrations.validateRLS.provide(RepoModule.connectContextAwareTransactorLayer)
×
117
    _ <- AgentMigrations.validateRLS.provide(RepoModule.agentContextAwareTransactorLayer)
×
118
  } yield ()
×
119
  override def run: ZIO[Any, Throwable, Unit] = {
×
120

121
    val app = for {
×
122
      _ <- Console
×
123
        .printLine(s"""
×
124
      |██╗██████╗ ███████╗███╗   ██╗████████╗██╗   ██╗███████╗
125
      |██║██╔══██╗██╔════╝████╗  ██║╚══██╔══╝██║   ██║██╔════╝
126
      |██║██║  ██║█████╗  ██╔██╗ ██║   ██║   ██║   ██║███████╗
127
      |██║██║  ██║██╔══╝  ██║╚██╗██║   ██║   ██║   ██║╚════██║
128
      |██║██████╔╝███████╗██║ ╚████║   ██║   ╚██████╔╝███████║
129
      |╚═╝╚═════╝ ╚══════╝╚═╝  ╚═══╝   ╚═╝    ╚═════╝ ╚══════╝
130
      |
131
      | ██████╗██╗      ██████╗ ██╗   ██╗██████╗
132
      |██╔════╝██║     ██╔═══██╗██║   ██║██╔══██╗
133
      |██║     ██║     ██║   ██║██║   ██║██║  ██║
134
      |██║     ██║     ██║   ██║██║   ██║██║  ██║
135
      |╚██████╗███████╗╚██████╔╝╚██████╔╝██████╔╝
136
      | ╚═════╝╚══════╝ ╚═════╝  ╚═════╝ ╚═════╝
137
      |
138
      | █████╗  ██████╗ ███████╗███╗   ██╗████████╗
139
      |██╔══██╗██╔════╝ ██╔════╝████╗  ██║╚══██╔══╝
140
      |███████║██║  ███╗█████╗  ██╔██╗ ██║   ██║
141
      |██╔══██║██║   ██║██╔══╝  ██║╚██╗██║   ██║
142
      |██║  ██║╚██████╔╝███████╗██║ ╚████║   ██║
143
      |╚═╝  ╚═╝ ╚═════╝ ╚══════╝╚═╝  ╚═══╝   ╚═╝
144
      |
145
      |version: ${buildinfo.BuildInfo.version}
146
      |
147
      |""".stripMargin)
×
148
        .ignore
149

150
      appConfig <- ZIO.service[AppConfig].provide(SystemModule.configLayer)
×
151
      // these services are added to any DID document by default when they are created.
152
      defaultDidDocumentServices = Set(
×
153
        DidDocumentService(
154
          id = appConfig.agent.httpEndpoint.serviceName,
155
          serviceEndpoint = DidDocumentServiceEndpoint
156
            .Single(
157
              DidDocumentServiceEndpoint.UriOrJsonEndpoint
158
                .Uri(
159
                  DidDocumentServiceEndpoint.UriValue
160
                    .fromString(appConfig.agent.httpEndpoint.publicEndpointUrl.toString)
×
161
                    .toOption
×
162
                    .get // This will fail if URL is invalid, which will prevent app from starting since public endpoint in config is invalid
×
163
                )
164
            ),
165
          `type` = DidDocumentServiceType.Single(DidDocumentServiceType.Name.fromStringUnsafe("LinkedResourceV1"))
×
166
        )
167
      )
168
      _ <- preMigrations
×
169
      _ <- migrations
×
170

171
      app <- CloudAgentApp.run
×
172
        .provide(
×
173
          DidCommX.liveLayer,
174
          // infra
175
          SystemModule.configLayer,
176
          ZioHttpClient.layer,
177
          // observability
178
          DefaultJvmMetrics.live.unit,
×
179
          SystemControllerImpl.layer,
180
          ZLayer.succeed(PrometheusMeterRegistry(PrometheusConfig.DEFAULT)),
×
181
          ZLayer.succeed(MicrometerConfig.default),
×
182
          micrometer.micrometerLayer,
183
          // controller
184
          ConnectionControllerImpl.layer,
185
          CredentialSchemaControllerImpl.layer,
186
          CredentialDefinitionControllerImpl.layer,
187
          DIDControllerImpl.layer,
188
          DIDRegistrarControllerImpl.layer,
189
          IssueControllerImpl.layer,
190
          CredentialStatusControllerImpl.layer,
191
          PresentProofControllerImpl.layer,
192
          VcVerificationControllerImpl.layer,
193
          VerificationPolicyControllerImpl.layer,
194
          EntityControllerImpl.layer,
195
          WalletManagementControllerImpl.layer,
196
          EventControllerImpl.layer,
197
          DIDCommControllerImpl.layer,
198
          PresentationExchangeControllerImpl.layer,
×
199
          // domain
200
          AppModule.apolloLayer,
201
          AppModule.didJwtResolverLayer,
202
          DIDOperationValidator.layer(),
×
203
          DIDResolver.layer,
204
          GenericUriResolverImpl.layer,
205
          PresentationDefinitionValidatorImpl.layer,
×
206
          // service
207
          ConnectionServiceImpl.layer >>> ConnectionServiceNotifier.layer,
×
208
          CredentialSchemaServiceImpl.layer,
209
          CredentialDefinitionServiceImpl.layer,
210
          CredentialStatusListServiceImpl.layer,
211
          LinkSecretServiceImpl.layer >>> CredentialServiceImpl.layer >>> CredentialServiceNotifier.layer,
×
212
          DIDServiceImpl.layer,
213
          EntityServiceImpl.layer,
214
          ZLayer.succeed(defaultDidDocumentServices) >>> ManagedDIDServiceWithEventNotificationImpl.layer,
×
215
          LinkSecretServiceImpl.layer >>> PresentationServiceImpl.layer >>> PresentationServiceNotifier.layer,
×
216
          VerificationPolicyServiceImpl.layer,
217
          WalletManagementServiceImpl.layer,
218
          VcVerificationServiceImpl.layer,
219
          PresentationExchangeServiceImpl.layer,
×
220
          // authentication
221
          AppModule.builtInAuthenticatorLayer,
222
          AppModule.keycloakAuthenticatorLayer,
223
          AppModule.keycloakPermissionManagementLayer,
224
          DefaultAuthenticator.layer,
225
          DefaultPermissionManagementService.layer,
×
226
          EntityPermissionManagementService.layer,
227
          Oid4vciAuthenticatorFactory.layer,
×
228
          // grpc
229
          GrpcModule.prismNodeStubLayer,
230
          // storage
231
          RepoModule.agentContextAwareTransactorLayer ++ RepoModule.agentTransactorLayer >>> JdbcDIDNonSecretStorage.layer,
×
232
          RepoModule.agentContextAwareTransactorLayer >>> JdbcWalletNonSecretStorage.layer,
×
233
          RepoModule.allSecretStorageLayer,
234
          RepoModule.agentTransactorLayer >>> JdbcEntityRepository.layer,
×
235
          RepoModule.agentTransactorLayer >>> JdbcAuthenticationRepository.layer,
×
236
          RepoModule.connectContextAwareTransactorLayer ++ RepoModule.connectTransactorLayer >>> JdbcConnectionRepository.layer,
×
237
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcCredentialRepository.layer,
×
238
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcCredentialStatusListRepository.layer,
×
239
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcCredentialSchemaRepository.layer,
×
240
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcCredentialDefinitionRepository.layer,
×
241
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcPresentationRepository.layer,
×
242
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcOID4VCIIssuerMetadataRepository.layer,
×
243
          RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcPresentationExchangeRepository.layer,
×
244
          RepoModule.polluxContextAwareTransactorLayer >>> JdbcVerificationPolicyRepository.layer,
×
245
          // oidc
246
          CredentialIssuerControllerImpl.layer,
247
          InMemoryIssuanceSessionService.layer,
248
          OID4VCIIssuerMetadataServiceImpl.layer,
×
249
          OIDCCredentialIssuerServiceImpl.layer,
250
          // event notification service
251
          ZLayer.succeed(500) >>> EventNotificationServiceImpl.layer,
×
252
          // HTTP client
253
          SystemModule.zioHttpClientLayer,
254
          Scope.default,
255
        )
256
    } yield app
257

258
    app.provide(
×
259
      RepoModule.polluxDbConfigLayer(appUser = false) >>> PolluxMigrations.layer,
×
260
      RepoModule.connectDbConfigLayer(appUser = false) >>> ConnectMigrations.layer,
×
261
      RepoModule.agentDbConfigLayer(appUser = false) >>> AgentMigrations.layer,
×
262
    )
263
  }
264

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