From 611c6dadd21003f4449a5007af726734d0eac2fd Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Tue, 28 May 2024 08:28:36 +0100 Subject: [PATCH] Break out functions. --- main.go | 98 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/main.go b/main.go index 2beec36..ad6db11 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ import ( prometheusmetrics "github.com/attestantio/dirk/services/metrics/prometheus" "github.com/attestantio/dirk/services/peers" staticpeers "github.com/attestantio/dirk/services/peers/static" + "github.com/attestantio/dirk/services/process" standardprocess "github.com/attestantio/dirk/services/process/standard" "github.com/attestantio/dirk/services/ruler" goruler "github.com/attestantio/dirk/services/ruler/golang" @@ -587,45 +588,22 @@ func startSender(ctx context.Context, return senderSvc, nil } -func startGrpcServer(ctx context.Context, +func startProcess(ctx context.Context, monitor metrics.Service, majordomoSvc majordomo.Service, + serverID uint64, stores []e2wtypes.Store, unlockerSvc unlocker.Service, checkerSvc checker.Service, fetcherSvc fetcher.Service, - rulerSvc ruler.Service, + peersSvc peers.Service, + certPEMBlock []byte, + keyPEMBlock []byte, + caPEMBlock []byte, ) ( - *grpcapi.Service, + process.Service, error, ) { - // Set up the lister. - listerSvc, err := startLister(ctx, monitor, fetcherSvc, checkerSvc, rulerSvc) - if err != nil { - return nil, err - } - - // Set up the signec. - signerSvc, err := startSigner(ctx, monitor, fetcherSvc, checkerSvc, unlockerSvc, rulerSvc) - if err != nil { - return nil, err - } - - peersSvc, err := startPeers(ctx, monitor) - if err != nil { - return nil, err - } - - serverID, err := strconv.ParseUint(viper.GetString("server.id"), 10, 64) - if err != nil { - return nil, errors.Wrap(err, "failed to obtain server ID") - } - - certPEMBlock, keyPEMBlock, caPEMBlock, err := obtainCerts(ctx, majordomoSvc) - if err != nil { - return nil, err - } - sender, err := startSender(ctx, monitor, certPEMBlock, keyPEMBlock, caPEMBlock) if err != nil { return nil, err @@ -661,6 +639,65 @@ func startGrpcServer(ctx context.Context, return nil, errors.Wrap(err, "failed to create process service") } + return processSvc, nil +} + +func startGrpcServer(ctx context.Context, + monitor metrics.Service, + majordomoSvc majordomo.Service, + stores []e2wtypes.Store, + unlockerSvc unlocker.Service, + checkerSvc checker.Service, + fetcherSvc fetcher.Service, + rulerSvc ruler.Service, +) ( + *grpcapi.Service, + error, +) { + // Set up the lister. + listerSvc, err := startLister(ctx, monitor, fetcherSvc, checkerSvc, rulerSvc) + if err != nil { + return nil, err + } + + // Set up the signec. + signerSvc, err := startSigner(ctx, monitor, fetcherSvc, checkerSvc, unlockerSvc, rulerSvc) + if err != nil { + return nil, err + } + + peersSvc, err := startPeers(ctx, monitor) + if err != nil { + return nil, err + } + + serverID, err := strconv.ParseUint(viper.GetString("server.id"), 10, 64) + if err != nil { + return nil, errors.Wrap(err, "failed to obtain server ID") + } + + certPEMBlock, keyPEMBlock, caPEMBlock, err := obtainCerts(ctx, majordomoSvc) + if err != nil { + return nil, err + } + + processSvc, err := startProcess(ctx, + monitor, + majordomoSvc, + serverID, + stores, + unlockerSvc, + checkerSvc, + fetcherSvc, + peersSvc, + certPEMBlock, + keyPEMBlock, + caPEMBlock, + ) + if err != nil { + return nil, err + } + var accountManagerMonitor metrics.AccountManagerMonitor if monitor, isMonitor := monitor.(metrics.AccountManagerMonitor); isMonitor { accountManagerMonitor = monitor @@ -698,7 +735,6 @@ func startGrpcServer(ctx context.Context, if monitor, isMonitor := monitor.(metrics.APIMonitor); isMonitor { apiMonitor = monitor } - svc, err := grpcapi.New(ctx, grpcapi.WithLogLevel(util.LogLevel("api")), grpcapi.WithMonitor(apiMonitor),