This commit is contained in:
Lizandro Guarnizo
2026-05-12 10:29:00 -05:00
parent f1d73ae63b
commit 40131e7266
3 changed files with 204 additions and 35 deletions
+15 -5
View File
@@ -5,16 +5,24 @@ import (
"gorm.io/gorm"
)
// CloudflareConfig almacena el API Token de Cloudflare.
// CloudflareConfig almacena las credenciales de Cloudflare.
// Solo un registro puede estar activo a la vez.
//
// AuthType puede ser:
// - "token" → API Token (recomendado, 40 chars, Bearer auth)
// - "global_key" → Global API Key (legacy, X-Auth-Email + X-Auth-Key)
type CloudflareConfig struct {
gorm.Model
// API Token (recomendado) se usa como Bearer token
APIToken string `json:"api_token" gorm:"column:api_token;type:text;not null"`
// Tipo de autenticación: "token" (defecto) o "global_key"
AuthType string `json:"auth_type" gorm:"column:auth_type;type:varchar(20);default:'token'"`
// API Token (AuthType=token) o Global API Key (AuthType=global_key)
APIToken string `json:"api_token" gorm:"column:api_token;type:text;not null"`
// Email de la cuenta (requerido solo para AuthType=global_key)
Email string `json:"email" gorm:"column:email;type:text"`
// Account ID principal (opcional, para endpoints de cuenta)
AccountID string `json:"account_id" gorm:"column:account_id;type:text"`
Activo bool `json:"activo" gorm:"column:activo;default:true"`
Nota string `json:"nota" gorm:"column:nota;type:text"`
Activo bool `json:"activo" gorm:"column:activo;default:true"`
Nota string `json:"nota" gorm:"column:nota;type:text"`
}
func (CloudflareConfig) TableName() string { return "cloudflare_config" }
@@ -35,7 +43,9 @@ func SaveCloudflareConfig(s CloudflareConfig) error {
s.Activo = true
if s.ID > 0 {
return app.Http.Database.DB.Model(&s).Updates(map[string]interface{}{
"auth_type": s.AuthType,
"api_token": s.APIToken,
"email": s.Email,
"account_id": s.AccountID,
"nota": s.Nota,
"activo": true,