feat: sync certificates to remote server #293, #363, #411

This commit is contained in:
Jacky 2024-06-18 17:39:05 +08:00
parent 11e460765a
commit b3486a42a5
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
41 changed files with 2429 additions and 1649 deletions

View file

@ -10,6 +10,7 @@ import (
)
const (
AutoCertSync = 2
AutoCertEnabled = 1
AutoCertDisabled = -1
CertChallengeMethodHTTP01 = "http01"
@ -42,6 +43,7 @@ type Cert struct {
KeyType certcrypto.KeyType `json:"key_type"`
Log string `json:"log"`
Resource *CertificateResource `json:"-" gorm:"serializer:json"`
SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"`
}
func FirstCert(confName string) (c Cert, err error) {
@ -94,10 +96,6 @@ func (c *Cert) Updates(n *Cert) error {
return db.Model(&Cert{}).Where("id", c.ID).Updates(n).Error
}
func (c *Cert) ClearLog() {
db.Model(&Cert{}).Where("id", c.ID).Update("log", "")
}
func (c *Cert) Remove() error {
if c.Filename == "" {
return db.Delete(c).Error

View file

@ -15,6 +15,25 @@ type Environment struct {
SyncApiRegex string `json:"sync_api_regex"`
}
func (e *Environment) GetUrl(uri string) (decodedUri string, err error) {
baseUrl, err := url.Parse(e.URL)
if err != nil {
return
}
u, err := url.JoinPath(baseUrl.String(), uri)
if err != nil {
return
}
decodedUri, err = url.QueryUnescape(u)
if err != nil {
return
}
return
}
func (e *Environment) GetWebSocketURL(uri string) (decodedUri string, err error) {
baseUrl, err := url.Parse(e.URL)
if err != nil {