
- 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
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.secnex.io/secnex/certman/utils"
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
|
|
Username string `json:"username" gorm:"not null;unique"`
|
|
Email string `json:"email" gorm:"not null;unique"`
|
|
Password string `json:"password" gorm:"not null"`
|
|
ExternalID *string `json:"external_id" gorm:"unique"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
|
|
OrganizationsCreated []*Organization `json:"organizations_created" gorm:"foreignKey:CreatedBy"`
|
|
OrganizationsUpdated []*Organization `json:"organizations_updated" gorm:"foreignKey:UpdatedBy"`
|
|
|
|
// Members of organizations
|
|
Organizations []*Organization `json:"organizations" gorm:"many2many:organization_members;"`
|
|
}
|
|
|
|
func (u *User) TableName() string {
|
|
return "users"
|
|
}
|
|
|
|
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
|
|
u.ID = uuid.New()
|
|
u.Password, err = utils.HashPassword(u.Password, utils.DefaultParams)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return
|
|
}
|