Skip to content

Commit

Permalink
feat: rename backend classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fritterhoff committed Dec 16, 2024
1 parent c87ead9 commit 5241250
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion backend/pki-service/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var runCmd = &cobra.Command{
}

// load Sectigo config
var sectigoCfg cfg.SectigoConfiguration
var sectigoCfg cfg.PKIConfiguration
if err := viper.Unmarshal(&sectigoCfg); err != nil {
logger.Panic("config unmarshal failed", zap.Error(err))
}
Expand Down Expand Up @@ -121,5 +121,7 @@ func init() {
runCmd.Flags().String("mail_from", "", "The mail from")
runCmd.Flags().String("acme_storage", "", "Storage for the internal acme client")
runCmd.Flags().String("acme_email", "", "Email for the acme client")
runCmd.Flags().String("acme_eab", "", "EAB for the acme client")
runCmd.Flags().String("acme_key", "", "Key for the acme client")
runCmd.Flags().String("dns_configs", "", "Config file for the dns provider")
}
2 changes: 1 addition & 1 deletion backend/pki-service/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var syncCmd = &cobra.Command{
defer deferFunc(logger)

// load HTTP server config
var sectigoCfg cfg.SectigoConfiguration
var sectigoCfg cfg.PKIConfiguration
if err := viper.Unmarshal(&sectigoCfg); err != nil {
logger.Panic("config unmarshal failed", zap.Error(err))
}
Expand Down
8 changes: 5 additions & 3 deletions backend/pki-service/pkg/cfg/sectigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"go.uber.org/zap"
)

// SectigoConfiguration handles different configuration properties for the sectigo client
type SectigoConfiguration struct {
// PKIConfiguration handles different configuration properties for the sectigo client
type PKIConfiguration struct {
User string `mapstructure:"sectigo_user"`
Password string `mapstructure:"sectigo_password"`
CustomerURI string `mapstructure:"sectigo_customeruri"`
Expand All @@ -26,11 +26,13 @@ type SectigoConfiguration struct {
SmimeKeyType string `mapstructure:"smime_key_type"`
AcmeStorage string `mapstructure:"acme_storage"`
AcmeEmail string `mapstructure:"acme_email"`
AcmeEab string `mapstructure:"acme_eab"`
AcmeKey string `mapstructure:"acme_key"`
DnsConfigs string `mapstructure:"dns_configs"`
}

// CheckSectigoConfiguration checks the sectigo configuration for the syntactical correctness.
func (cfg *SectigoConfiguration) CheckSectigoConfiguration() {
func (cfg *PKIConfiguration) CheckSectigoConfiguration() {

logger := zap.L()

Expand Down
4 changes: 2 additions & 2 deletions backend/pki-service/pkg/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
type Server struct {
logger *zap.Logger
config *Config
sectigoCfg *cfg.SectigoConfiguration
sectigoCfg *cfg.PKIConfiguration
db *ent.Client
}

Expand All @@ -41,7 +41,7 @@ type Config struct {
}

// NewServer creates a new GRPC server
func NewServer(config *Config, logger *zap.Logger, sectigoCfg *cfg.SectigoConfiguration, db *ent.Client) (*Server, error) {
func NewServer(config *Config, logger *zap.Logger, sectigoCfg *cfg.PKIConfiguration, db *ent.Client) (*Server, error) {
srv := &Server{
logger: logger,
sectigoCfg: sectigoCfg,
Expand Down
4 changes: 2 additions & 2 deletions backend/pki-service/pkg/grpc/smime.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
type smimeAPIServer struct {
pb.UnimplementedSmimeServiceServer
client *sectigo.Client
cfg *cfg.SectigoConfiguration
cfg *cfg.PKIConfiguration
logger *zap.Logger
}

func newSmimeAPIServer(client *sectigo.Client, cfg *cfg.SectigoConfiguration) *smimeAPIServer {
func newSmimeAPIServer(client *sectigo.Client, cfg *cfg.PKIConfiguration) *smimeAPIServer {
return &smimeAPIServer{client: client, cfg: cfg, logger: zap.L()}
}

Expand Down
10 changes: 6 additions & 4 deletions backend/pki-service/pkg/grpc/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ type sslAPIServer struct {
pb.UnimplementedSSLServiceServer
client *sectigo.Client
db *ent.Client
cfg *cfg.SectigoConfiguration
cfg *cfg.PKIConfiguration
logger *zap.Logger
legoClient *lego.Client

last *time.Time
duration *time.Duration
}

func newSslAPIServer(client *sectigo.Client, cfg *cfg.SectigoConfiguration, db *ent.Client) *sslAPIServer {
func newSslAPIServer(client *sectigo.Client, cfg *cfg.PKIConfiguration, db *ent.Client) *sslAPIServer {

legoClient := registerAcme(cfg)
instance := &sslAPIServer{client: client, legoClient: legoClient, cfg: cfg, logger: zap.L(), db: db}
_ = promauto.NewGaugeFunc(prometheus.GaugeOpts{
Expand All @@ -112,6 +113,7 @@ func newSslAPIServer(client *sectigo.Client, cfg *cfg.SectigoConfiguration, db *
}, func() float64 {
if instance.duration != nil {
return instance.duration.Seconds()
}
return 0
})

Expand All @@ -128,7 +130,7 @@ func newSslAPIServer(client *sectigo.Client, cfg *cfg.SectigoConfiguration, db *
return instance
}

func registerAcme(cfg *cfg.SectigoConfiguration) *lego.Client {
func registerAcme(cfg *cfg.PKIConfiguration) *lego.Client {
accountFile := filepath.Join(cfg.AcmeStorage, "reg.json")
keyFile := filepath.Join(cfg.AcmeStorage, "reg.key")

Expand Down Expand Up @@ -310,7 +312,7 @@ func (s *sslAPIServer) IssueCertificate(ctx context.Context, req *pb.IssueSslReq

resp, err := s.legoClient.Certificate.ObtainForCSR(legoCert.ObtainForCSRRequest{CSR: csr, Bundle: true})
if err != nil {
return s.handleError("Error while obtaining certificate", err, logger)
return s.handleError("Error while obtaining certificate", err, logger, hub)
}
hub.AddBreadcrumb(&sentry.Breadcrumb{Message: "Certificate collected", Category: "info", Level: sentry.LevelInfo}, nil)
stop := time.Now()
Expand Down

0 comments on commit 5241250

Please sign in to comment.