Skip to content

Commit

Permalink
feat(证书管理): DNS 添加备注名称
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 5, 2023
1 parent 4c4a605 commit 485b7b9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/http/requests/cert/cert_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type CertAdd struct {
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
}

func (r *CertAdd) Authorize(ctx http.Context) error {
Expand Down
3 changes: 3 additions & 0 deletions app/http/requests/cert/dns_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type DNSAdd struct {
Type string `form:"type" json:"type"`
Name string `form:"name" json:"name"`
Data acme.DNSParam `form:"data" json:"data"`
}

Expand All @@ -18,6 +19,7 @@ func (r *DNSAdd) Authorize(ctx http.Context) error {
func (r *DNSAdd) Rules(ctx http.Context) map[string]string {
return map[string]string{
"type": "required|in:dnspod,aliyun,cloudflare",
"name": "required",
"data": "required",
"data.id": "required_if:type,dnspod",
"data.token": "required_if:type,dnspod",
Expand All @@ -32,6 +34,7 @@ func (r *DNSAdd) Messages(ctx http.Context) map[string]string {
return map[string]string{
"type.required": "类型不能为空",
"type.in": "类型必须为 dnspod, aliyun, cloudflare 中的一个",
"name.required": "备注名称不能为空",
"data.required": "数据不能为空",
"data.id.required_if": "ID 不能为空",
"data.token.required_if": "Token 不能为空",
Expand Down
1 change: 1 addition & 0 deletions app/models/cert_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type CertDNS struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"` // 备注名称
Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, aliyun, cloudflare)
Data acme.DNSParam `gorm:"type:json;serializer:json" json:"dns_param"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
Expand Down
4 changes: 4 additions & 0 deletions app/services/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (s *CertImpl) UserDelete(ID uint) error {
func (s *CertImpl) DNSAdd(request requests.DNSAdd) error {
var dns models.CertDNS
dns.Type = request.Type
dns.Name = request.Name
dns.Data = request.Data

return facades.Orm().Query().Create(&dns)
Expand Down Expand Up @@ -133,6 +134,9 @@ func (s *CertImpl) CertAdd(request requests.CertAdd) error {
if request.DNSID != nil {
cert.DNSID = request.DNSID
}
if request.WebsiteID != nil {
cert.WebsiteID = request.WebsiteID
}

return facades.Orm().Query().Create(&cert)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE TABLE cert_dns
(
id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
name varchar(255) NOT NULL,
type varchar(255) NOT NULL,
data text NOT NULL,
created_at datetime NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-acme/lego/v4 v4.14.2
github.com/gookit/color v1.5.4
github.com/goravel/fiber v1.1.10
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1
github.com/goravel/framework v1.13.1-0.20231105170024-1042844af36a
github.com/iancoleman/strcase v0.3.0
github.com/imroc/req/v3 v3.42.1
github.com/mojocn/base64Captcha v1.3.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c h1:obhFK91
github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c/go.mod h1:YSWsLXlG16u5CWFaXNZHhEQD10+NwF3xfgDV816OwLE=
github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHPuDbOaP78O1M=
github.com/goravel/file-rotatelogs/v2 v2.4.1/go.mod h1:euk9qr52WrzM8ICs1hecFcR4CZ/ZZOPdacHfvHgbOf0=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1 h1:Bi86UTQtrQIo74ler6NbbXTy0dOGGZaNwtRcBOuZom8=
github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/goravel/framework v1.13.1-0.20231105170024-1042844af36a h1:2+LVTqbsHm1ng3MVWwIKVTOZefRMo/tpfkKrDvNg2f0=
github.com/goravel/framework v1.13.1-0.20231105170024-1042844af36a/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
Expand Down

0 comments on commit 485b7b9

Please sign in to comment.