mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-04-08 06:35:18 +08:00
准备0.0.2.1开发
This commit is contained in:
93
internal/acme/acme_test.go
Normal file
93
internal/acme/acme_test.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package acme
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
acmelog "github.com/go-acme/lego/v4/log"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/registration"
|
||||
)
|
||||
|
||||
// You'll need a user or account type that implements acme.User
|
||||
type MyUser struct {
|
||||
Email string
|
||||
Registration *registration.Resource
|
||||
key crypto.PrivateKey
|
||||
}
|
||||
|
||||
func (u *MyUser) GetEmail() string {
|
||||
return u.Email
|
||||
}
|
||||
func (u MyUser) GetRegistration() *registration.Resource {
|
||||
return u.Registration
|
||||
}
|
||||
func (u *MyUser) GetPrivateKey() crypto.PrivateKey {
|
||||
return u.key
|
||||
}
|
||||
|
||||
type MyProvider struct {
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (this *MyProvider) Present(domain, token, keyAuth string) error {
|
||||
fqdn, value := dns01.GetRecord(domain, keyAuth)
|
||||
this.t.Log("provider: domain:", domain, "fqdn:", fqdn, "value:", value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *MyProvider) CleanUp(domain, token, keyAuth string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 参考 https://go-acme.github.io/lego/usage/library/
|
||||
func TestGenerate(t *testing.T) {
|
||||
acmelog.Logger = log.New(ioutil.Discard, "", log.LstdFlags)
|
||||
|
||||
// 生成私钥
|
||||
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
myUser := &MyUser{
|
||||
Email: "test1@teaos.cn",
|
||||
key: privateKey,
|
||||
}
|
||||
|
||||
config := lego.NewConfig(myUser)
|
||||
config.Certificate.KeyType = certcrypto.RSA2048
|
||||
|
||||
client, err := lego.NewClient(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = client.Challenge.SetDNS01Provider(&MyProvider{t: t})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// New users will need to register
|
||||
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
myUser.Registration = reg
|
||||
|
||||
request := certificate.ObtainRequest{
|
||||
Domains: []string{"teaos.com"},
|
||||
Bundle: true,
|
||||
}
|
||||
certificates, err := client.Certificate.Obtain(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(certificates)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
Version = "0.0.2"
|
||||
Version = "0.0.2.1"
|
||||
|
||||
ProductName = "Edge API"
|
||||
ProcessName = "edge-api"
|
||||
|
||||
63
internal/db/models/acme_user_dao.go
Normal file
63
internal/db/models/acme_user_dao.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
ACMEUserStateEnabled = 1 // 已启用
|
||||
ACMEUserStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type ACMEUserDAO dbs.DAO
|
||||
|
||||
func NewACMEUserDAO() *ACMEUserDAO {
|
||||
return dbs.NewDAO(&ACMEUserDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeACMEUsers",
|
||||
Model: new(ACMEUser),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*ACMEUserDAO)
|
||||
}
|
||||
|
||||
var SharedACMEUserDAO *ACMEUserDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedACMEUserDAO = NewACMEUserDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
func (this *ACMEUserDAO) EnableACMEUser(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", ACMEUserStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *ACMEUserDAO) DisableACMEUser(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", ACMEUserStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *ACMEUserDAO) FindEnabledACMEUser(id int64) (*ACMEUser, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", ACMEUserStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*ACMEUser), err
|
||||
}
|
||||
5
internal/db/models/acme_user_dao_test.go
Normal file
5
internal/db/models/acme_user_dao_test.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
28
internal/db/models/acme_user_model.go
Normal file
28
internal/db/models/acme_user_model.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
//
|
||||
type ACMEUser struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
PrivateKey string `field:"privateKey"` // 私钥
|
||||
Email string `field:"email"` // E-mail
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
State uint8 `field:"state"` // 状态
|
||||
Description string `field:"description"` // 备注介绍
|
||||
}
|
||||
|
||||
type ACMEUserOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
PrivateKey interface{} // 私钥
|
||||
Email interface{} // E-mail
|
||||
CreatedAt interface{} // 创建时间
|
||||
State interface{} // 状态
|
||||
Description interface{} // 备注介绍
|
||||
}
|
||||
|
||||
func NewACMEUserOperator() *ACMEUserOperator {
|
||||
return &ACMEUserOperator{}
|
||||
}
|
||||
1
internal/db/models/acme_user_model_ext.go
Normal file
1
internal/db/models/acme_user_model_ext.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
@@ -4,6 +4,7 @@ package models
|
||||
type DNSDomain struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
ProviderId uint32 `field:"providerId"` // 服务商ID
|
||||
IsOn uint8 `field:"isOn"` // 是否可用
|
||||
Name string `field:"name"` // 域名
|
||||
@@ -19,6 +20,7 @@ type DNSDomain struct {
|
||||
type DNSDomainOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
ProviderId interface{} // 服务商ID
|
||||
IsOn interface{} // 是否可用
|
||||
Name interface{} // 域名
|
||||
|
||||
@@ -5,6 +5,7 @@ type DNSProvider struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
Name string `field:"name"` // 名称
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
Type string `field:"type"` // 供应商类型
|
||||
ApiParams string `field:"apiParams"` // API参数
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
@@ -16,6 +17,7 @@ type DNSProviderOperator struct {
|
||||
Id interface{} // ID
|
||||
Name interface{} // 名称
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
Type interface{} // 供应商类型
|
||||
ApiParams interface{} // API参数
|
||||
CreatedAt interface{} // 创建时间
|
||||
|
||||
@@ -2,45 +2,51 @@ package models
|
||||
|
||||
// SSL证书
|
||||
type SSLCert struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
Name string `field:"name"` // 证书名
|
||||
Description string `field:"description"` // 描述
|
||||
CertData string `field:"certData"` // 证书内容
|
||||
KeyData string `field:"keyData"` // 密钥内容
|
||||
ServerName string `field:"serverName"` // 证书使用的主机名
|
||||
IsCA uint8 `field:"isCA"` // 是否为CA证书
|
||||
GroupIds string `field:"groupIds"` // 证书分组
|
||||
TimeBeginAt uint64 `field:"timeBeginAt"` // 开始时间
|
||||
TimeEndAt uint64 `field:"timeEndAt"` // 结束时间
|
||||
DnsNames string `field:"dnsNames"` // DNS名称列表
|
||||
CommonNames string `field:"commonNames"` // 发行单位列表
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
Name string `field:"name"` // 证书名
|
||||
Description string `field:"description"` // 描述
|
||||
CertData string `field:"certData"` // 证书内容
|
||||
KeyData string `field:"keyData"` // 密钥内容
|
||||
ServerName string `field:"serverName"` // 证书使用的主机名
|
||||
IsCA uint8 `field:"isCA"` // 是否为CA证书
|
||||
GroupIds string `field:"groupIds"` // 证书分组
|
||||
TimeBeginAt uint64 `field:"timeBeginAt"` // 开始时间
|
||||
TimeEndAt uint64 `field:"timeEndAt"` // 结束时间
|
||||
DnsNames string `field:"dnsNames"` // DNS名称列表
|
||||
CommonNames string `field:"commonNames"` // 发行单位列表
|
||||
IsACME uint8 `field:"isACME"` // 是否为ACME自动生成的
|
||||
AcmeUserId uint64 `field:"acmeUserId"` // ACME用户ID
|
||||
AcmeAutoRenew uint8 `field:"acmeAutoRenew"` // ACME生成后是否自动更新
|
||||
}
|
||||
|
||||
type SSLCertOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
UpdatedAt interface{} // 修改时间
|
||||
IsOn interface{} // 是否启用
|
||||
Name interface{} // 证书名
|
||||
Description interface{} // 描述
|
||||
CertData interface{} // 证书内容
|
||||
KeyData interface{} // 密钥内容
|
||||
ServerName interface{} // 证书使用的主机名
|
||||
IsCA interface{} // 是否为CA证书
|
||||
GroupIds interface{} // 证书分组
|
||||
TimeBeginAt interface{} // 开始时间
|
||||
TimeEndAt interface{} // 结束时间
|
||||
DnsNames interface{} // DNS名称列表
|
||||
CommonNames interface{} // 发行单位列表
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
UpdatedAt interface{} // 修改时间
|
||||
IsOn interface{} // 是否启用
|
||||
Name interface{} // 证书名
|
||||
Description interface{} // 描述
|
||||
CertData interface{} // 证书内容
|
||||
KeyData interface{} // 密钥内容
|
||||
ServerName interface{} // 证书使用的主机名
|
||||
IsCA interface{} // 是否为CA证书
|
||||
GroupIds interface{} // 证书分组
|
||||
TimeBeginAt interface{} // 开始时间
|
||||
TimeEndAt interface{} // 结束时间
|
||||
DnsNames interface{} // DNS名称列表
|
||||
CommonNames interface{} // 发行单位列表
|
||||
IsACME interface{} // 是否为ACME自动生成的
|
||||
AcmeUserId interface{} // ACME用户ID
|
||||
AcmeAutoRenew interface{} // ACME生成后是否自动更新
|
||||
}
|
||||
|
||||
func NewSSLCertOperator() *SSLCertOperator {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user