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

hyperledger / identus-cloud-agent / 11682955786

05 Nov 2024 11:10AM UTC coverage: 48.848% (+0.1%) from 48.748%
11682955786

Pull #1433

mineme0110
Invitation generated no processing is required

Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
Pull Request #1433: fix: Warning on Invitation generated on Issuance

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

154 existing lines in 56 files now uncovered.

8060 of 16500 relevant lines covered (48.85%)

0.49 hits per line

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

50.0
/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/CloudAgentApp.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, WalletManagementService}
9
import org.hyperledger.identus.castor.controller.{DIDRegistrarServerEndpoints, DIDServerEndpoints}
10
import org.hyperledger.identus.connect.controller.ConnectionServerEndpoints
11
import org.hyperledger.identus.credentialstatus.controller.CredentialStatusServiceEndpoints
12
import org.hyperledger.identus.event.controller.EventServerEndpoints
13
import org.hyperledger.identus.event.notification.EventNotificationConfig
14
import org.hyperledger.identus.iam.authentication.apikey.ApiKeyAuthenticator
15
import org.hyperledger.identus.iam.entity.http.EntityServerEndpoints
16
import org.hyperledger.identus.iam.wallet.http.WalletManagementServerEndpoints
17
import org.hyperledger.identus.issue.controller.IssueServerEndpoints
18
import org.hyperledger.identus.oid4vci.CredentialIssuerServerEndpoints
19
import org.hyperledger.identus.pollux.credentialdefinition.CredentialDefinitionRegistryServerEndpoints
20
import org.hyperledger.identus.pollux.credentialschema.{
21
  SchemaRegistryServerEndpoints,
22
  VerificationPolicyServerEndpoints
23
}
24
import org.hyperledger.identus.pollux.prex.PresentationExchangeServerEndpoints
25
import org.hyperledger.identus.presentproof.controller.PresentProofServerEndpoints
26
import org.hyperledger.identus.shared.models.*
27
import org.hyperledger.identus.system.controller.SystemServerEndpoints
28
import org.hyperledger.identus.verification.controller.VcVerificationServerEndpoints
29
import zio.*
30
object CloudAgentApp {
31

32
  def run = for {
×
33
    _ <- AgentInitialization.run
×
34
    _ <- ConnectBackgroundJobs.connectFlowsHandler
×
35
    _ <- IssueBackgroundJobs.issueFlowsHandler
×
36
    _ <- PresentBackgroundJobs.presentFlowsHandler
×
37
    _ <- DIDStateSyncBackgroundJobs.didStateSyncTrigger
×
38
    _ <- DIDStateSyncBackgroundJobs.didStateSyncHandler
×
39
    _ <- StatusListJobs.statusListsSyncTrigger
×
40
    _ <- StatusListJobs.statusListSyncHandler
×
41
    _ <- AgentHttpServer.run.tapDefect(e => ZIO.logErrorCause("Agent HTTP Server failure", e)).fork
×
42
    fiber <- DidCommHttpServer.run.tapDefect(e => ZIO.logErrorCause("DIDComm HTTP Server failure", e)).fork
×
43
    _ <- WebhookPublisher.layer.build.map(_.get[WebhookPublisher]).flatMap(_.run.fork)
×
44
    _ <- fiber.join *> ZIO.log(s"Server End")
×
45
    _ <- ZIO.never
×
46
  } yield ()
×
47
}
48

49
object AgentHttpServer {
50
  val agentRESTServiceEndpoints = for {
×
51
    allCredentialDefinitionRegistryEndpoints <- CredentialDefinitionRegistryServerEndpoints.all
×
52
    allSchemaRegistryEndpoints <- SchemaRegistryServerEndpoints.all
×
53
    allVerificationPolicyEndpoints <- VerificationPolicyServerEndpoints.all
×
54
    allConnectionEndpoints <- ConnectionServerEndpoints.all
×
55
    allIssueEndpoints <- IssueServerEndpoints.all
×
56
    allStatusListEndpoints <- CredentialStatusServiceEndpoints.all
×
57
    allDIDEndpoints <- DIDServerEndpoints.all
×
58
    allDIDRegistrarEndpoints <- DIDRegistrarServerEndpoints.all
×
59
    allPresentProofEndpoints <- PresentProofServerEndpoints.all
×
60
    allVcVerificationEndpoints <- VcVerificationServerEndpoints.all
×
61
    allSystemEndpoints <- SystemServerEndpoints.all
×
62
    allEntityEndpoints <- EntityServerEndpoints.all
×
63
    allWalletManagementEndpoints <- WalletManagementServerEndpoints.all
×
64
    allEventEndpoints <- EventServerEndpoints.all
×
65
    allOIDCEndpoints <- CredentialIssuerServerEndpoints.all
×
66
    allPresentationExchangeEndpoints <- PresentationExchangeServerEndpoints.all
×
67
  } yield allCredentialDefinitionRegistryEndpoints ++
×
68
    allSchemaRegistryEndpoints ++
69
    allVerificationPolicyEndpoints ++
70
    allConnectionEndpoints ++
71
    allDIDEndpoints ++
72
    allDIDRegistrarEndpoints ++
73
    allIssueEndpoints ++
74
    allStatusListEndpoints ++
75
    allPresentProofEndpoints ++
76
    allVcVerificationEndpoints ++
77
    allPresentationExchangeEndpoints ++
78
    allSystemEndpoints ++
79
    allEntityEndpoints ++
80
    allWalletManagementEndpoints ++
81
    allEventEndpoints ++
82
    allOIDCEndpoints
83

84
  def run =
×
85
    for {
×
86
      allEndpoints <- agentRESTServiceEndpoints
×
87
      allEndpointsWithDocumentation = ZHttpEndpoints.withDocumentations[Task](allEndpoints)
×
88
      server <- ZHttp4sBlazeServer.make("rest_api")
×
89
      appConfig <- ZIO.service[AppConfig]
×
90
      _ <- server.start(allEndpointsWithDocumentation, port = appConfig.agent.httpEndpoint.http.port).debug
×
91
    } yield ()
×
92
}
93

94
object AgentInitialization {
95

96
  private val defaultWalletId = WalletId.default
1✔
97
  private val defaultWallet = Wallet("default", defaultWalletId)
1✔
98
  private val defaultEntity = Entity.Default
99

100
  def run: RIO[AppConfig & WalletManagementService & EntityService & ApiKeyAuthenticator, Unit] =
1✔
101
    for {
1✔
102
      _ <- validateAppConfig
103
      _ <- initializeDefaultWallet
1✔
104
        .provideSomeLayer(ZLayer.succeed(WalletAdministrationContext.Admin()))
1✔
105
    } yield ()
1✔
106

107
  private val validateAppConfig =
108
    ZIO.serviceWithZIO[AppConfig](conf =>
1✔
109
      ZIO
1✔
110
        .fromEither(conf.validate)
1✔
111
        .mapError(msg => RuntimeException(s"Application configuration is invalid. $msg"))
1✔
112
    )
113

114
  private val initializeDefaultWallet =
115
    for {
1✔
116
      _ <- ZIO.logInfo("Initializing default wallet.")
1✔
117
      config <- ZIO.serviceWith[AppConfig](_.agent.defaultWallet)
1✔
118
      walletService <- ZIO.service[WalletManagementService]
1✔
119
      isDefaultWalletEnabled = config.enabled
120
      isDefaultWalletExist <- walletService
1✔
121
        .findWallet(defaultWalletId)
1✔
122
        .map(_.isDefined)
1✔
123
      _ <- ZIO.logInfo(s"Default wallet not enabled.").when(!isDefaultWalletEnabled)
1✔
124
      _ <- ZIO.logInfo(s"Default wallet already exist.").when(isDefaultWalletExist)
1✔
125
      _ <- createDefaultWallet.when(isDefaultWalletEnabled && !isDefaultWalletExist)
1✔
126
    } yield ()
1✔
127

128
  private val createDefaultWallet =
129
    for {
1✔
130
      walletService <- ZIO.service[WalletManagementService]
1✔
131
      entityService <- ZIO.service[EntityService]
1✔
132
      apiKeyAuth <- ZIO.service[ApiKeyAuthenticator]
1✔
133
      config <- ZIO.serviceWith[AppConfig](_.agent.defaultWallet)
1✔
134
      seed <- config.seed.fold(ZIO.none) { seedHex =>
1✔
135
        ZIO
1✔
136
          .fromTry(HexString.fromString(seedHex))
1✔
137
          .map(bytes => WalletSeed.fromByteArray(bytes.toByteArray).left.map(Exception(_)))
1✔
138
          .absolve
139
          .asSome
140
      }
UNCOV
141
      _ <- ZIO.logInfo(s"Default wallet seed is not provided. New seed will be generated.").when(seed.isEmpty)
×
142
      _ <- walletService
1✔
143
        .createWallet(defaultWallet, seed)
1✔
144
        .orDieAsUnmanagedFailure
1✔
145
      _ <- entityService.create(defaultEntity).orDieAsUnmanagedFailure
1✔
146
      _ <- apiKeyAuth.add(defaultEntity.id, config.authApiKey)
1✔
147
      _ <- config.webhookUrl.fold(ZIO.unit) { url =>
1✔
148
        val customHeaders = config.webhookApiKey.fold(Map.empty)(apiKey => Map("Authorization" -> s"Bearer $apiKey"))
1✔
149
        walletService
150
          .createWalletNotification(EventNotificationConfig(defaultWalletId, url, customHeaders))
1✔
151
          .orDieAsUnmanagedFailure
1✔
152
          .provide(ZLayer.succeed(WalletAccessContext(defaultWalletId)))
1✔
153
      }
154
    } yield ()
1✔
155

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