|
|
|
@ -22,9 +22,13 @@ import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
|
|
"git.cacert.org/cacert-gosigner/pkg/protocol"
|
|
|
|
|
|
|
|
|
|
"git.cacert.org/cacert-gosigner/internal/config"
|
|
|
|
|
"git.cacert.org/cacert-gosigner/internal/handler"
|
|
|
|
|
"git.cacert.org/cacert-gosigner/internal/health"
|
|
|
|
@ -83,6 +87,11 @@ func main() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
framer, err := protocol.NewCOBSFramer(logger)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.WithError(err).Fatal("could not create framer")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
healthHandler := health.New(version, access)
|
|
|
|
|
|
|
|
|
|
revokingRepositories, err := configureRepositories(caConfig, logger)
|
|
|
|
@ -101,7 +110,7 @@ func main() {
|
|
|
|
|
logger.WithError(err).Fatal("could not setup protocol handler")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serialHandler, err := serial.New(caConfig.GetSerial(), logger, proto)
|
|
|
|
|
serialHandler, err := serial.New(caConfig.GetSerial(), logger, framer, proto)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.WithError(err).Fatal("could not setup serial link handler")
|
|
|
|
|
}
|
|
|
|
@ -110,11 +119,33 @@ func main() {
|
|
|
|
|
|
|
|
|
|
logger.Info("setup complete, starting signer operation")
|
|
|
|
|
|
|
|
|
|
if err = serialHandler.Run(context.Background()); err != nil {
|
|
|
|
|
logger.WithError(err).Fatal("error in serial handler")
|
|
|
|
|
if err = runSigner(logger, serialHandler); err != nil {
|
|
|
|
|
logger.WithError(err).Fatal("error running serial handler")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSigner(logger *logrus.Logger, serialHandler *serial.Handler) error {
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
<-c
|
|
|
|
|
|
|
|
|
|
logger.Info("received shutdown signal")
|
|
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err := serialHandler.Run(ctx); err != nil {
|
|
|
|
|
return fmt.Errorf("error from serial handler: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func configureRepositories(
|
|
|
|
|
caConfig *config.SignerConfig,
|
|
|
|
|
logger *logrus.Logger,
|
|
|
|
|