style: format

This commit is contained in:
Fu Diwei 2024-10-15 21:14:54 +08:00
parent cf3de10eff
commit 26be47d072
29 changed files with 71 additions and 98 deletions

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"github.com/go-acme/lego/v4/providers/dns/alidns" "github.com/go-acme/lego/v4/providers/dns/alidns"
"certimate/internal/domain"
) )
type aliyun struct { type aliyun struct {
@ -20,7 +21,6 @@ func NewAliyun(option *ApplyOption) Applicant {
} }
func (a *aliyun) Apply() (*Certificate, error) { func (a *aliyun) Apply() (*Certificate, error) {
access := &domain.AliyunAccess{} access := &domain.AliyunAccess{}
json.Unmarshal([]byte(a.option.Access), access) json.Unmarshal([]byte(a.option.Access), access)

View File

@ -1,8 +1,6 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"certimate/internal/utils/app"
"crypto" "crypto"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/elliptic" "crypto/elliptic"
@ -18,6 +16,9 @@ import (
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/domain"
"certimate/internal/utils/app"
) )
const ( const (
@ -66,19 +67,21 @@ type ApplyOption struct {
Timeout int64 `json:"timeout"` Timeout int64 `json:"timeout"`
} }
type MyUser struct { type ApplyUser struct {
Email string Email string
Registration *registration.Resource Registration *registration.Resource
key crypto.PrivateKey key crypto.PrivateKey
} }
func (u *MyUser) GetEmail() string { func (u *ApplyUser) GetEmail() string {
return u.Email return u.Email
} }
func (u MyUser) GetRegistration() *registration.Resource {
func (u ApplyUser) GetRegistration() *registration.Resource {
return u.Registration return u.Registration
} }
func (u *MyUser) GetPrivateKey() crypto.PrivateKey {
func (u *ApplyUser) GetPrivateKey() crypto.PrivateKey {
return u.key return u.key
} }
@ -87,7 +90,6 @@ type Applicant interface {
} }
func Get(record *models.Record) (Applicant, error) { func Get(record *models.Record) (Applicant, error) {
if record.GetString("applyConfig") == "" { if record.GetString("applyConfig") == "" {
return nil, errors.New("apply config is empty") return nil, errors.New("apply config is empty")
} }
@ -97,7 +99,6 @@ func Get(record *models.Record) (Applicant, error) {
record.UnmarshalJSONField("applyConfig", applyConfig) record.UnmarshalJSONField("applyConfig", applyConfig)
access, err := app.GetApp().Dao().FindRecordById("access", applyConfig.Access) access, err := app.GetApp().Dao().FindRecordById("access", applyConfig.Access)
if err != nil { if err != nil {
return nil, fmt.Errorf("access record not found: %w", err) return nil, fmt.Errorf("access record not found: %w", err)
} }
@ -129,7 +130,6 @@ func Get(record *models.Record) (Applicant, error) {
default: default:
return nil, errors.New("unknown config type") return nil, errors.New("unknown config type")
} }
} }
type SSLProviderConfig struct { type SSLProviderConfig struct {
@ -162,7 +162,7 @@ func apply(option *ApplyOption, provider challenge.Provider) (*Certificate, erro
return nil, err return nil, err
} }
myUser := MyUser{ myUser := ApplyUser{
Email: option.Email, Email: option.Email,
key: privateKey, key: privateKey,
} }
@ -213,7 +213,6 @@ func apply(option *ApplyOption, provider challenge.Provider) (*Certificate, erro
IssuerCertificate: string(certificates.IssuerCertificate), IssuerCertificate: string(certificates.IssuerCertificate),
Csr: string(certificates.CSR), Csr: string(certificates.CSR),
}, nil }, nil
} }
func getReg(client *lego.Client, sslProvider *SSLProviderConfig) (*registration.Resource, error) { func getReg(client *lego.Client, sslProvider *SSLProviderConfig) (*registration.Resource, error) {

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
cf "github.com/go-acme/lego/v4/providers/dns/cloudflare" cf "github.com/go-acme/lego/v4/providers/dns/cloudflare"
"certimate/internal/domain"
) )
type cloudflare struct { type cloudflare struct {

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
godaddyProvider "github.com/go-acme/lego/v4/providers/dns/godaddy" godaddyProvider "github.com/go-acme/lego/v4/providers/dns/godaddy"
"certimate/internal/domain"
) )
type godaddy struct { type godaddy struct {
@ -20,7 +21,6 @@ func NewGodaddy(option *ApplyOption) Applicant {
} }
func (a *godaddy) Apply() (*Certificate, error) { func (a *godaddy) Apply() (*Certificate, error) {
access := &domain.GodaddyAccess{} access := &domain.GodaddyAccess{}
json.Unmarshal([]byte(a.option.Access), access) json.Unmarshal([]byte(a.option.Access), access)

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
huaweicloudProvider "github.com/go-acme/lego/v4/providers/dns/huaweicloud" huaweicloudProvider "github.com/go-acme/lego/v4/providers/dns/huaweicloud"
"certimate/internal/domain"
) )
type huaweicloud struct { type huaweicloud struct {
@ -20,7 +21,6 @@ func NewHuaweiCloud(option *ApplyOption) Applicant {
} }
func (t *huaweicloud) Apply() (*Certificate, error) { func (t *huaweicloud) Apply() (*Certificate, error) {
access := &domain.HuaweiCloudAccess{} access := &domain.HuaweiCloudAccess{}
json.Unmarshal([]byte(t.option.Access), access) json.Unmarshal([]byte(t.option.Access), access)
@ -28,7 +28,7 @@ func (t *huaweicloud) Apply() (*Certificate, error) {
os.Setenv("HUAWEICLOUD_ACCESS_KEY_ID", access.AccessKeyId) os.Setenv("HUAWEICLOUD_ACCESS_KEY_ID", access.AccessKeyId)
os.Setenv("HUAWEICLOUD_SECRET_ACCESS_KEY", access.SecretAccessKey) os.Setenv("HUAWEICLOUD_SECRET_ACCESS_KEY", access.SecretAccessKey)
os.Setenv("HUAWEICLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout)) os.Setenv("HUAWEICLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout))
dnsProvider, err := huaweicloudProvider.NewDNSProvider() dnsProvider, err := huaweicloudProvider.NewDNSProvider()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
namesiloProvider "github.com/go-acme/lego/v4/providers/dns/namesilo" namesiloProvider "github.com/go-acme/lego/v4/providers/dns/namesilo"
"certimate/internal/domain"
) )
type namesilo struct { type namesilo struct {
@ -20,7 +21,6 @@ func NewNamesilo(option *ApplyOption) Applicant {
} }
func (a *namesilo) Apply() (*Certificate, error) { func (a *namesilo) Apply() (*Certificate, error) {
access := &domain.NameSiloAccess{} access := &domain.NameSiloAccess{}
json.Unmarshal([]byte(a.option.Access), access) json.Unmarshal([]byte(a.option.Access), access)

View File

@ -1,12 +1,13 @@
package applicant package applicant
import ( import (
"certimate/internal/domain"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"github.com/go-acme/lego/v4/providers/dns/tencentcloud" "github.com/go-acme/lego/v4/providers/dns/tencentcloud"
"certimate/internal/domain"
) )
type tencent struct { type tencent struct {
@ -20,14 +21,13 @@ func NewTencent(option *ApplyOption) Applicant {
} }
func (t *tencent) Apply() (*Certificate, error) { func (t *tencent) Apply() (*Certificate, error) {
access := &domain.TencentAccess{} access := &domain.TencentAccess{}
json.Unmarshal([]byte(t.option.Access), access) json.Unmarshal([]byte(t.option.Access), access)
os.Setenv("TENCENTCLOUD_SECRET_ID", access.SecretId) os.Setenv("TENCENTCLOUD_SECRET_ID", access.SecretId)
os.Setenv("TENCENTCLOUD_SECRET_KEY", access.SecretKey) os.Setenv("TENCENTCLOUD_SECRET_KEY", access.SecretKey)
os.Setenv("TENCENTCLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout)) os.Setenv("TENCENTCLOUD_PROPAGATION_TIMEOUT", fmt.Sprintf("%d", t.option.Timeout))
dnsProvider, err := tencentcloud.NewDNSProvider() dnsProvider, err := tencentcloud.NewDNSProvider()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,12 +1,13 @@
package deployer package deployer
import ( import (
"certimate/internal/domain"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
"certimate/internal/domain"
) )
type aliyun struct { type aliyun struct {
@ -28,7 +29,6 @@ func NewAliyun(option *DeployerOption) (Deployer, error) {
} }
a.client = client a.client = client
return a, nil return a, nil
} }
func (a *aliyun) GetID() string { func (a *aliyun) GetID() string {
@ -48,13 +48,11 @@ func (a *aliyun) Deploy(ctx context.Context) error {
Force: true, Force: true,
}, },
}) })
if err != nil { if err != nil {
return fmt.Errorf("deploy aliyun oss error: %w", err) return fmt.Errorf("deploy aliyun oss error: %w", err)
} }
return nil return nil
} }
func (a *aliyun) createClient(accessKeyId, accessKeySecret string) (*oss.Client, error) { func (a *aliyun) createClient(accessKeyId, accessKeySecret string) (*oss.Client, error) {

View File

@ -1,8 +1,6 @@
package deployer package deployer
import ( import (
"certimate/internal/domain"
"certimate/internal/utils/rand"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -11,6 +9,9 @@ import (
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
util "github.com/alibabacloud-go/tea-utils/v2/service" util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea" "github.com/alibabacloud-go/tea/tea"
"certimate/internal/domain"
"certimate/internal/utils/rand"
) )
type AliyunCdn struct { type AliyunCdn struct {
@ -46,7 +47,6 @@ func (a *AliyunCdn) GetInfo() []string {
} }
func (a *AliyunCdn) Deploy(ctx context.Context) error { func (a *AliyunCdn) Deploy(ctx context.Context) error {
certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6)) certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6))
setCdnDomainSSLCertificateRequest := &cdn20180510.SetCdnDomainSSLCertificateRequest{ setCdnDomainSSLCertificateRequest := &cdn20180510.SetCdnDomainSSLCertificateRequest{
DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")), DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")),

View File

@ -6,8 +6,6 @@
package deployer package deployer
import ( import (
"certimate/internal/domain"
"certimate/internal/utils/rand"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -16,6 +14,9 @@ import (
dcdn20180115 "github.com/alibabacloud-go/dcdn-20180115/v3/client" dcdn20180115 "github.com/alibabacloud-go/dcdn-20180115/v3/client"
util "github.com/alibabacloud-go/tea-utils/v2/service" util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea" "github.com/alibabacloud-go/tea/tea"
"certimate/internal/domain"
"certimate/internal/utils/rand"
) )
type AliyunEsa struct { type AliyunEsa struct {
@ -51,7 +52,6 @@ func (a *AliyunEsa) GetInfo() []string {
} }
func (a *AliyunEsa) Deploy(ctx context.Context) error { func (a *AliyunEsa) Deploy(ctx context.Context) error {
certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6)) certName := fmt.Sprintf("%s-%s-%s", a.option.Domain, a.option.DomainId, rand.RandStr(6))
setDcdnDomainSSLCertificateRequest := &dcdn20180115.SetDcdnDomainSSLCertificateRequest{ setDcdnDomainSSLCertificateRequest := &dcdn20180115.SetDcdnDomainSSLCertificateRequest{
DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")), DomainName: tea.String(getDeployString(a.option.DeployConfig, "domain")),

View File

@ -1,9 +1,6 @@
package deployer package deployer
import ( import (
"certimate/internal/applicant"
"certimate/internal/domain"
"certimate/internal/utils/app"
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
@ -11,6 +8,10 @@ import (
"strings" "strings"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/applicant"
"certimate/internal/domain"
"certimate/internal/utils/app"
) )
const ( const (
@ -61,7 +62,6 @@ func Gets(record *models.Record, cert *applicant.Certificate) ([]Deployer, error
for _, deployConfig := range deployConfigs { for _, deployConfig := range deployConfigs {
deployer, err := getWithDeployConfig(record, cert, deployConfig) deployer, err := getWithDeployConfig(record, cert, deployConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -70,13 +70,10 @@ func Gets(record *models.Record, cert *applicant.Certificate) ([]Deployer, error
} }
return rs, nil return rs, nil
} }
func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, deployConfig domain.DeployConfig) (Deployer, error) { func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, deployConfig domain.DeployConfig) (Deployer, error) {
access, err := app.GetApp().Dao().FindRecordById("access", deployConfig.Access) access, err := app.GetApp().Dao().FindRecordById("access", deployConfig.Access)
if err != nil { if err != nil {
return nil, fmt.Errorf("access record not found: %w", err) return nil, fmt.Errorf("access record not found: %w", err)
} }
@ -169,5 +166,4 @@ func getDeployVariables(conf domain.DeployConfig) map[string]string {
} }
return rs return rs
} }

View File

@ -10,8 +10,7 @@ import (
"runtime" "runtime"
) )
type localAccess struct { type localAccess struct{}
}
type local struct { type local struct {
option *DeployerOption option *DeployerOption

View File

@ -2,8 +2,6 @@ package deployer
import ( import (
"bytes" "bytes"
"certimate/internal/domain"
xhttp "certimate/internal/utils/http"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -11,6 +9,9 @@ import (
"net/http" "net/http"
"github.com/qiniu/go-sdk/v7/auth" "github.com/qiniu/go-sdk/v7/auth"
"certimate/internal/domain"
xhttp "certimate/internal/utils/http"
) )
const qiniuGateway = "http://api.qiniu.com" const qiniuGateway = "http://api.qiniu.com"
@ -42,7 +43,6 @@ func (q *qiuniu) GetInfo() []string {
} }
func (q *qiuniu) Deploy(ctx context.Context) error { func (q *qiuniu) Deploy(ctx context.Context) error {
// 上传证书 // 上传证书
certId, err := q.uploadCert() certId, err := q.uploadCert()
if err != nil { if err != nil {

View File

@ -1,10 +1,11 @@
package deployer package deployer
import ( import (
"certimate/internal/applicant"
"testing" "testing"
"github.com/qiniu/go-sdk/v7/auth" "github.com/qiniu/go-sdk/v7/auth"
"certimate/internal/applicant"
) )
func Test_qiuniu_uploadCert(t *testing.T) { func Test_qiuniu_uploadCert(t *testing.T) {

View File

@ -103,7 +103,6 @@ func (s *ssh) sshExecCommand(client *sshPkg.Client, command string) (error, stri
} }
func (s *ssh) upload(client *sshPkg.Client, content, path string) error { func (s *ssh) upload(client *sshPkg.Client, content, path string) error {
sftpCli, err := sftp.NewClient(client) sftpCli, err := sftp.NewClient(client)
if err != nil { if err != nil {
return fmt.Errorf("failed to create sftp client: %w", err) return fmt.Errorf("failed to create sftp client: %w", err)
@ -129,7 +128,6 @@ func (s *ssh) upload(client *sshPkg.Client, content, path string) error {
} }
func (s *ssh) getClient(access *sshAccess) (*sshPkg.Client, error) { func (s *ssh) getClient(access *sshAccess) (*sshPkg.Client, error) {
var authMethod sshPkg.AuthMethod var authMethod sshPkg.AuthMethod
if access.Key != "" { if access.Key != "" {

View File

@ -8,5 +8,5 @@ import (
func TestPath(t *testing.T) { func TestPath(t *testing.T) {
dir := path.Dir("./a/b/c") dir := path.Dir("./a/b/c")
os.MkdirAll(dir, 0755) os.MkdirAll(dir, 0o755)
} }

View File

@ -1,18 +1,19 @@
package deployer package deployer
import ( import (
"certimate/internal/domain"
"certimate/internal/utils/rand"
"context" "context"
"encoding/json"
"encoding/base64" "encoding/base64"
"encoding/json"
"fmt" "fmt"
"strings" "strings"
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205" ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
"certimate/internal/domain"
"certimate/internal/utils/rand"
) )
type tencentCdn struct { type tencentCdn struct {
@ -22,7 +23,6 @@ type tencentCdn struct {
} }
func NewTencentCdn(option *DeployerOption) (Deployer, error) { func NewTencentCdn(option *DeployerOption) (Deployer, error) {
access := &domain.TencentAccess{} access := &domain.TencentAccess{}
if err := json.Unmarshal([]byte(option.Access), access); err != nil { if err := json.Unmarshal([]byte(option.Access), access); err != nil {
return nil, fmt.Errorf("failed to unmarshal tencent access: %w", err) return nil, fmt.Errorf("failed to unmarshal tencent access: %w", err)
@ -49,7 +49,6 @@ func (t *tencentCdn) GetInfo() []string {
} }
func (t *tencentCdn) Deploy(ctx context.Context) error { func (t *tencentCdn) Deploy(ctx context.Context) error {
// 上传证书 // 上传证书
certId, err := t.uploadCert() certId, err := t.uploadCert()
if err != nil { if err != nil {
@ -65,7 +64,6 @@ func (t *tencentCdn) Deploy(ctx context.Context) error {
} }
func (t *tencentCdn) uploadCert() (string, error) { func (t *tencentCdn) uploadCert() (string, error) {
cpf := profile.NewClientProfile() cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "ssl.tencentcloudapi.com" cpf.HttpProfile.Endpoint = "ssl.tencentcloudapi.com"
@ -92,8 +90,6 @@ func (t *tencentCdn) deploy(certId string) error {
// 实例化要请求产品的client对象,clientProfile是可选的 // 实例化要请求产品的client对象,clientProfile是可选的
client, _ := ssl.NewClient(t.credential, "", cpf) client, _ := ssl.NewClient(t.credential, "", cpf)
// 实例化一个请求对象,每个接口都会对应一个request对象 // 实例化一个请求对象,每个接口都会对应一个request对象
request := ssl.NewDeployCertificateInstanceRequest() request := ssl.NewDeployCertificateInstanceRequest()
@ -102,7 +98,7 @@ func (t *tencentCdn) deploy(certId string) error {
request.Status = common.Int64Ptr(1) request.Status = common.Int64Ptr(1)
// 如果是泛域名就从cdn列表下获取SSL证书中的可用域名 // 如果是泛域名就从cdn列表下获取SSL证书中的可用域名
if(strings.Contains(t.option.Domain, "*")){ if strings.Contains(t.option.Domain, "*") {
list, errGetList := t.getDomainList() list, errGetList := t.getDomainList()
if errGetList != nil { if errGetList != nil {
return fmt.Errorf("failed to get certificate domain list: %w", errGetList) return fmt.Errorf("failed to get certificate domain list: %w", errGetList)
@ -111,13 +107,12 @@ func (t *tencentCdn) deploy(certId string) error {
return fmt.Errorf("failed to get certificate domain list: empty list.") return fmt.Errorf("failed to get certificate domain list: empty list.")
} }
request.InstanceIdList = common.StringPtrs(list) request.InstanceIdList = common.StringPtrs(list)
}else{ // 否则直接使用传入的域名 } else { // 否则直接使用传入的域名
request.InstanceIdList = common.StringPtrs([]string{t.option.Domain}) request.InstanceIdList = common.StringPtrs([]string{t.option.Domain})
} }
// 返回的resp是一个DeployCertificateInstanceResponse的实例与请求对象对应 // 返回的resp是一个DeployCertificateInstanceResponse的实例与请求对象对应
resp, err := client.DeployCertificateInstance(request) resp, err := client.DeployCertificateInstance(request)
if err != nil { if err != nil {
return fmt.Errorf("failed to deploy certificate: %w", err) return fmt.Errorf("failed to deploy certificate: %w", err)
} }
@ -134,7 +129,6 @@ func (t *tencentCdn) getDomainList() ([]string, error) {
cert := base64.StdEncoding.EncodeToString([]byte(t.option.Certificate.Certificate)) cert := base64.StdEncoding.EncodeToString([]byte(t.option.Certificate.Certificate))
request.Cert = &cert request.Cert = &cert
response, err := client.DescribeCertDomains(request) response, err := client.DescribeCertDomains(request)
if err != nil { if err != nil {

View File

@ -2,11 +2,12 @@ package deployer
import ( import (
"bytes" "bytes"
xhttp "certimate/internal/utils/http"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
xhttp "certimate/internal/utils/http"
) )
type webhookAccess struct { type webhookAccess struct {
@ -26,7 +27,6 @@ type webhook struct {
} }
func NewWebhook(option *DeployerOption) (Deployer, error) { func NewWebhook(option *DeployerOption) (Deployer, error) {
return &webhook{ return &webhook{
option: option, option: option,
infos: make([]string, 0), infos: make([]string, 0),

View File

@ -33,4 +33,3 @@ type GodaddyAccess struct {
ApiKey string `json:"apiKey"` ApiKey string `json:"apiKey"`
ApiSecret string `json:"apiSecret"` ApiSecret string `json:"apiSecret"`
} }

View File

@ -1,14 +1,15 @@
package domains package domains
import ( import (
"certimate/internal/applicant"
"certimate/internal/deployer"
"certimate/internal/utils/app"
"context" "context"
"fmt" "fmt"
"time" "time"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/applicant"
"certimate/internal/deployer"
"certimate/internal/utils/app"
) )
type Phase string type Phase string

View File

@ -1,11 +1,12 @@
package domains package domains
import ( import (
"certimate/internal/utils/app"
"context" "context"
"fmt" "fmt"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/utils/app"
) )
func create(ctx context.Context, record *models.Record) error { func create(ctx context.Context, record *models.Record) error {
@ -19,7 +20,6 @@ func create(ctx context.Context, record *models.Record) error {
app.GetApp().Logger().Error("deploy failed", "err", err) app.GetApp().Logger().Error("deploy failed", "err", err)
} }
}() }()
} }
scheduler := app.GetScheduler() scheduler := app.GetScheduler()
@ -27,7 +27,6 @@ func create(ctx context.Context, record *models.Record) error {
err := scheduler.Add(record.Id, record.GetString("crontab"), func() { err := scheduler.Add(record.Id, record.GetString("crontab"), func() {
deploy(ctx, record) deploy(ctx, record)
}) })
if err != nil { if err != nil {
app.GetApp().Logger().Error("add cron job failed", "err", err) app.GetApp().Logger().Error("add cron job failed", "err", err)
return fmt.Errorf("add cron job failed: %w", err) return fmt.Errorf("add cron job failed: %w", err)
@ -46,7 +45,6 @@ func update(ctx context.Context, record *models.Record) error {
} }
if record.GetBool("rightnow") { if record.GetBool("rightnow") {
go func() { go func() {
if err := deploy(ctx, record); err != nil { if err := deploy(ctx, record); err != nil {
app.GetApp().Logger().Error("deploy failed", "err", err) app.GetApp().Logger().Error("deploy failed", "err", err)
@ -57,7 +55,6 @@ func update(ctx context.Context, record *models.Record) error {
err := scheduler.Add(record.Id, record.GetString("crontab"), func() { err := scheduler.Add(record.Id, record.GetString("crontab"), func() {
deploy(ctx, record) deploy(ctx, record)
}) })
if err != nil { if err != nil {
app.GetApp().Logger().Error("update cron job failed", "err", err) app.GetApp().Logger().Error("update cron job failed", "err", err)
return fmt.Errorf("update cron job failed: %w", err) return fmt.Errorf("update cron job failed: %w", err)

View File

@ -1,9 +1,9 @@
package domains package domains
import ( import (
"certimate/internal/utils/app"
"github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/core"
"certimate/internal/utils/app"
) )
const tableName = "domains" const tableName = "domains"

View File

@ -1,12 +1,13 @@
package domains package domains
import ( import (
"certimate/internal/applicant"
"certimate/internal/utils/app"
"certimate/internal/utils/xtime"
"time" "time"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/applicant"
"certimate/internal/utils/app"
"certimate/internal/utils/xtime"
) )
type historyItem struct { type historyItem struct {
@ -62,7 +63,6 @@ func (a *history) record(phase Phase, msg string, info *RecordInfo, pass ...bool
Info: info.Info, Info: info.Info,
Time: xtime.BeijingTimeStr(), Time: xtime.BeijingTimeStr(),
}) })
} }
func (a *history) setCert(cert *applicant.Certificate) { func (a *history) setCert(cert *applicant.Certificate) {

View File

@ -1,9 +1,10 @@
package domains package domains
import ( import (
"context"
"certimate/internal/notify" "certimate/internal/notify"
"certimate/internal/utils/app" "certimate/internal/utils/app"
"context"
) )
func InitSchedule() { func InitSchedule() {
@ -34,5 +35,4 @@ func InitSchedule() {
// 启动定时任务 // 启动定时任务
app.GetScheduler().Start() app.GetScheduler().Start()
app.GetApp().Logger().Info("定时任务启动成功", "total", app.GetScheduler().Total()) app.GetApp().Logger().Info("定时任务启动成功", "total", app.GetScheduler().Total())
} }

View File

@ -1,14 +1,15 @@
package notify package notify
import ( import (
"certimate/internal/utils/app"
"certimate/internal/utils/xtime"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/pocketbase/dbx" "github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"certimate/internal/utils/app"
"certimate/internal/utils/xtime"
) )
type msg struct { type msg struct {
@ -41,7 +42,6 @@ func PushExpireMsg() {
if err := Send(msg.subject, msg.message); err != nil { if err := Send(msg.subject, msg.message); err != nil {
app.GetApp().Logger().Error("send expire msg", "error", err) app.GetApp().Logger().Error("send expire msg", "error", err)
} }
} }
type notifyTemplates struct { type notifyTemplates struct {
@ -94,5 +94,4 @@ func buildMsg(records []*models.Record) *msg {
subject: title, subject: title,
message: content, message: content,
} }
} }

View File

@ -1,18 +1,16 @@
package notify package notify
import ( import (
"certimate/internal/utils/app"
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
notifyPackage "github.com/nikoksr/notify" notifyPackage "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/dingding" "github.com/nikoksr/notify/service/dingding"
"github.com/nikoksr/notify/service/http"
"github.com/nikoksr/notify/service/telegram" "github.com/nikoksr/notify/service/telegram"
"github.com/nikoksr/notify/service/http" "certimate/internal/utils/app"
) )
const ( const (
@ -40,7 +38,6 @@ func Send(title, content string) error {
} }
func getNotifiers() ([]notifyPackage.Notifier, error) { func getNotifiers() ([]notifyPackage.Notifier, error) {
resp, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='notifyChannels'") resp, err := app.GetApp().Dao().FindFirstRecordByFilter("settings", "name='notifyChannels'")
if err != nil { if err != nil {
return nil, fmt.Errorf("find notifyChannels error: %w", err) return nil, fmt.Errorf("find notifyChannels error: %w", err)
@ -77,7 +74,6 @@ func getNotifiers() ([]notifyPackage.Notifier, error) {
} }
return notifiers, nil return notifiers, nil
} }
func getWebhookNotifier(conf map[string]any) notifyPackage.Notifier { func getWebhookNotifier(conf map[string]any) notifyPackage.Notifier {
@ -110,7 +106,6 @@ func getDingTalkNotifier(conf map[string]any) notifyPackage.Notifier {
Token: getString(conf, "accessToken"), Token: getString(conf, "accessToken"),
Secret: getString(conf, "secret"), Secret: getString(conf, "secret"),
}) })
} }
func getString(conf map[string]any, key string) string { func getString(conf map[string]any, key string) string {

View File

@ -35,11 +35,9 @@ func Req2GetReader(url string, method string, body io.Reader, head map[string]st
req := BuildReq(url, method, body, head) req := BuildReq(url, method, body, head)
return ToRequest(req, opts...) return ToRequest(req, opts...)
} }
func BuildReq(url string, method string, body io.Reader, head map[string]string) *http.Request { func BuildReq(url string, method string, body io.Reader, head map[string]string) *http.Request {
// Create an http.Request instance // Create an http.Request instance
req, _ := http.NewRequest(method, url, body) req, _ := http.NewRequest(method, url, body)
for k, v := range head { for k, v := range head {

View File

@ -4,7 +4,6 @@ import "strings"
// Parse2Map 将变量赋值字符串解析为map // Parse2Map 将变量赋值字符串解析为map
func Parse2Map(str string) map[string]string { func Parse2Map(str string) map[string]string {
m := make(map[string]string) m := make(map[string]string)
lines := strings.Split(str, ";") lines := strings.Split(str, ";")

View File

@ -15,7 +15,6 @@ func BeijingTimeStr() string {
} }
func GetTimeAfter(d time.Duration) string { func GetTimeAfter(d time.Duration) string {
t := time.Now().UTC() t := time.Now().UTC()
return t.Add(d).Format("2006-01-02 15:04:05") return t.Add(d).Format("2006-01-02 15:04:05")