Jan Dittberner
91d4f69a9b
This commit adds the project setup and implements a basic signer client that sends health check commands to the signer.
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
/*
|
|
Copyright 2022 CAcert Inc.
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"os"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"git.cacert.org/cacert-gosigner/pkg/protocol"
|
|
"git.cacert.org/cacert-gosignerclient/internal/client"
|
|
"git.cacert.org/cacert-gosignerclient/internal/config"
|
|
"git.cacert.org/cacert-gosignerclient/internal/handler"
|
|
)
|
|
|
|
var (
|
|
commit = "dev"
|
|
date = "unknown"
|
|
version = "unknown"
|
|
)
|
|
|
|
const (
|
|
defaultConfigFile = "config.yaml"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
showVersion, verbose bool
|
|
configFile, logLevel string
|
|
logger *logrus.Logger
|
|
)
|
|
|
|
logger = logrus.New()
|
|
logger.SetOutput(os.Stdout)
|
|
logger.SetLevel(logrus.InfoLevel)
|
|
|
|
logger.Infof("cacert-gosignerclient %s (%s) - build %s", version, commit, date)
|
|
|
|
flag.StringVar(&configFile, "config", defaultConfigFile, "signer client configuration file")
|
|
flag.BoolVar(&showVersion, "version", false, "show version")
|
|
flag.BoolVar(&verbose, "verbose", false, "verbose output")
|
|
flag.StringVar(&logLevel, "loglevel", "INFO", "log level")
|
|
|
|
flag.Parse()
|
|
|
|
if showVersion {
|
|
return
|
|
}
|
|
|
|
parsedLevel, err := logrus.ParseLevel(logLevel)
|
|
if err != nil {
|
|
logger.WithError(err).Fatal("could not parse log level")
|
|
}
|
|
|
|
logger.SetLevel(parsedLevel)
|
|
|
|
clientConfig, err := config.New(configFile)
|
|
if err != nil {
|
|
logger.WithError(err).Fatal("could not configure client")
|
|
}
|
|
|
|
commands := make(chan *protocol.Command)
|
|
|
|
clientHandler, err := handler.New(clientConfig, logger, commands)
|
|
if err != nil {
|
|
logger.WithError(err).Fatal("could not setup client handler")
|
|
}
|
|
|
|
signerClient, err := client.New(clientConfig, logger, clientHandler, commands)
|
|
if err != nil {
|
|
logger.WithError(err).Fatal("could not setup client")
|
|
}
|
|
|
|
defer func() { _ = signerClient.Close() }()
|
|
|
|
logger.Info("setup complete, starting client operation")
|
|
|
|
if err = signerClient.Run(context.Background()); err != nil {
|
|
logger.WithError(err).Fatal("error in client")
|
|
}
|
|
}
|