mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-30 03:50:25 +08:00
[SSL证书]免费证书申请增加HTTP认证方式
This commit is contained in:
54
internal/db/models/acme_authentication_dao.go
Normal file
54
internal/db/models/acme_authentication_dao.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type ACMEAuthenticationDAO dbs.DAO
|
||||
|
||||
func NewACMEAuthenticationDAO() *ACMEAuthenticationDAO {
|
||||
return dbs.NewDAO(&ACMEAuthenticationDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeACMEAuthentications",
|
||||
Model: new(ACMEAuthentication),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*ACMEAuthenticationDAO)
|
||||
}
|
||||
|
||||
var SharedACMEAuthenticationDAO *ACMEAuthenticationDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedACMEAuthenticationDAO = NewACMEAuthenticationDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// 创建认证信息
|
||||
func (this *ACMEAuthenticationDAO) CreateAuth(taskId int64, domain string, token string, key string) error {
|
||||
op := NewACMEAuthenticationOperator()
|
||||
op.TaskId = taskId
|
||||
op.Domain = domain
|
||||
op.Token = token
|
||||
op.Key = key
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 根据令牌查找认证信息
|
||||
func (this *ACMEAuthenticationDAO) FindAuthWithToken(token string) (*ACMEAuthentication, error) {
|
||||
one, err := this.Query().
|
||||
Attr("token", token).
|
||||
DescPk().
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if one == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return one.(*ACMEAuthentication), nil
|
||||
}
|
||||
Reference in New Issue
Block a user