Documentation
¶
Overview ¶
Package validation provides cross-database validation for TMI models. These validators replace PostgreSQL CHECK constraints to enable consistent validation across all supported databases.
Index ¶
- Variables
- func IsBuiltInGroup(groupUUID string) bool
- func ValidateAssetType(assetType string) error
- func ValidateDiagramType(diagramType string) error
- func ValidateEntityType(entityType string) error
- func ValidateEnum(field, value string, allowed []string) error
- func ValidateEnumPtr(field string, value *string, allowed []string) error
- func ValidateLength(field, value string, minLen, maxLen int) error
- func ValidateMetadataKey(key string) error
- func ValidateMetadataValue(value string) error
- func ValidateNonEmpty(field, value string) error
- func ValidateNotEveryoneGroup(groupUUID string) error
- func ValidateNotEveryoneGroupMember(groupUUID string) error
- func ValidateRepositoryType(repoType string) error
- func ValidateRole(role string) error
- func ValidateScore(score *float64) error
- func ValidateStatusLength(status *string) error
- func ValidateSubjectType(subjectType string) error
- func ValidateSubjectXOR(subjectType string, userUUID, groupUUID *string) error
- func ValidateThreatModelFramework(framework string) error
- func ValidateURI(field, uri string) error
- func ValidateWebSocketURL(url string) error
- func ValidateWebhookDeliveryStatus(status string) error
- func ValidateWebhookPatternType(patternType string) error
- func ValidateWebhookStatus(status string) error
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ValidThreatModelFrameworks are the allowed threat modeling frameworks ValidThreatModelFrameworks = []string{"CIA", "STRIDE", "LINDDUN", "DIE", "PLOT4ai"} // ValidDiagramTypes are the allowed diagram types ValidDiagramTypes = []string{"DFD-1.0.0"} // ValidAssetTypes are the allowed asset types ValidAssetTypes = []string{"data", "hardware", "software", "infrastructure", "service", "personnel"} // ValidRepositoryTypes are the allowed repository types ValidRepositoryTypes = []string{"git", "svn", "mercurial", "other"} // ValidRoles are the allowed access roles ValidRoles = []string{"owner", "writer", "reader"} // ValidSubjectTypes are the allowed subject types for access control ValidSubjectTypes = []string{"user", "group"} // ValidWebhookStatuses are the allowed webhook subscription statuses ValidWebhookStatuses = []string{"pending_verification", "active", "pending_delete"} // ValidWebhookDeliveryStatuses are the allowed webhook delivery statuses ValidWebhookDeliveryStatuses = []string{"pending", "delivered", "failed"} // ValidWebhookPatternTypes are the allowed webhook URL deny list pattern types ValidWebhookPatternTypes = []string{"glob", "regex"} // ValidEntityTypes are the allowed metadata entity types ValidEntityTypes = []string{"threat_model", "threat", "diagram", "document", "repository", "cell", "note", "asset", "survey", "survey_response", "team", "project"} // EveryonePseudoGroupUUID is the reserved UUID for the "everyone" pseudo-group EveryonePseudoGroupUUID = "00000000-0000-0000-0000-000000000000" // SecurityReviewersGroupUUID is the well-known UUID for the Security Reviewers group. SecurityReviewersGroupUUID = "00000000-0000-0000-0000-000000000001" // AdministratorsGroupUUID is the well-known UUID for the Administrators built-in group. AdministratorsGroupUUID = "00000000-0000-0000-0000-000000000002" // ConfidentialProjectReviewersGroupUUID is the well-known UUID for the Confidential Project Reviewers group. ConfidentialProjectReviewersGroupUUID = "00000000-0000-0000-0000-000000000003" // TMIAutomationGroupUUID is the well-known UUID for the TMI Automation built-in group. TMIAutomationGroupUUID = "00000000-0000-0000-0000-000000000004" // EmbeddingAutomationGroupUUID is the well-known UUID for the Embedding Automation built-in group. EmbeddingAutomationGroupUUID = "00000000-0000-0000-0000-000000000005" )
Valid enum values for various fields
var BuiltInGroupUUIDs = []string{ EveryonePseudoGroupUUID, SecurityReviewersGroupUUID, AdministratorsGroupUUID, ConfidentialProjectReviewersGroupUUID, TMIAutomationGroupUUID, EmbeddingAutomationGroupUUID, }
BuiltInGroupUUIDs contains the UUIDs of all built-in groups that cannot be deleted or renamed
var ( // MetadataKeyPattern is the single metadata key rule; it must match the // OpenAPI Metadata.key pattern. Length (1-256) is checked separately. MetadataKeyPattern = regexp.MustCompile(`^[a-zA-Z0-9_./:-]+$`) )
Regex patterns for validation
Functions ¶
func IsBuiltInGroup ¶
IsBuiltInGroup returns true if the given UUID belongs to a built-in group
func ValidateAssetType ¶
ValidateAssetType validates the asset type field
func ValidateDiagramType ¶
ValidateDiagramType validates the diagram type field
func ValidateEntityType ¶
ValidateEntityType validates the metadata entity type field
func ValidateEnum ¶
ValidateEnum checks if a value is in an allowed list (case-insensitive).
func ValidateEnumPtr ¶
ValidateEnumPtr validates an optional enum field
func ValidateLength ¶
ValidateLength checks string length constraints
func ValidateMetadataKey ¶
ValidateMetadataKey validates a metadata key
func ValidateMetadataValue ¶
ValidateMetadataValue validates a metadata value
func ValidateNonEmpty ¶
ValidateNonEmpty checks that a string is not empty after trimming
func ValidateNotEveryoneGroup ¶
ValidateNotEveryoneGroup checks that operations don't target the protected "everyone" group
func ValidateNotEveryoneGroupMember ¶
ValidateNotEveryoneGroupMember checks that members aren't added to "everyone" group
func ValidateRepositoryType ¶
ValidateRepositoryType validates the repository type field
func ValidateRole ¶
ValidateRole validates the access role field
func ValidateScore ¶
ValidateScore validates a threat score (0.0 to 10.0)
func ValidateStatusLength ¶
ValidateStatusLength validates optional status field length (max 128)
func ValidateSubjectType ¶
ValidateSubjectType validates the subject type field
func ValidateSubjectXOR ¶
ValidateSubjectXOR validates the XOR constraint for subject_type/user_internal_uuid/group_internal_uuid Used by ThreatModelAccess and Administrator models
func ValidateThreatModelFramework ¶
ValidateThreatModelFramework validates the threat model framework field
func ValidateURI ¶
ValidateURI validates that a URI is not empty
func ValidateWebSocketURL ¶
ValidateWebSocketURL validates that a WebSocket URL is not empty
func ValidateWebhookDeliveryStatus ¶
ValidateWebhookDeliveryStatus validates the webhook delivery status field
func ValidateWebhookPatternType ¶
ValidateWebhookPatternType validates the webhook URL deny list pattern type
func ValidateWebhookStatus ¶
ValidateWebhookStatus validates the webhook subscription status field
Types ¶
type ValidationError ¶
ValidationError represents a validation failure
func NewValidationError ¶
func NewValidationError(field, message string) *ValidationError
NewValidationError creates a new validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string