mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: deploy config to remote nodes #359
This commit is contained in:
parent
e75dce92ad
commit
1c1da92363
46 changed files with 1480 additions and 605 deletions
|
@ -45,6 +45,8 @@ func newCert(db *gorm.DB, opts ...gen.DOOption) cert {
|
|||
_cert.Log = field.NewString(tableName, "log")
|
||||
_cert.Resource = field.NewField(tableName, "resource")
|
||||
_cert.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
|
||||
_cert.MustStaple = field.NewBool(tableName, "must_staple")
|
||||
_cert.LegoDisableCNAMESupport = field.NewBool(tableName, "lego_disable_cname_support")
|
||||
_cert.DnsCredential = certBelongsToDnsCredential{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
|
@ -65,25 +67,27 @@ func newCert(db *gorm.DB, opts ...gen.DOOption) cert {
|
|||
type cert struct {
|
||||
certDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Name field.String
|
||||
Domains field.Field
|
||||
Filename field.String
|
||||
SSLCertificatePath field.String
|
||||
SSLCertificateKeyPath field.String
|
||||
AutoCert field.Int
|
||||
ChallengeMethod field.String
|
||||
DnsCredentialID field.Int
|
||||
ACMEUserID field.Int
|
||||
KeyType field.String
|
||||
Log field.String
|
||||
Resource field.Field
|
||||
SyncNodeIds field.Field
|
||||
DnsCredential certBelongsToDnsCredential
|
||||
ALL field.Asterisk
|
||||
ID field.Int
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Name field.String
|
||||
Domains field.Field
|
||||
Filename field.String
|
||||
SSLCertificatePath field.String
|
||||
SSLCertificateKeyPath field.String
|
||||
AutoCert field.Int
|
||||
ChallengeMethod field.String
|
||||
DnsCredentialID field.Int
|
||||
ACMEUserID field.Int
|
||||
KeyType field.String
|
||||
Log field.String
|
||||
Resource field.Field
|
||||
SyncNodeIds field.Field
|
||||
MustStaple field.Bool
|
||||
LegoDisableCNAMESupport field.Bool
|
||||
DnsCredential certBelongsToDnsCredential
|
||||
|
||||
ACMEUser certBelongsToACMEUser
|
||||
|
||||
|
@ -119,6 +123,8 @@ func (c *cert) updateTableName(table string) *cert {
|
|||
c.Log = field.NewString(table, "log")
|
||||
c.Resource = field.NewField(table, "resource")
|
||||
c.SyncNodeIds = field.NewField(table, "sync_node_ids")
|
||||
c.MustStaple = field.NewBool(table, "must_staple")
|
||||
c.LegoDisableCNAMESupport = field.NewBool(table, "lego_disable_cname_support")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
|
@ -135,7 +141,7 @@ func (c *cert) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (c *cert) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 19)
|
||||
c.fieldMap = make(map[string]field.Expr, 21)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
|
@ -153,6 +159,8 @@ func (c *cert) fillFieldMap() {
|
|||
c.fieldMap["log"] = c.Log
|
||||
c.fieldMap["resource"] = c.Resource
|
||||
c.fieldMap["sync_node_ids"] = c.SyncNodeIds
|
||||
c.fieldMap["must_staple"] = c.MustStaple
|
||||
c.fieldMap["lego_disable_cname_support"] = c.LegoDisableCNAMESupport
|
||||
|
||||
}
|
||||
|
||||
|
|
370
query/configs.gen.go
Normal file
370
query/configs.gen.go
Normal file
|
@ -0,0 +1,370 @@
|
|||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
)
|
||||
|
||||
func newConfig(db *gorm.DB, opts ...gen.DOOption) config {
|
||||
_config := config{}
|
||||
|
||||
_config.configDo.UseDB(db, opts...)
|
||||
_config.configDo.UseModel(&model.Config{})
|
||||
|
||||
tableName := _config.configDo.TableName()
|
||||
_config.ALL = field.NewAsterisk(tableName)
|
||||
_config.ID = field.NewInt(tableName, "id")
|
||||
_config.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_config.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_config.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_config.Filepath = field.NewString(tableName, "filepath")
|
||||
_config.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
|
||||
|
||||
_config.fillFieldMap()
|
||||
|
||||
return _config
|
||||
}
|
||||
|
||||
type config struct {
|
||||
configDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Filepath field.String
|
||||
SyncNodeIds field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c config) Table(newTableName string) *config {
|
||||
c.configDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c config) As(alias string) *config {
|
||||
c.configDo.DO = *(c.configDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *config) updateTableName(table string) *config {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt(table, "id")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
c.Filepath = field.NewString(table, "filepath")
|
||||
c.SyncNodeIds = field.NewField(table, "sync_node_ids")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *config) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := c.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (c *config) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 6)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
c.fieldMap["filepath"] = c.Filepath
|
||||
c.fieldMap["sync_node_ids"] = c.SyncNodeIds
|
||||
}
|
||||
|
||||
func (c config) clone(db *gorm.DB) config {
|
||||
c.configDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c config) replaceDB(db *gorm.DB) config {
|
||||
c.configDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type configDo struct{ gen.DO }
|
||||
|
||||
// FirstByID Where("id=@id")
|
||||
func (c configDo) FirstByID(id int) (result *model.Config, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = c.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
|
||||
func (c configDo) DeleteByID(id int) (err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("update configs set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = c.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) Debug() *configDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c configDo) WithContext(ctx context.Context) *configDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c configDo) ReadDB() *configDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c configDo) WriteDB() *configDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c configDo) Session(config *gorm.Session) *configDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c configDo) Clauses(conds ...clause.Expression) *configDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Returning(value interface{}, columns ...string) *configDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c configDo) Not(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Or(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Select(conds ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Where(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Order(conds ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Distinct(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Omit(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Join(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) LeftJoin(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) RightJoin(table schema.Tabler, on ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c configDo) Group(cols ...field.Expr) *configDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c configDo) Having(conds ...gen.Condition) *configDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c configDo) Limit(limit int) *configDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c configDo) Offset(offset int) *configDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c configDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *configDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c configDo) Unscoped() *configDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c configDo) Create(values ...*model.Config) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c configDo) CreateInBatches(values []*model.Config, batchSize int) error {
|
||||
return c.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (c configDo) Save(values ...*model.Config) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c configDo) First() (*model.Config, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Take() (*model.Config, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Last() (*model.Config, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) Find() ([]*model.Config, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*model.Config), err
|
||||
}
|
||||
|
||||
func (c configDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Config, err error) {
|
||||
buf := make([]*model.Config, 0, batchSize)
|
||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (c configDo) FindInBatches(result *[]*model.Config, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c configDo) Attrs(attrs ...field.AssignExpr) *configDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c configDo) Assign(attrs ...field.AssignExpr) *configDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c configDo) Joins(fields ...field.RelationField) *configDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c configDo) Preload(fields ...field.RelationField) *configDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c configDo) FirstOrInit() (*model.Config, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) FirstOrCreate() (*model.Config, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Config), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configDo) FindByPage(offset int, limit int) (result []*model.Config, count int64, err error) {
|
||||
result, err = c.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = c.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = c.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (c configDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c configDo) Delete(models ...*model.Config) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (c *configDo) withDO(do gen.Dao) *configDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
|
@ -23,6 +23,7 @@ var (
|
|||
BanIP *banIP
|
||||
Cert *cert
|
||||
ChatGPTLog *chatGPTLog
|
||||
Config *config
|
||||
ConfigBackup *configBackup
|
||||
DnsCredential *dnsCredential
|
||||
Environment *environment
|
||||
|
@ -39,6 +40,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
|||
BanIP = &Q.BanIP
|
||||
Cert = &Q.Cert
|
||||
ChatGPTLog = &Q.ChatGPTLog
|
||||
Config = &Q.Config
|
||||
ConfigBackup = &Q.ConfigBackup
|
||||
DnsCredential = &Q.DnsCredential
|
||||
Environment = &Q.Environment
|
||||
|
@ -56,6 +58,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|||
BanIP: newBanIP(db, opts...),
|
||||
Cert: newCert(db, opts...),
|
||||
ChatGPTLog: newChatGPTLog(db, opts...),
|
||||
Config: newConfig(db, opts...),
|
||||
ConfigBackup: newConfigBackup(db, opts...),
|
||||
DnsCredential: newDnsCredential(db, opts...),
|
||||
Environment: newEnvironment(db, opts...),
|
||||
|
@ -74,6 +77,7 @@ type Query struct {
|
|||
BanIP banIP
|
||||
Cert cert
|
||||
ChatGPTLog chatGPTLog
|
||||
Config config
|
||||
ConfigBackup configBackup
|
||||
DnsCredential dnsCredential
|
||||
Environment environment
|
||||
|
@ -93,6 +97,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
|||
BanIP: q.BanIP.clone(db),
|
||||
Cert: q.Cert.clone(db),
|
||||
ChatGPTLog: q.ChatGPTLog.clone(db),
|
||||
Config: q.Config.clone(db),
|
||||
ConfigBackup: q.ConfigBackup.clone(db),
|
||||
DnsCredential: q.DnsCredential.clone(db),
|
||||
Environment: q.Environment.clone(db),
|
||||
|
@ -119,6 +124,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|||
BanIP: q.BanIP.replaceDB(db),
|
||||
Cert: q.Cert.replaceDB(db),
|
||||
ChatGPTLog: q.ChatGPTLog.replaceDB(db),
|
||||
Config: q.Config.replaceDB(db),
|
||||
ConfigBackup: q.ConfigBackup.replaceDB(db),
|
||||
DnsCredential: q.DnsCredential.replaceDB(db),
|
||||
Environment: q.Environment.replaceDB(db),
|
||||
|
@ -135,6 +141,7 @@ type queryCtx struct {
|
|||
BanIP *banIPDo
|
||||
Cert *certDo
|
||||
ChatGPTLog *chatGPTLogDo
|
||||
Config *configDo
|
||||
ConfigBackup *configBackupDo
|
||||
DnsCredential *dnsCredentialDo
|
||||
Environment *environmentDo
|
||||
|
@ -151,6 +158,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
|||
BanIP: q.BanIP.WithContext(ctx),
|
||||
Cert: q.Cert.WithContext(ctx),
|
||||
ChatGPTLog: q.ChatGPTLog.WithContext(ctx),
|
||||
Config: q.Config.WithContext(ctx),
|
||||
ConfigBackup: q.ConfigBackup.WithContext(ctx),
|
||||
DnsCredential: q.DnsCredential.WithContext(ctx),
|
||||
Environment: q.Environment.WithContext(ctx),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue