mirror of
https://github.com/usual2970/certimate.git
synced 2025-07-19 09:29:52 +00:00
.github
.vscode
docker
internal
applicant
deployer
aliyun_alb.go
aliyun_cdn.go
aliyun_clb.go
aliyun_dcdn.go
aliyun_nlb.go
aliyun_oss.go
baiducloud_cdn.go
deployer.go
dogecloud_cdn.go
huaweicloud_cdn.go
huaweicloud_elb.go
k8s_secret.go
local.go
qiniu_cdn.go
ssh.go
ssh_test.go
tencent_cdn.go
tencent_clb.go
tencent_cos.go
tencent_ecdn.go
tencent_teo.go
webhook.go
domain
domains
notify
pkg
repository
rest
routes
utils
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
usage.gif
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package deployer
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
xerrors "github.com/pkg/errors"
|
|
|
|
"github.com/usual2970/certimate/internal/domain"
|
|
xhttp "github.com/usual2970/certimate/internal/utils/http"
|
|
)
|
|
|
|
type WebhookDeployer struct {
|
|
option *DeployerOption
|
|
infos []string
|
|
}
|
|
|
|
func NewWebhookDeployer(option *DeployerOption) (Deployer, error) {
|
|
return &WebhookDeployer{
|
|
option: option,
|
|
infos: make([]string, 0),
|
|
}, nil
|
|
}
|
|
|
|
func (d *WebhookDeployer) GetID() string {
|
|
return fmt.Sprintf("%s-%s", d.option.AccessRecord.GetString("name"), d.option.AccessRecord.Id)
|
|
}
|
|
|
|
func (d *WebhookDeployer) GetInfos() []string {
|
|
return d.infos
|
|
}
|
|
|
|
type webhookData struct {
|
|
Domain string `json:"domain"`
|
|
Certificate string `json:"certificate"`
|
|
PrivateKey string `json:"privateKey"`
|
|
Variables map[string]string `json:"variables"`
|
|
}
|
|
|
|
func (d *WebhookDeployer) Deploy(ctx context.Context) error {
|
|
access := &domain.WebhookAccess{}
|
|
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
|
|
return xerrors.Wrap(err, "failed to get access")
|
|
}
|
|
|
|
data := &webhookData{
|
|
Domain: d.option.Domain,
|
|
Certificate: d.option.Certificate.Certificate,
|
|
PrivateKey: d.option.Certificate.PrivateKey,
|
|
Variables: d.option.DeployConfig.GetConfigAsVariables(),
|
|
}
|
|
body, _ := json.Marshal(data)
|
|
resp, err := xhttp.Req(access.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
|
|
"Content-Type": "application/json",
|
|
})
|
|
if err != nil {
|
|
return xerrors.Wrap(err, "failed to send webhook request")
|
|
}
|
|
|
|
d.infos = append(d.infos, toStr("Webhook Response", string(resp)))
|
|
|
|
return nil
|
|
}
|