Skip to content

Commit

Permalink
feat: 同步前端修改
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 8, 2023
1 parent c4d304f commit 3f64d81
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/http/controllers/cert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (r *CertController) CertList(ctx http.Context) http.Response {

var certs []models.Cert
var total int64
err := facades.Orm().Query().Paginate(paginateRequest.Page, paginateRequest.Limit, &certs, &total)
err := facades.Orm().Query().With("Website").With("User").With("DNS").Paginate(paginateRequest.Page, paginateRequest.Limit, &certs, &total)
if err != nil {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
Expand Down Expand Up @@ -619,7 +619,7 @@ func (r *CertController) Obtain(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("签发证书失败")
return ErrorSystem(ctx)
return Error(ctx, http.StatusInternalServerError, err.Error())
}

return Success(ctx, nil)
Expand Down Expand Up @@ -649,7 +649,7 @@ func (r *CertController) Renew(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("续签证书失败")
return ErrorSystem(ctx)
return Error(ctx, http.StatusInternalServerError, err.Error())
}

return Success(ctx, nil)
Expand Down Expand Up @@ -679,7 +679,7 @@ func (r *CertController) ManualDNS(ctx http.Context) http.Response {
facades.Log().Request(ctx.Request()).Tags("面板", "证书管理").With(map[string]any{
"error": err.Error(),
}).Error("获取手动DNS记录失败")
return ErrorSystem(ctx)
return Error(ctx, http.StatusInternalServerError, err.Error())
}

return Success(ctx, resolves)
Expand Down
24 changes: 22 additions & 2 deletions app/http/requests/cert/cert_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package requests
import (
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/validation"
"github.com/spf13/cast"
)

type CertStore struct {
Type string `form:"type" json:"type"`
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
UserID uint `form:"user_id" json:"user_id" filter:"uint"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
}
Expand All @@ -23,7 +24,9 @@ func (r *CertStore) Rules(ctx http.Context) map[string]string {
"type": "required|in:P256,P384,2048,4096",
"domains": "required|array",
"auto_renew": "required|bool",
"user_id": "required|exists:cert_users,id",
"user_id": "required|uint|exists:cert_users,id",
"dns_id": "uint",
"website_id": "uint",
}
}

Expand All @@ -36,5 +39,22 @@ func (r *CertStore) Attributes(ctx http.Context) map[string]string {
}

func (r *CertStore) PrepareForValidation(ctx http.Context, data validation.Data) error {
// TODO 由于验证器 filter 标签的问题,暂时这里这样处理
dnsID, exist := data.Get("dns_id")
if exist {
err := data.Set("dns_id", cast.ToUint(dnsID))
if err != nil {
return err
}

}
websiteID, exist := data.Get("website_id")
if exist {
err := data.Set("website_id", cast.ToUint(websiteID))
if err != nil {
return err
}
}

return nil
}
24 changes: 22 additions & 2 deletions app/http/requests/cert/cert_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package requests
import (
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/validation"
"github.com/spf13/cast"
)

type CertUpdate struct {
ID uint `form:"id" json:"id"`
Type string `form:"type" json:"type"`
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
UserID uint `form:"user_id" json:"user_id" filter:"uint"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
}
Expand All @@ -25,7 +26,9 @@ func (r *CertUpdate) Rules(ctx http.Context) map[string]string {
"type": "required|in:P256,P384,2048,4096",
"domains": "required|array",
"auto_renew": "required|bool",
"user_id": "required|exists:cert_users,id",
"user_id": "required|uint|exists:cert_users,id",
"dns_id": "uint",
"website_id": "uint",
}
}

Expand All @@ -38,5 +41,22 @@ func (r *CertUpdate) Attributes(ctx http.Context) map[string]string {
}

func (r *CertUpdate) PrepareForValidation(ctx http.Context, data validation.Data) error {
// TODO 由于验证器 filter 标签的问题,暂时这里这样处理
dnsID, exist := data.Get("dns_id")
if exist {
err := data.Set("dns_id", cast.ToUint(dnsID))
if err != nil {
return err
}

}
websiteID, exist := data.Get("website_id")
if exist {
err := data.Set("website_id", cast.ToUint(websiteID))
if err != nil {
return err
}
}

return nil
}
2 changes: 1 addition & 1 deletion app/http/requests/setting/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type Update struct {
Name string `form:"name" json:"name"`
Port uint `form:"port" json:"port" filter:"int"`
Port uint `form:"port" json:"port" filter:"uint"`
BackupPath string `form:"backup_path" json:"backup_path"`
WebsitePath string `form:"website_path" json:"website_path"`
Entrance string `form:"entrance" json:"entrance"`
Expand Down
6 changes: 3 additions & 3 deletions app/models/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Cert struct {
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`

Website *Website `gorm:"foreignKey:WebsiteID" json:"-"`
User *CertUser `gorm:"foreignKey:UserID" json:"-"`
DNS *CertDNS `gorm:"foreignKey:DNSID" json:"-"`
Website *Website `gorm:"foreignKey:WebsiteID" json:"website"`
User *CertUser `gorm:"foreignKey:UserID" json:"user"`
DNS *CertDNS `gorm:"foreignKey:DNSID" json:"dns"`
}
2 changes: 1 addition & 1 deletion app/services/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func (s *CertImpl) ManualDNS(ID uint) (map[string]acme.Resolve, error) {
// Renew 续签证书
func (s *CertImpl) Renew(ID uint) (certificate.Resource, error) {
var cert models.Cert
err := facades.Orm().Query().With("User").With("DNS").Where("id = ?", ID).First(&cert)
err := facades.Orm().Query().With("Website").With("User").With("DNS").Where("id = ?", ID).First(&cert)
if err != nil {
return certificate.Resource{}, err
}
Expand Down
44 changes: 44 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,9 @@ const docTemplate = `{
"created_at": {
"type": "string"
},
"dns": {
"$ref": "#/definitions/models.CertDNS"
},
"dns_id": {
"description": "关联的 DNS ID",
"type": "integer"
Expand All @@ -1372,10 +1375,16 @@ const docTemplate = `{
"updated_at": {
"type": "string"
},
"user": {
"$ref": "#/definitions/models.CertUser"
},
"user_id": {
"description": "关联的 ACME 用户 ID",
"type": "integer"
},
"website": {
"$ref": "#/definitions/models.Website"
},
"website_id": {
"description": "关联的网站 ID",
"type": "integer"
Expand Down Expand Up @@ -1440,6 +1449,41 @@ const docTemplate = `{
}
}
},
"models.Website": {
"type": "object",
"properties": {
"cert": {
"$ref": "#/definitions/models.Cert"
},
"created_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"path": {
"type": "string"
},
"php": {
"type": "integer"
},
"remark": {
"type": "string"
},
"ssl": {
"type": "boolean"
},
"status": {
"type": "boolean"
},
"updated_at": {
"type": "string"
}
}
},
"requests.CertStore": {
"type": "object",
"properties": {
Expand Down
44 changes: 44 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,9 @@
"created_at": {
"type": "string"
},
"dns": {
"$ref": "#/definitions/models.CertDNS"
},
"dns_id": {
"description": "关联的 DNS ID",
"type": "integer"
Expand All @@ -1365,10 +1368,16 @@
"updated_at": {
"type": "string"
},
"user": {
"$ref": "#/definitions/models.CertUser"
},
"user_id": {
"description": "关联的 ACME 用户 ID",
"type": "integer"
},
"website": {
"$ref": "#/definitions/models.Website"
},
"website_id": {
"description": "关联的网站 ID",
"type": "integer"
Expand Down Expand Up @@ -1433,6 +1442,41 @@
}
}
},
"models.Website": {
"type": "object",
"properties": {
"cert": {
"$ref": "#/definitions/models.Cert"
},
"created_at": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"path": {
"type": "string"
},
"php": {
"type": "integer"
},
"remark": {
"type": "string"
},
"ssl": {
"type": "boolean"
},
"status": {
"type": "boolean"
},
"updated_at": {
"type": "string"
}
}
},
"requests.CertStore": {
"type": "object",
"properties": {
Expand Down
29 changes: 29 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ definitions:
type: string
created_at:
type: string
dns:
$ref: '#/definitions/models.CertDNS'
dns_id:
description: 关联的 DNS ID
type: integer
Expand All @@ -69,9 +71,13 @@ definitions:
type: string
updated_at:
type: string
user:
$ref: '#/definitions/models.CertUser'
user_id:
description: 关联的 ACME 用户 ID
type: integer
website:
$ref: '#/definitions/models.Website'
website_id:
description: 关联的网站 ID
type: integer
Expand Down Expand Up @@ -115,6 +121,29 @@ definitions:
updated_at:
type: string
type: object
models.Website:
properties:
cert:
$ref: '#/definitions/models.Cert'
created_at:
type: string
id:
type: integer
name:
type: string
path:
type: string
php:
type: integer
remark:
type: string
ssl:
type: boolean
status:
type: boolean
updated_at:
type: string
type: object
requests.CertStore:
properties:
auto_renew:
Expand Down
6 changes: 3 additions & 3 deletions pkg/acme/dns_manual.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package acme

type Resolve struct {
Key string
Value string
Err string
Key string `json:"key"`
Value string `json:"value"`
Err string `json:"err"`
}

type manualDnsProvider struct {
Expand Down

0 comments on commit 3f64d81

Please sign in to comment.