Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Classification ¶
type Classification struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Priority int `yaml:"priority"`
Patterns []Pattern `yaml:"patterns"`
CompiledPatterns []*regexp.Regexp `yaml:"-"`
}
Classification represents a high-level category of data sensitivity (e.g., "Secret", "PII").
It contains metadata about the category and a collection of specific regex patterns used to identify data belonging to this category.
type ConfidenceLevel ¶
type ConfidenceLevel string
ConfidenceLevel represents the degree of certainty that a matched pattern indicates a specific data classification.
Allowed values are "low", "medium", and "high".
const ( Low ConfidenceLevel = "low" Medium ConfidenceLevel = "medium" High ConfidenceLevel = "high" )
func (*ConfidenceLevel) UnmarshalYAML ¶
func (c *ConfidenceLevel) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface for ConfidenceLevel.
It validates that the confidence level string provided in the YAML config matches one of the allowed constants (low, medium, high), returning an error if invalid.
type Pattern ¶
type Pattern struct {
Id string `yaml:"id"`
Description string `yaml:"description"`
Regex string `yaml:"regex"`
Confidence ConfidenceLevel `yaml:"confidence"`
// contains filtered or unexported fields
}
Pattern defines a specific rule for identifying sensitive data within a Classification.
type PolicyEngine ¶
type PolicyEngine struct {
Classifiers []Classification
}
PolicyEngine serves as the main entry point for data classification operations. It holds the state of the loaded rules and provides methods to scan data against those rules.
func NewPolicyEngine ¶
func NewPolicyEngine() (*PolicyEngine, error)
NewPolicyEngine initializes a new instance of the PolicyEngine.
Unlike previous versions, this function takes no arguments. It automatically loads the policy definitions embedded in the binary via the enforcement package.
It performs the following operations: 1. Unmarshals the embedded YAML data. 2. Compiles all regex patterns. 3. Sorts classifications by priority.
Returns an error if the embedded YAML is malformed or contains invalid regex.
func (*PolicyEngine) ClassifyData ¶
func (e *PolicyEngine) ClassifyData(data []byte) string
ClassifyData performs a quick boolean check on a byte slice to determine its classification.
It iterates through classifications by priority and returns the name of the *first* classification that matches the data. If no match is found, it returns "public".
This is optimized for high-throughput categorization rather than detailed auditing.
func (*PolicyEngine) ScanFileContent ¶
func (e *PolicyEngine) ScanFileContent(content string) []ScanFinding
ScanFileContent performs a comprehensive audit of a string.
It splits the content into lines and checks every line against every pattern in the engine. It captures specific details about every match found, including line numbers and the specific text that triggered the match.
This function is intended for the ingestion pipeline where detailed feedback is required.
type PolicyEngineClassificationFile ¶
type PolicyEngineClassificationFile struct {
ClassificationPatterns []Classification `yaml:"classifications"`
}
PolicyEngineClassificationFile represents the root structure of the YAML policy configuration. It maps directly to the top-level "classifications" key in the data_classification_patterns.yaml file.
func (*PolicyEngineClassificationFile) CompileRegexes ¶
func (p *PolicyEngineClassificationFile) CompileRegexes() error
CompileRegexes iterates through every pattern in the configuration and pre-compiles the regex strings into optimized *regexp.Regexp objects.
This method must be called before any scanning occurs to ensure performance and to validate that all regex strings in the YAML are syntactically correct.
func (*PolicyEngineClassificationFile) SortByPriority ¶
func (p *PolicyEngineClassificationFile) SortByPriority()
SortByPriority reorders the internal ClassificationPatterns slice based on the Priority field, in descending order (highest priority first).
This ensures that when multiple rules might match the same data, the most sensitive classification is applied.
type ScanFinding ¶
type ScanFinding struct {
FilePath string `json:"file_path"`
LineNumber int `json:"line_number"`
MatchedContent string `json:"matched_content"`
ClassificationName string `json:"classification_name"`
PatternId string `json:"pattern_id"`
PatternDescription string `json:"pattern_description"`
Confidence ConfidenceLevel `json:"confidence"`
ReviewTimestamp int64 `json:"review_timestamp"`
UserDecision string `json:"user_decision"`
Reviewer string `json:"reviewer"`
}
ScanFinding represents a specific instance of a policy violation or data match found within a file.