feat: add comprehensive database models and type definitions
- Define Certificate model with full X.509 attributes - Add CertificateAuthority model for CA management - Implement CertificateRequest model for CSR handling - Add CertificateRevocationList model for CRL support - Define User and Organization models for access control - Include comprehensive certificate type definitions (web, client, email, etc.) - Add status enums for certificates, requests, and organizations - Configure GORM relationships and constraints
This commit is contained in:
57
models/cert.go
Normal file
57
models/cert.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Certificate represents a digital certificate
|
||||
type Certificate struct {
|
||||
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
|
||||
Name string `json:"name" gorm:"not null"`
|
||||
Description string `json:"description"`
|
||||
SerialNumber string `json:"serial_number" gorm:"not null;unique"`
|
||||
AttributeCommonName string `json:"attribute_common_name" gorm:"not null"`
|
||||
AttributeSubjectAlternativeName string `json:"attribute_subject_alternative_name"` // JSON array of SANs
|
||||
AttributeOrganization string `json:"attribute_organization" gorm:"not null"`
|
||||
AttributeOrganizationUnit string `json:"attribute_organization_unit" gorm:"not null"`
|
||||
AttributeCountry string `json:"attribute_country" gorm:"not null"`
|
||||
AttributeState string `json:"attribute_state" gorm:"not null"`
|
||||
AttributeLocality string `json:"attribute_locality" gorm:"not null"`
|
||||
AttributeStreet string `json:"attribute_street" gorm:"not null"`
|
||||
AttributeEmail string `json:"attribute_email" gorm:"not null"`
|
||||
AttributeAddress string `json:"attribute_address" gorm:"not null"`
|
||||
AttributePostalCode string `json:"attribute_postal_code" gorm:"not null"`
|
||||
AttributeNotBefore time.Time `json:"attribute_not_before" gorm:"not null"`
|
||||
AttributeNotAfter time.Time `json:"attribute_not_after" gorm:"not null"`
|
||||
Type CertificateType `json:"type" gorm:"not null"`
|
||||
Status CertificateStatus `json:"status" gorm:"not null;default:'pending'"`
|
||||
CertificateAuthorityID uuid.UUID `json:"ca_id" gorm:"type:uuid;not null"`
|
||||
RequestID *uuid.UUID `json:"request_id" gorm:"type:uuid"`
|
||||
FileID string `json:"file_id" gorm:"not null"`
|
||||
PrivateKeyID string `json:"private_key_id" gorm:"not null"`
|
||||
Generated bool `json:"generated" gorm:"not null;default:false"`
|
||||
GeneratedAt *time.Time `json:"generated_at"`
|
||||
RevocationReason string `json:"revocation_reason"`
|
||||
RevokedAt *time.Time `json:"revoked_at"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
|
||||
// Relationships
|
||||
CertificateAuthority *CertificateAuthority `json:"certificate_authority" gorm:"foreignKey:CertificateAuthorityID"`
|
||||
Request *CertificateRequest `json:"request" gorm:"foreignKey:RequestID"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for Certificate
|
||||
func (c *Certificate) TableName() string {
|
||||
return "certificates"
|
||||
}
|
||||
|
||||
// BeforeCreate generates a new UUID before creating the record
|
||||
func (c *Certificate) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
c.ID = uuid.New()
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user