mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-16 17:39:51 +00:00
refactor: deprecate internal/deployer/deployer.getDeployVariables
This commit is contained in:
parent
0ceb44a7cd
commit
0d96ea9eef
@ -156,28 +156,6 @@ func toStr(tag string, data any) string {
|
|||||||
return tag + ":" + string(byts)
|
return tag + ":" + string(byts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeployVariables(conf domain.DeployConfig) map[string]string {
|
|
||||||
rs := make(map[string]string)
|
|
||||||
data, ok := conf.Config["variables"]
|
|
||||||
if !ok {
|
|
||||||
return rs
|
|
||||||
}
|
|
||||||
|
|
||||||
bts, _ := json.Marshal(data)
|
|
||||||
|
|
||||||
kvData := make([]domain.KV, 0)
|
|
||||||
|
|
||||||
if err := json.Unmarshal(bts, &kvData); err != nil {
|
|
||||||
return rs
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kv := range kvData {
|
|
||||||
rs[kv.Key] = kv.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
return rs
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertPEMToPFX(certificate string, privateKey string, password string) ([]byte, error) {
|
func convertPEMToPFX(certificate string, privateKey string, password string) ([]byte, error) {
|
||||||
cert, err := x509.ParseCertificateFromPEM(certificate)
|
cert, err := x509.ParseCertificateFromPEM(certificate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ func (d *WebhookDeployer) Deploy(ctx context.Context) error {
|
|||||||
Domain: d.option.Domain,
|
Domain: d.option.Domain,
|
||||||
Certificate: d.option.Certificate.Certificate,
|
Certificate: d.option.Certificate.Certificate,
|
||||||
PrivateKey: d.option.Certificate.PrivateKey,
|
PrivateKey: d.option.Certificate.PrivateKey,
|
||||||
Variables: getDeployVariables(d.option.DeployConfig),
|
Variables: d.option.DeployConfig.GetConfigAsVariables(),
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(data)
|
body, _ := json.Marshal(data)
|
||||||
resp, err := xhttp.Req(access.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
|
resp, err := xhttp.Req(access.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
type ApplyConfig struct {
|
type ApplyConfig struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
@ -117,6 +122,33 @@ func (dc *DeployConfig) GetConfigOrDefaultAsBool(key string, defaultValue bool)
|
|||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 以变量字典形式获取配置项。
|
||||||
|
//
|
||||||
|
// 出参:
|
||||||
|
// - 变量字典。
|
||||||
|
func (dc *DeployConfig) GetConfigAsVariables() map[string]string {
|
||||||
|
rs := make(map[string]string)
|
||||||
|
|
||||||
|
if dc.Config != nil {
|
||||||
|
value, ok := dc.Config["variables"]
|
||||||
|
if !ok {
|
||||||
|
return rs
|
||||||
|
}
|
||||||
|
|
||||||
|
kvs := make([]domain.KV, 0)
|
||||||
|
bts, _ := json.Marshal(value)
|
||||||
|
if err := json.Unmarshal(bts, &kvs); err != nil {
|
||||||
|
return rs
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kv := range kvs {
|
||||||
|
rs[kv.Key] = kv.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs
|
||||||
|
}
|
||||||
|
|
||||||
// GetDomain returns the domain from the deploy config
|
// GetDomain returns the domain from the deploy config
|
||||||
// if the domain is a wildcard domain, and wildcard is true, return the wildcard domain
|
// if the domain is a wildcard domain, and wildcard is true, return the wildcard domain
|
||||||
func (dc *DeployConfig) GetDomain(wildcard ...bool) string {
|
func (dc *DeployConfig) GetDomain(wildcard ...bool) string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user