refactor: clean code
This commit is contained in:
@@ -75,7 +75,7 @@ func (u *acmeUser) getPrivateKeyPEM() string {
|
||||
return u.privkey
|
||||
}
|
||||
|
||||
type AcmeAccountRepository interface {
|
||||
type acmeAccountRepository interface {
|
||||
GetByCAAndEmail(ca, email string) (*domain.AcmeAccount, error)
|
||||
Save(ca, email, key string, resource *registration.Resource) error
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package applicant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -13,7 +14,6 @@ import (
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
"github.com/usual2970/certimate/internal/repository"
|
||||
)
|
||||
@@ -37,11 +37,11 @@ type ApplyCertResult struct {
|
||||
CSR string
|
||||
}
|
||||
|
||||
type applicant interface {
|
||||
type Applicant interface {
|
||||
Apply() (*ApplyCertResult, error)
|
||||
}
|
||||
|
||||
func NewWithApplyNode(node *domain.WorkflowNode) (applicant, error) {
|
||||
func NewWithApplyNode(node *domain.WorkflowNode) (Applicant, error) {
|
||||
if node.Type != domain.WorkflowNodeTypeApply {
|
||||
return nil, fmt.Errorf("node type is not apply")
|
||||
}
|
||||
@@ -74,14 +74,15 @@ func NewWithApplyNode(node *domain.WorkflowNode) (applicant, error) {
|
||||
}
|
||||
|
||||
func apply(challengeProvider challenge.Provider, applyConfig *applyConfig) (*ApplyCertResult, error) {
|
||||
record, _ := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='sslProvider'")
|
||||
settingsRepo := repository.NewSettingsRepository()
|
||||
settings, _ := settingsRepo.GetByName(context.Background(), "sslProvider")
|
||||
|
||||
sslProvider := &acmeSSLProviderConfig{
|
||||
Config: acmeSSLProviderConfigContent{},
|
||||
Provider: defaultSSLProvider,
|
||||
}
|
||||
if record != nil {
|
||||
if err := record.UnmarshalJSONField("content", sslProvider); err != nil {
|
||||
if settings != nil {
|
||||
if err := json.Unmarshal([]byte(settings.Content), sslProvider); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/notifier"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/maps"
|
||||
"github.com/usual2970/certimate/internal/repository"
|
||||
)
|
||||
|
||||
func SendToAllChannels(subject, message string) error {
|
||||
@@ -48,13 +49,14 @@ func SendToChannel(subject, message string, channel string, channelConfig map[st
|
||||
}
|
||||
|
||||
func getEnabledNotifiers() ([]notifier.Notifier, error) {
|
||||
settings, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='notifyChannels'")
|
||||
settingsRepo := repository.NewSettingsRepository()
|
||||
settings, err := settingsRepo.GetByName(context.Background(), "notifyChannels")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find notifyChannels error: %w", err)
|
||||
}
|
||||
|
||||
rs := make(map[string]map[string]any)
|
||||
if err := settings.UnmarshalJSONField("content", &rs); err != nil {
|
||||
if err := json.Unmarshal([]byte(settings.Content), &rs); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal notifyChannels error: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user