validation

package
v0.0.0-...-548cdc5 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 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

Functions

func IsBuiltInGroup

func IsBuiltInGroup(groupUUID string) bool

IsBuiltInGroup returns true if the given UUID belongs to a built-in group SEM@3d0d5a8cf02fa74fad102f0f99c2b936a164bbea: check whether a group UUID belongs to a built-in system group (pure)

func ValidateAssetType

func ValidateAssetType(assetType string) error

ValidateAssetType validates the asset type field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate an asset type value against allowed asset types (pure)

func ValidateDiagramType

func ValidateDiagramType(diagramType string) error

ValidateDiagramType validates the diagram type field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a diagram type value against allowed diagram types (pure)

func ValidateEntityType

func ValidateEntityType(entityType string) error

ValidateEntityType validates the metadata entity type field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a metadata entity type value against allowed entity types (pure)

func ValidateEnum

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

ValidateEnum checks if a value is in an allowed list (case-insensitive). SEM@034968fa0e0ba8c15e9af9052b475f4d5dd72d50: validate that a string value belongs to an allowed enum list, case-insensitively (pure)

func ValidateEnumPtr

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

ValidateEnumPtr validates an optional enum field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate an optional enum field, passing nil values (pure)

func ValidateLength

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

ValidateLength checks string length constraints SEM@7cd4e086ca351285b214de56af06e83e3a2a8807: validate that a string field falls within minimum and maximum length bounds (pure)

func ValidateMetadataKey

func ValidateMetadataKey(key string) error

ValidateMetadataKey validates a metadata key SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a metadata key for non-empty, length, and alphanumeric-plus-hyphen pattern (pure)

func ValidateMetadataValue

func ValidateMetadataValue(value string) error

ValidateMetadataValue validates a metadata value SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a metadata value for non-empty and maximum 65535-character length (pure)

func ValidateNonEmpty

func ValidateNonEmpty(field, value string) error

ValidateNonEmpty checks that a string is not empty after trimming SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate that a string field is non-empty after trimming whitespace (pure)

func ValidateNotEveryoneGroup

func ValidateNotEveryoneGroup(groupUUID string) error

ValidateNotEveryoneGroup checks that operations don't target the protected "everyone" group SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: reject operations targeting the protected everyone pseudo-group (pure)

func ValidateNotEveryoneGroupMember

func ValidateNotEveryoneGroupMember(groupUUID string) error

ValidateNotEveryoneGroupMember checks that members aren't added to "everyone" group SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: reject adding members to the protected everyone pseudo-group (pure)

func ValidateRepositoryType

func ValidateRepositoryType(repoType string) error

ValidateRepositoryType validates the repository type field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a repository type value against allowed repository types (pure)

func ValidateRole

func ValidateRole(role string) error

ValidateRole validates the access role field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate an access role value against allowed roles (pure)

func ValidateScore

func ValidateScore(score *float64) error

ValidateScore validates a threat score (0.0 to 10.0) SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate an optional threat score is within the 0.0-10.0 range (pure)

func ValidateStatusLength

func ValidateStatusLength(status *string) error

ValidateStatusLength validates optional status field length (max 128) SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate an optional status field does not exceed 128 characters (pure)

func ValidateSubjectType

func ValidateSubjectType(subjectType string) error

ValidateSubjectType validates the subject type field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a subject type value against allowed subject types (pure)

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 SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate that exactly one of user or group UUID is set consistent with subject type (pure)

func ValidateThreatModelFramework

func ValidateThreatModelFramework(framework string) error

ValidateThreatModelFramework validates the threat model framework field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a threat model framework value against allowed frameworks (pure)

func ValidateURI

func ValidateURI(field, uri string) error

ValidateURI validates that a URI is not empty SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate that a URI field is non-empty after trimming (pure)

func ValidateWebSocketURL

func ValidateWebSocketURL(url string) error

ValidateWebSocketURL validates that a WebSocket URL is not empty SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate that a WebSocket URL is non-empty after trimming (pure)

func ValidateWebhookDeliveryStatus

func ValidateWebhookDeliveryStatus(status string) error

ValidateWebhookDeliveryStatus validates the webhook delivery status field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a webhook delivery status value against allowed delivery statuses (pure)

func ValidateWebhookPatternType

func ValidateWebhookPatternType(patternType string) error

ValidateWebhookPatternType validates the webhook URL deny list pattern type SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a webhook URL deny-list pattern type against allowed pattern types (pure)

func ValidateWebhookStatus

func ValidateWebhookStatus(status string) error

ValidateWebhookStatus validates the webhook subscription status field SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: validate a webhook subscription status value against allowed statuses (pure)

Types

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation failure SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: structured validation error carrying field name and message (pure)

func NewValidationError

func NewValidationError(field, message string) *ValidationError

NewValidationError creates a new validation error SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: build a ValidationError for a named field with a given message (pure)

func (*ValidationError) Error

func (e *ValidationError) Error() string

SEM@acf29174839ed9f1cb1950265092e2bdacdcb5bd: format the validation error as a field-prefixed message string (pure)

Jump to

Keyboard shortcuts

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