chore(deps): upgrade gomod dependencies

This commit is contained in:
Fu Diwei
2024-12-23 15:05:25 +08:00
parent cda54085b9
commit d7bff599b7
6 changed files with 339 additions and 379 deletions

View File

@@ -5,14 +5,15 @@ import (
"context"
"encoding/json"
"errors"
"net/http"
"io"
"strings"
"time"
"github.com/gojek/heimdall/v7/httpclient"
xerrors "github.com/pkg/errors"
"github.com/usual2970/certimate/internal/pkg/core/deployer"
"github.com/usual2970/certimate/internal/pkg/utils/x509"
xhttp "github.com/usual2970/certimate/internal/utils/http"
)
type WebhookDeployerConfig struct {
@@ -23,8 +24,9 @@ type WebhookDeployerConfig struct {
}
type WebhookDeployer struct {
config *WebhookDeployerConfig
logger deployer.Logger
config *WebhookDeployerConfig
logger deployer.Logger
httpClient *httpclient.Client
}
var _ deployer.Deployer = (*WebhookDeployer)(nil)
@@ -42,9 +44,12 @@ func NewWithLogger(config *WebhookDeployerConfig, logger deployer.Logger) (*Webh
return nil, errors.New("logger is nil")
}
client := httpclient.NewClient(httpclient.WithHTTPTimeout(30 * time.Second))
return &WebhookDeployer{
config: config,
logger: logger,
config: config,
logger: logger,
httpClient: client,
}, nil
}
@@ -61,25 +66,28 @@ func (d *WebhookDeployer) Deploy(ctx context.Context, certPem string, privkeyPem
return nil, xerrors.Wrap(err, "failed to parse x509")
}
data := &webhookData{
reqBody, _ := json.Marshal(&webhookData{
SubjectAltNames: strings.Join(certX509.DNSNames, ","),
Certificate: certPem,
PrivateKey: privkeyPem,
Variables: d.config.Variables,
}
body, _ := json.Marshal(data)
resp, err := xhttp.Req(d.config.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
"Content-Type": "application/json",
})
resp, err := d.httpClient.Post(d.config.Url, bytes.NewReader(reqBody), map[string][]string{"Content-Type": {"application/json"}})
if err != nil {
return nil, xerrors.Wrap(err, "failed to send webhook request")
}
d.logger.Logt("Webhook Response", string(resp))
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, xerrors.Wrap(err, "failed to read response body")
}
d.logger.Logt("Webhook Response", string(respBody))
return &deployer.DeployResult{
DeploymentData: map[string]any{
"responseText": string(resp),
"responseText": string(respBody),
},
}, nil
}