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:
58
models/organization.go
Normal file
58
models/organization.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.secnex.io/secnex/certman/utils"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Organization struct {
|
||||
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
|
||||
Name string `json:"name" gorm:"not null;unique"`
|
||||
Description string `json:"description"`
|
||||
Address string `json:"address"`
|
||||
City string `json:"city" gorm:"not null"`
|
||||
State string `json:"state"`
|
||||
Country string `json:"country" gorm:"not null"`
|
||||
PostalCode string `json:"postal_code"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email" gorm:"not null;unique"`
|
||||
Website string `json:"website" gorm:"not null;unique"`
|
||||
Logo string `json:"logo"`
|
||||
Status OrganizationStatus `json:"status" gorm:"not null;default:'active'"`
|
||||
CreatedBy uuid.UUID `json:"created_by" gorm:"type:uuid;not null"`
|
||||
UpdatedBy uuid.UUID `json:"updated_by" gorm:"type:uuid;not null"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
|
||||
CertificateAuthorities []*CertificateAuthority `gorm:"foreignKey:OrganizationID"`
|
||||
|
||||
UserCreatedBy User `gorm:"foreignKey:CreatedBy"`
|
||||
UserUpdatedBy User `gorm:"foreignKey:UpdatedBy"`
|
||||
|
||||
// Members of organizations
|
||||
Members []*User `gorm:"many2many:organization_members;"`
|
||||
}
|
||||
|
||||
func (o *Organization) TableName() string {
|
||||
return "organizations"
|
||||
}
|
||||
|
||||
func (o *Organization) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
o.ID = uuid.New()
|
||||
// Check if the email address matches the email regex and the domain is the same as the website
|
||||
if !utils.IsEmailValid(o.Email) {
|
||||
return fmt.Errorf("invalid email address")
|
||||
}
|
||||
if !utils.IsDomainValid(o.Website) {
|
||||
return fmt.Errorf("invalid website domain")
|
||||
}
|
||||
if !utils.IsEmailDomainValid(o.Email, o.Website) {
|
||||
return fmt.Errorf("email and website domains do not match")
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user