Files
certman/models/csr.go
Björn Benouarets e8f4bca221 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
2025-09-30 11:44:10 +02:00

51 lines
2.4 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// CertificateRequest represents a request for a certificate (CSR)
type CertificateRequest struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
CommonName string `json:"common_name" gorm:"not null"`
SubjectAlternativeName string `json:"subject_alternative_name"` // JSON array of SANs
Type CertificateType `json:"type" gorm:"not null"`
Status RequestStatus `json:"status" gorm:"not null;default:'pending'"`
CertificateAuthorityID uuid.UUID `json:"certificate_authority_id" gorm:"type:uuid;not null"`
RequesterName string `json:"requester_name" gorm:"not null"`
RequesterEmail string `json:"requester_email" gorm:"not null"`
RequesterPhone string `json:"requester_phone"`
Organization string `json:"organization"`
Department string `json:"department"`
City string `json:"city"`
State string `json:"state"`
Country string `json:"country"`
CSRFilePath string `json:"csr_file_path"` // Path to CSR file
CSRData []byte `json:"csr_data" gorm:"type:bytea"` // CSR data in DER format
ValidDays int `json:"valid_days" gorm:"not null;default:365"`
ApprovedBy *uuid.UUID `json:"approved_by" gorm:"type:uuid"`
ApprovedAt *time.Time `json:"approved_at"`
RejectionReason string `json:"rejection_reason"`
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"`
Certificates []*Certificate `json:"certificates" gorm:"foreignKey:RequestID"`
}
// TableName returns the table name for CertificateRequest
func (cr *CertificateRequest) TableName() string {
return "certificate_requests"
}
// BeforeCreate generates a new UUID before creating the record
func (cr *CertificateRequest) BeforeCreate(tx *gorm.DB) (err error) {
cr.ID = uuid.New()
return
}