Files
Jacky 69cfa82b1d feat: self-signed certificate support (#1655) (#1688)
* feat(cert): add self-signed certificate type and config to model

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): generate self-signed leaf certificates

Add GenerateSelfSigned / SelfSignedOptions plus five new error codes
(50032-50036) and a full TDD test suite covering valid cert output,
multiple key types, empty-SAN rejection, and invalid-IP rejection.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): regenerate self-signed certificates with key reuse

Add RegenerateSelfSigned, SelfSignedOptionsFromModel, deriveSelfSignedCommonName,
loadSelfSignedKey, and parsePrivateKeyPEM to support re-issuing self-signed
certificates for the auto-renewal job, reusing the on-disk private key when possible.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): add self-signed certificate renewal worker

Add auto-renewal worker for self-signed certificates that mirrors the
ACME renewal logic, using a dedicated shouldRenewSelfSignedCert threshold
function verified with TDD.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cron): schedule self-signed certificate renewal

Register setupSelfSignedCertRenewalJob as a periodic cron job (every
30 minutes) in InitCronJobs, mirroring the existing setupAutoCertJob
pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(api): add self-signed certificate generation endpoints

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): add self-signed certificate frontend API

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): add shared self-signed certificate fields component

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): add self-signed certificate generation modal and list entry

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): support self-signed certificates in the editor

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(site): generate self-signed certificates from the site editor

Extract hasTLSListen/ensureDirective/ensureTLSDirectives into a shared
useTLSDirectives composable, refactor ObtainCert.vue to use it, and add
SelfSignedCert.vue to the site cert tab so users can generate and apply
a self-signed certificate directly from the site editor.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cert): validate self-signed key type and name IP-only renewals

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(cert): apply code-review cleanup

- reuse certcrypto.ParsePEMPrivateKey instead of a hand-rolled PEM
  private-key parser
- stop exporting the unused ensureDirective from useTLSDirectives
- use the AutoCertState enum instead of integer literals in certColumns
- allocate the renewal Logger only when renewal is attempted, avoiding a
  per-tick goroutine and empty-log database write for non-due certificates

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cert): address PR #1688 review feedback

- clean up the partial certificate directory when the initial write
  fails, not just the database row
- log a warning when the existing self-signed private key cannot be
  reused so operators notice the public-key fingerprint has changed
- defensively copy the model's Domains and IPAddresses slices in
  SelfSignedOptionsFromModel
- require an explicit "Save now" confirmation after generating from the
  site editor, and write the directives into the editor first so the
  user can review the diff before saving

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cert): harden self-signed certificate lifecycle

Reuse private keys on manual self-signed edits, make certificate writes safer, clean managed self-signed files on delete, and guard renewal against missing config.

* fix(cert): harden self-signed frontend handling

Avoid undefined certificate redirects, rely on payload defaults for self-signed fields, and parse TLS listen directives precisely.

* fix(site): satisfy strict listen regex lint

Escape the IPv6 listen closing bracket explicitly so the strict regexp lint rule accepts TLS listen parsing.

* fix(cert): harden self-signed key handling

Co-authored-by: Jacky <me@jackyu.cn>

* docs(cert): design merging self-signed entry into issue dialog

Spec for collapsing the Certificate list header from three actions to
two by adding a Self-signed option inside the existing Issue Certificate
dialog.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(cert): plan merging self-signed into issue dialog

Step-by-step plan that turns the spec into two scoped commits:
extend DNSIssueCertificate with a self-signed type, then drop the
standalone header button from the certificate list view.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): add self-signed option in issue certificate dialog

Extend the Issue Certificate dialog's Certificate Type select with a
"Self-signed" option that swaps the form body to SelfSignedCertFields
and routes submission through cert.generate_self_signed(). ACME paths
(Wildcard / Custom Domains) are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(cert): drop standalone self-signed button from list header

Certificate creation is now consolidated under the Issue Certificate
dialog (which exposes Self-signed as a Certificate Type option), so
the duplicate header entry, its ref, handler, and modal mount are
removed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(cert): design self-signed UX enhancements

Adds a reusable StringListInput, renewal-policy hint in the self-signed
form, and a required Name field (frontend + backend). Builds on the
prior merge spec.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(cert): plan self-signed UX enhancements

Six-task plan: extract StringListInput, require Name backend + test,
refactor SelfSignedCertFields with renewal hint, hide duplicate alert
in editor, seed/filter payloads with Name validation, and adopt
StringListInput in the ACME Custom Domains branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(ui): add StringListInput component

Reusable multi-row text input with Add/Remove buttons. Used in the
upcoming refactor of Custom Domains and self-signed Domains / IP
Addresses editors so all three share a single editor pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(ui): simplify StringListInput model write and add a11y label

Replace the captured-index update closure with v-model:value on
items[index] so input events are guaranteed to write to the array
slot currently bound to the DOM input. Add an aria-label suffix
on the Remove button so screen readers can distinguish rows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): require Name when generating self-signed certificates

Adds binding:"required" to SelfSignedCertRequest.Name so an empty name
is rejected at the request boundary, and covers the contract with a
new API-level test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): unify self-signed editor and surface renewal hint

Switch Domains and IP Addresses to the shared StringListInput so all
self-signed field editors match the Custom Domains pattern. Add an
auto-renewal hint (suppressible via hideRenewalNote) and mark Name as
required to match the new backend contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(cert): suppress duplicate renewal alert in cert editor

SelfSignedCertManagement already has its own renewal-status alert;
pass hide-renewal-note to SelfSignedCertFields to avoid showing two
adjacent alerts saying the same thing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(cert): seed and filter self-signed payloads, validate Name

StringListInput preserves empty placeholder rows for editing; seed
arrays with [''] in toSelfSignedPayload / emptySelfSignedPayload /
emptyForm so the editor always renders an empty row to type into.

Each submit/save path trims and filters the arrays before sending and
now rejects an empty Name client-side to match the new server contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(cert): make SelfSignedCertPayload.name required

Every factory already seeds name as ''; the optional marker forced
defensive (name ?? '').trim() at three call sites. Align the type
with reality.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(cert): use StringListInput for Custom Domains

Drop the inline multi-row template + add/remove helpers in favour of
the shared StringListInput component, matching the editor used by the
self-signed branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(ui): regenerate components.d.ts for StringListInput

Auto-generated by unplugin-vue-components after the new component
was added under app/src/components/StringListInput/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(cert): render key_type for both legacy and canonical forms

The backend's helper.GetKeyType normalizes key_type to its canonical
form (EC256, RSA2048…) on every write — self-signed generation as well
as the ModifyCert BeforeExecuteHook. The frontend PrivateKeyTypeMask
was keyed only by the legacy form (P256, 2048…), so maskRender returned
"/" for every cert that took a write path through normalization.

Two reported symptoms with the same root cause:
- New self-signed cert always shows "/" in the Key Type column
- Editing any ACME cert (issue #1697) flips its column to "/" after save

Add formatPrivateKeyType / normalizePrivateKeyType helpers that map both
forms to the frontend's legacy key. Use them in the list column renderer
and when loading certs into the self-signed and ACME editor forms so the
ASelect highlights the correct option.

Fixes #1697.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* style(cert): cap self-signed fields width at 600px

The fields stretched full-width inside the certificate editor page; cap
the form at 600px to match AutoCertManagement and keep the editing area
readable. Modal consumers were already bounded by their own width, so
the change is invisible there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: update translations

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Hintay <hintay@me.com>
2026-05-24 09:22:21 +08:00

634 lines
18 KiB
Go

// 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 newCert(db *gorm.DB, opts ...gen.DOOption) cert {
_cert := cert{}
_cert.certDo.UseDB(db, opts...)
_cert.certDo.UseModel(&model.Cert{})
tableName := _cert.certDo.TableName()
_cert.ALL = field.NewAsterisk(tableName)
_cert.ID = field.NewUint64(tableName, "id")
_cert.CreatedAt = field.NewTime(tableName, "created_at")
_cert.UpdatedAt = field.NewTime(tableName, "updated_at")
_cert.DeletedAt = field.NewField(tableName, "deleted_at")
_cert.Name = field.NewString(tableName, "name")
_cert.Domains = field.NewField(tableName, "domains")
_cert.Filename = field.NewString(tableName, "filename")
_cert.SSLCertificatePath = field.NewString(tableName, "ssl_certificate_path")
_cert.SSLCertificateKeyPath = field.NewString(tableName, "ssl_certificate_key_path")
_cert.AutoCert = field.NewInt(tableName, "auto_cert")
_cert.ChallengeMethod = field.NewString(tableName, "challenge_method")
_cert.DnsCredentialID = field.NewUint64(tableName, "dns_credential_id")
_cert.ACMEUserID = field.NewUint64(tableName, "acme_user_id")
_cert.KeyType = field.NewString(tableName, "key_type")
_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.RevokeOld = field.NewBool(tableName, "revoke_old")
_cert.SelfSignedConfig = field.NewField(tableName, "self_signed_config")
_cert.LastAutoRenewAt = field.NewTime(tableName, "last_auto_renew_at")
_cert.LastAutoRenewError = field.NewString(tableName, "last_auto_renew_error")
_cert.Status = field.NewString(tableName, "status")
_cert.LastError = field.NewString(tableName, "last_error")
_cert.LastAttemptAt = field.NewTime(tableName, "last_attempt_at")
_cert.DnsCredential = certBelongsToDnsCredential{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("DnsCredential", "model.DnsCredential"),
}
_cert.ACMEUser = certBelongsToACMEUser{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("ACMEUser", "model.AcmeUser"),
}
_cert.fillFieldMap()
return _cert
}
type cert struct {
certDo
ALL field.Asterisk
ID field.Uint64
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.Uint64
ACMEUserID field.Uint64
KeyType field.String
Log field.String
Resource field.Field
SyncNodeIds field.Field
MustStaple field.Bool
LegoDisableCNAMESupport field.Bool
RevokeOld field.Bool
SelfSignedConfig field.Field
LastAutoRenewAt field.Time
LastAutoRenewError field.String
Status field.String
LastError field.String
LastAttemptAt field.Time
DnsCredential certBelongsToDnsCredential
ACMEUser certBelongsToACMEUser
fieldMap map[string]field.Expr
}
func (c cert) Table(newTableName string) *cert {
c.certDo.UseTable(newTableName)
return c.updateTableName(newTableName)
}
func (c cert) As(alias string) *cert {
c.certDo.DO = *(c.certDo.As(alias).(*gen.DO))
return c.updateTableName(alias)
}
func (c *cert) updateTableName(table string) *cert {
c.ALL = field.NewAsterisk(table)
c.ID = field.NewUint64(table, "id")
c.CreatedAt = field.NewTime(table, "created_at")
c.UpdatedAt = field.NewTime(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at")
c.Name = field.NewString(table, "name")
c.Domains = field.NewField(table, "domains")
c.Filename = field.NewString(table, "filename")
c.SSLCertificatePath = field.NewString(table, "ssl_certificate_path")
c.SSLCertificateKeyPath = field.NewString(table, "ssl_certificate_key_path")
c.AutoCert = field.NewInt(table, "auto_cert")
c.ChallengeMethod = field.NewString(table, "challenge_method")
c.DnsCredentialID = field.NewUint64(table, "dns_credential_id")
c.ACMEUserID = field.NewUint64(table, "acme_user_id")
c.KeyType = field.NewString(table, "key_type")
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.RevokeOld = field.NewBool(table, "revoke_old")
c.SelfSignedConfig = field.NewField(table, "self_signed_config")
c.LastAutoRenewAt = field.NewTime(table, "last_auto_renew_at")
c.LastAutoRenewError = field.NewString(table, "last_auto_renew_error")
c.Status = field.NewString(table, "status")
c.LastError = field.NewString(table, "last_error")
c.LastAttemptAt = field.NewTime(table, "last_attempt_at")
c.fillFieldMap()
return c
}
func (c *cert) 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 *cert) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 28)
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["name"] = c.Name
c.fieldMap["domains"] = c.Domains
c.fieldMap["filename"] = c.Filename
c.fieldMap["ssl_certificate_path"] = c.SSLCertificatePath
c.fieldMap["ssl_certificate_key_path"] = c.SSLCertificateKeyPath
c.fieldMap["auto_cert"] = c.AutoCert
c.fieldMap["challenge_method"] = c.ChallengeMethod
c.fieldMap["dns_credential_id"] = c.DnsCredentialID
c.fieldMap["acme_user_id"] = c.ACMEUserID
c.fieldMap["key_type"] = c.KeyType
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
c.fieldMap["revoke_old"] = c.RevokeOld
c.fieldMap["self_signed_config"] = c.SelfSignedConfig
c.fieldMap["last_auto_renew_at"] = c.LastAutoRenewAt
c.fieldMap["last_auto_renew_error"] = c.LastAutoRenewError
c.fieldMap["status"] = c.Status
c.fieldMap["last_error"] = c.LastError
c.fieldMap["last_attempt_at"] = c.LastAttemptAt
}
func (c cert) clone(db *gorm.DB) cert {
c.certDo.ReplaceConnPool(db.Statement.ConnPool)
c.DnsCredential.db = db.Session(&gorm.Session{Initialized: true})
c.DnsCredential.db.Statement.ConnPool = db.Statement.ConnPool
c.ACMEUser.db = db.Session(&gorm.Session{Initialized: true})
c.ACMEUser.db.Statement.ConnPool = db.Statement.ConnPool
return c
}
func (c cert) replaceDB(db *gorm.DB) cert {
c.certDo.ReplaceDB(db)
c.DnsCredential.db = db.Session(&gorm.Session{})
c.ACMEUser.db = db.Session(&gorm.Session{})
return c
}
type certBelongsToDnsCredential struct {
db *gorm.DB
field.RelationField
}
func (a certBelongsToDnsCredential) Where(conds ...field.Expr) *certBelongsToDnsCredential {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a certBelongsToDnsCredential) WithContext(ctx context.Context) *certBelongsToDnsCredential {
a.db = a.db.WithContext(ctx)
return &a
}
func (a certBelongsToDnsCredential) Session(session *gorm.Session) *certBelongsToDnsCredential {
a.db = a.db.Session(session)
return &a
}
func (a certBelongsToDnsCredential) Model(m *model.Cert) *certBelongsToDnsCredentialTx {
return &certBelongsToDnsCredentialTx{a.db.Model(m).Association(a.Name())}
}
func (a certBelongsToDnsCredential) Unscoped() *certBelongsToDnsCredential {
a.db = a.db.Unscoped()
return &a
}
type certBelongsToDnsCredentialTx struct{ tx *gorm.Association }
func (a certBelongsToDnsCredentialTx) Find() (result *model.DnsCredential, err error) {
return result, a.tx.Find(&result)
}
func (a certBelongsToDnsCredentialTx) Append(values ...*model.DnsCredential) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a certBelongsToDnsCredentialTx) Replace(values ...*model.DnsCredential) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a certBelongsToDnsCredentialTx) Delete(values ...*model.DnsCredential) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a certBelongsToDnsCredentialTx) Clear() error {
return a.tx.Clear()
}
func (a certBelongsToDnsCredentialTx) Count() int64 {
return a.tx.Count()
}
func (a certBelongsToDnsCredentialTx) Unscoped() *certBelongsToDnsCredentialTx {
a.tx = a.tx.Unscoped()
return &a
}
type certBelongsToACMEUser struct {
db *gorm.DB
field.RelationField
}
func (a certBelongsToACMEUser) Where(conds ...field.Expr) *certBelongsToACMEUser {
if len(conds) == 0 {
return &a
}
exprs := make([]clause.Expression, 0, len(conds))
for _, cond := range conds {
exprs = append(exprs, cond.BeCond().(clause.Expression))
}
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
return &a
}
func (a certBelongsToACMEUser) WithContext(ctx context.Context) *certBelongsToACMEUser {
a.db = a.db.WithContext(ctx)
return &a
}
func (a certBelongsToACMEUser) Session(session *gorm.Session) *certBelongsToACMEUser {
a.db = a.db.Session(session)
return &a
}
func (a certBelongsToACMEUser) Model(m *model.Cert) *certBelongsToACMEUserTx {
return &certBelongsToACMEUserTx{a.db.Model(m).Association(a.Name())}
}
func (a certBelongsToACMEUser) Unscoped() *certBelongsToACMEUser {
a.db = a.db.Unscoped()
return &a
}
type certBelongsToACMEUserTx struct{ tx *gorm.Association }
func (a certBelongsToACMEUserTx) Find() (result *model.AcmeUser, err error) {
return result, a.tx.Find(&result)
}
func (a certBelongsToACMEUserTx) Append(values ...*model.AcmeUser) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a certBelongsToACMEUserTx) Replace(values ...*model.AcmeUser) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a certBelongsToACMEUserTx) Delete(values ...*model.AcmeUser) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a certBelongsToACMEUserTx) Clear() error {
return a.tx.Clear()
}
func (a certBelongsToACMEUserTx) Count() int64 {
return a.tx.Count()
}
func (a certBelongsToACMEUserTx) Unscoped() *certBelongsToACMEUserTx {
a.tx = a.tx.Unscoped()
return &a
}
type certDo struct{ gen.DO }
// FirstByID Where("id=@id")
func (c certDo) FirstByID(id uint64) (result *model.Cert, 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 certDo) DeleteByID(id uint64) (err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, id)
generateSQL.WriteString("update certs 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 certDo) Debug() *certDo {
return c.withDO(c.DO.Debug())
}
func (c certDo) WithContext(ctx context.Context) *certDo {
return c.withDO(c.DO.WithContext(ctx))
}
func (c certDo) ReadDB() *certDo {
return c.Clauses(dbresolver.Read)
}
func (c certDo) WriteDB() *certDo {
return c.Clauses(dbresolver.Write)
}
func (c certDo) Session(config *gorm.Session) *certDo {
return c.withDO(c.DO.Session(config))
}
func (c certDo) Clauses(conds ...clause.Expression) *certDo {
return c.withDO(c.DO.Clauses(conds...))
}
func (c certDo) Returning(value interface{}, columns ...string) *certDo {
return c.withDO(c.DO.Returning(value, columns...))
}
func (c certDo) Not(conds ...gen.Condition) *certDo {
return c.withDO(c.DO.Not(conds...))
}
func (c certDo) Or(conds ...gen.Condition) *certDo {
return c.withDO(c.DO.Or(conds...))
}
func (c certDo) Select(conds ...field.Expr) *certDo {
return c.withDO(c.DO.Select(conds...))
}
func (c certDo) Where(conds ...gen.Condition) *certDo {
return c.withDO(c.DO.Where(conds...))
}
func (c certDo) Order(conds ...field.Expr) *certDo {
return c.withDO(c.DO.Order(conds...))
}
func (c certDo) Distinct(cols ...field.Expr) *certDo {
return c.withDO(c.DO.Distinct(cols...))
}
func (c certDo) Omit(cols ...field.Expr) *certDo {
return c.withDO(c.DO.Omit(cols...))
}
func (c certDo) Join(table schema.Tabler, on ...field.Expr) *certDo {
return c.withDO(c.DO.Join(table, on...))
}
func (c certDo) LeftJoin(table schema.Tabler, on ...field.Expr) *certDo {
return c.withDO(c.DO.LeftJoin(table, on...))
}
func (c certDo) RightJoin(table schema.Tabler, on ...field.Expr) *certDo {
return c.withDO(c.DO.RightJoin(table, on...))
}
func (c certDo) Group(cols ...field.Expr) *certDo {
return c.withDO(c.DO.Group(cols...))
}
func (c certDo) Having(conds ...gen.Condition) *certDo {
return c.withDO(c.DO.Having(conds...))
}
func (c certDo) Limit(limit int) *certDo {
return c.withDO(c.DO.Limit(limit))
}
func (c certDo) Offset(offset int) *certDo {
return c.withDO(c.DO.Offset(offset))
}
func (c certDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *certDo {
return c.withDO(c.DO.Scopes(funcs...))
}
func (c certDo) Unscoped() *certDo {
return c.withDO(c.DO.Unscoped())
}
func (c certDo) Create(values ...*model.Cert) error {
if len(values) == 0 {
return nil
}
return c.DO.Create(values)
}
func (c certDo) CreateInBatches(values []*model.Cert, 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 certDo) Save(values ...*model.Cert) error {
if len(values) == 0 {
return nil
}
return c.DO.Save(values)
}
func (c certDo) First() (*model.Cert, error) {
if result, err := c.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.Cert), nil
}
}
func (c certDo) Take() (*model.Cert, error) {
if result, err := c.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.Cert), nil
}
}
func (c certDo) Last() (*model.Cert, error) {
if result, err := c.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.Cert), nil
}
}
func (c certDo) Find() ([]*model.Cert, error) {
result, err := c.DO.Find()
return result.([]*model.Cert), err
}
func (c certDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Cert, err error) {
buf := make([]*model.Cert, 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 certDo) FindInBatches(result *[]*model.Cert, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return c.DO.FindInBatches(result, batchSize, fc)
}
func (c certDo) Attrs(attrs ...field.AssignExpr) *certDo {
return c.withDO(c.DO.Attrs(attrs...))
}
func (c certDo) Assign(attrs ...field.AssignExpr) *certDo {
return c.withDO(c.DO.Assign(attrs...))
}
func (c certDo) Joins(fields ...field.RelationField) *certDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Joins(_f))
}
return &c
}
func (c certDo) Preload(fields ...field.RelationField) *certDo {
for _, _f := range fields {
c = *c.withDO(c.DO.Preload(_f))
}
return &c
}
func (c certDo) FirstOrInit() (*model.Cert, error) {
if result, err := c.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.Cert), nil
}
}
func (c certDo) FirstOrCreate() (*model.Cert, error) {
if result, err := c.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.Cert), nil
}
}
func (c certDo) FindByPage(offset int, limit int) (result []*model.Cert, 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 certDo) 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 certDo) Scan(result interface{}) (err error) {
return c.DO.Scan(result)
}
func (c certDo) Delete(models ...*model.Cert) (result gen.ResultInfo, err error) {
return c.DO.Delete(models)
}
func (c *certDo) withDO(do gen.Dao) *certDo {
c.DO = *do.(*gen.DO)
return c
}