validation

package
v1.21.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

BuiltInGroupUUIDs contains the UUIDs of all built-in groups that cannot be deleted or renamed

View Source
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

func IsBuiltInGroup(groupUUID string) bool

IsBuiltInGroup returns true if the given UUID belongs to a built-in group

func ValidateAssetType

func ValidateAssetType(assetType string) error

ValidateAssetType validates the asset type field

func ValidateDiagramType

func ValidateDiagramType(diagramType string) error

ValidateDiagramType validates the diagram type field

func ValidateEntityType

func ValidateEntityType(entityType string) error

ValidateEntityType validates the metadata entity type field

func ValidateEnum

func ValidateEnum(field, value string, allowed []string) error

ValidateEnum checks if a value is in an allowed list (case-insensitive).

func ValidateEnumPtr

func ValidateEnumPtr(field string, value *string, allowed []string) error

ValidateEnumPtr validates an optional enum field

func ValidateLength

func ValidateLength(field, value string, minLen, maxLen int) error

ValidateLength checks string length constraints

func ValidateMetadataKey

func ValidateMetadataKey(key string) error

ValidateMetadataKey validates a metadata key

func ValidateMetadataValue

func ValidateMetadataValue(value string) error

ValidateMetadataValue validates a metadata value

func ValidateNonEmpty

func ValidateNonEmpty(field, value string) error

ValidateNonEmpty checks that a string is not empty after trimming

func ValidateNotEveryoneGroup

func ValidateNotEveryoneGroup(groupUUID string) error

ValidateNotEveryoneGroup checks that operations don't target the protected "everyone" group

func ValidateNotEveryoneGroupMember

func ValidateNotEveryoneGroupMember(groupUUID string) error

ValidateNotEveryoneGroupMember checks that members aren't added to "everyone" group

func ValidateRepositoryType

func ValidateRepositoryType(repoType string) error

ValidateRepositoryType validates the repository type field

func ValidateRole

func ValidateRole(role string) error

ValidateRole validates the access role field

func ValidateScore

func ValidateScore(score *float64) error

ValidateScore validates a threat score (0.0 to 10.0)

func ValidateStatusLength

func ValidateStatusLength(status *string) error

ValidateStatusLength validates optional status field length (max 128)

func ValidateSubjectType

func ValidateSubjectType(subjectType string) error

ValidateSubjectType validates the subject type field

func ValidateSubjectXOR

func ValidateSubjectXOR(subjectType string, userUUID, groupUUID *string) error

ValidateSubjectXOR validates the XOR constraint for subject_type/user_internal_uuid/group_internal_uuid Used by ThreatModelAccess and Administrator models

func ValidateThreatModelFramework

func ValidateThreatModelFramework(framework string) error

ValidateThreatModelFramework validates the threat model framework field

func ValidateURI

func ValidateURI(field, uri string) error

ValidateURI validates that a URI is not empty

func ValidateWebSocketURL

func ValidateWebSocketURL(url string) error

ValidateWebSocketURL validates that a WebSocket URL is not empty

func ValidateWebhookDeliveryStatus

func ValidateWebhookDeliveryStatus(status string) error

ValidateWebhookDeliveryStatus validates the webhook delivery status field

func ValidateWebhookPatternType

func ValidateWebhookPatternType(patternType string) error

ValidateWebhookPatternType validates the webhook URL deny list pattern type

func ValidateWebhookStatus

func ValidateWebhookStatus(status string) error

ValidateWebhookStatus validates the webhook subscription status field

Types

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL