Documentation
¶
Overview ¶
Package ast provides Abstract Syntax Tree analysis capabilities for extracting structural information from source code files. It supports multiple programming languages and identifies code constructs, risk zones, and contextual information that helps improve the accuracy of PI detection.
Index ¶
- type AnalysisResult
- type Analyzer
- func (a *Analyzer) AnalyzeFile(ctx context.Context, filePath string, content []byte) (*AnalysisResult, error)
- func (a *Analyzer) AnalyzeRepository(ctx context.Context, rootPath string, files []discovery.FileResult) (*RepositoryStructure, error)
- func (a *Analyzer) DetermineRiskLevel(filePath string) RiskLevel
- func (a *Analyzer) DetermineRiskZone(filePath string) string
- type Annotation
- type BankingComplianceInfo
- type BankingDomainConfig
- type ClassInfo
- type CodeStructure
- type ComplianceFinding
- type Config
- type Dependency
- type DependencyEdge
- type DependencyGraph
- type DependencyNode
- type FileContext
- type Language
- type MethodInfo
- type RepositoryAnalysis
- type RepositoryAnalyzer
- type RepositoryStructure
- type RiskLevel
- type RiskZoneInfo
- type SecurityHint
- type VariableInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
Language Language `json:"language"`
FilePath string `json:"file_path"`
RiskLevel RiskLevel `json:"risk_level"`
RiskZone string `json:"risk_zone"`
CodeStructure *CodeStructure `json:"code_structure"`
SecurityHints []SecurityHint `json:"security_hints"`
Dependencies []Dependency `json:"dependencies"`
AnalysisTime int64 `json:"analysis_time_ms"`
Error string `json:"error,omitempty"`
}
AnalysisResult contains the results of AST analysis
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer provides AST-based code analysis capabilities
func NewAnalyzer ¶
NewAnalyzer creates a new AST analyzer
func (*Analyzer) AnalyzeFile ¶
func (a *Analyzer) AnalyzeFile(ctx context.Context, filePath string, content []byte) (*AnalysisResult, error)
AnalyzeFile performs AST analysis on a single file
func (*Analyzer) AnalyzeRepository ¶
func (a *Analyzer) AnalyzeRepository(ctx context.Context, rootPath string, files []discovery.FileResult) (*RepositoryStructure, error)
AnalyzeRepository performs repository-wide AST analysis
func (*Analyzer) DetermineRiskLevel ¶
DetermineRiskLevel determines the risk level based on file path patterns
func (*Analyzer) DetermineRiskZone ¶
DetermineRiskZone categorizes the file into a risk zone
type Annotation ¶
type Annotation struct {
Name string `json:"name"`
Parameters map[string]string `json:"parameters,omitempty"`
LineNumber int `json:"line_number"`
}
Annotation represents code annotations/decorators
type BankingComplianceInfo ¶
type BankingComplianceInfo struct {
DataModelFiles []string `json:"data_model_files"`
CustomerDataFiles []string `json:"customer_data_files"`
PaymentProcessingFiles []string `json:"payment_processing_files"`
AuthenticationFiles []string `json:"authentication_files"`
ComplianceFindings []ComplianceFinding `json:"compliance_findings"`
RiskScore float64 `json:"risk_score"`
RecommendedActions []string `json:"recommended_actions"`
}
BankingComplianceInfo contains banking domain specific compliance information
type BankingDomainConfig ¶
type BankingDomainConfig struct {
HighRiskPatterns []string `json:"high_risk_patterns"`
MediumRiskPatterns []string `json:"medium_risk_patterns"`
LowRiskPatterns []string `json:"low_risk_patterns"`
ExcludePatterns []string `json:"exclude_patterns"`
RiskZones map[string]RiskLevel `json:"risk_zones"`
}
BankingDomainConfig contains banking-specific analysis rules
func DefaultBankingDomainConfig ¶
func DefaultBankingDomainConfig() *BankingDomainConfig
DefaultBankingDomainConfig returns default banking domain configuration
type ClassInfo ¶
type ClassInfo struct {
Name string `json:"name"`
Package string `json:"package"`
LineNumber int `json:"line_number"`
IsPublic bool `json:"is_public"`
Extends string `json:"extends,omitempty"`
Implements []string `json:"implements,omitempty"`
Annotations []string `json:"annotations,omitempty"`
}
ClassInfo represents information about a class
type CodeStructure ¶
type CodeStructure struct {
Classes []ClassInfo `json:"classes"`
Methods []MethodInfo `json:"methods"`
Variables []VariableInfo `json:"variables"`
Annotations []Annotation `json:"annotations"`
Imports []string `json:"imports"`
}
CodeStructure represents the structural analysis of code
type ComplianceFinding ¶
type ComplianceFinding struct {
Type string `json:"type"`
Severity string `json:"severity"`
Description string `json:"description"`
FilePath string `json:"file_path"`
LineNumber int `json:"line_number"`
Regulation string `json:"regulation"` // GDPR, CCPA, PCI-DSS, etc.
}
ComplianceFinding represents a banking compliance finding
type Config ¶
type Config struct {
EnabledLanguages []Language `json:"enabled_languages"`
BankingDomainRules *BankingDomainConfig `json:"banking_domain_rules"`
MaxFileSize int64 `json:"max_file_size"`
ConcurrentAnalysis int `json:"concurrent_analysis"`
CacheEnabled bool `json:"cache_enabled"`
}
Config contains configuration for AST analysis
func DefaultBankingConfig ¶
func DefaultBankingConfig() *Config
DefaultBankingConfig returns the default configuration for banking domain analysis
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default AST analysis configuration
type Dependency ¶
type Dependency struct {
Name string `json:"name"`
Type string `json:"type"` // import, inheritance, composition
Target string `json:"target"`
Package string `json:"package,omitempty"`
}
Dependency represents a code dependency
type DependencyEdge ¶
type DependencyEdge struct {
From string `json:"from"`
To string `json:"to"`
Type string `json:"type"` // import, inheritance, composition
Weight int `json:"weight"`
}
DependencyEdge represents an edge in the dependency graph
type DependencyGraph ¶
type DependencyGraph struct {
Nodes []DependencyNode `json:"nodes"`
Edges []DependencyEdge `json:"edges"`
}
DependencyGraph represents the dependency structure of the repository
type DependencyNode ¶
type DependencyNode struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // class, package, module
FilePath string `json:"file_path"`
RiskLevel RiskLevel `json:"risk_level"`
Connections int `json:"connections"`
}
DependencyNode represents a node in the dependency graph
type FileContext ¶
type FileContext struct {
FilePath string
Language Language
RiskLevel RiskLevel
RiskZone string
IsTestFile bool
IsConfigFile bool
CodeStructure *CodeStructure
Imports []string
Classes []string
Methods []string
}
FileContext contains AST-derived context for a specific file
type MethodInfo ¶
type MethodInfo struct {
Name string `json:"name"`
Class string `json:"class"`
LineNumber int `json:"line_number"`
IsPublic bool `json:"is_public"`
Parameters []string `json:"parameters"`
ReturnType string `json:"return_type"`
Annotations []string `json:"annotations,omitempty"`
}
MethodInfo represents information about a method
type RepositoryAnalysis ¶
type RepositoryAnalysis struct {
RepositoryPath string `json:"repository_path"`
AnalysisTime time.Time `json:"analysis_time"`
Duration time.Duration `json:"duration"`
TotalFiles int `json:"total_files"`
AnalyzedFiles int `json:"analyzed_files"`
SkippedFiles int `json:"skipped_files"`
LanguageStats map[Language]int `json:"language_stats"`
RiskZoneStats map[string]int `json:"risk_zone_stats"`
RiskLevelStats map[RiskLevel]int `json:"risk_level_stats"`
SecurityHints []SecurityHint `json:"security_hints"`
DependencyGraph *DependencyGraph `json:"dependency_graph"`
RiskZones []RiskZoneInfo `json:"risk_zones"`
BankingCompliance *BankingComplianceInfo `json:"banking_compliance"`
FileAnalyses []*AnalysisResult `json:"file_analyses"`
}
RepositoryAnalysis contains the results of repository structure analysis
type RepositoryAnalyzer ¶
type RepositoryAnalyzer struct {
// contains filtered or unexported fields
}
RepositoryAnalyzer performs repository-level analysis
func NewRepositoryAnalyzer ¶
func NewRepositoryAnalyzer(config *Config) *RepositoryAnalyzer
NewRepositoryAnalyzer creates a new repository analyzer
func (*RepositoryAnalyzer) AnalyzeRepository ¶
func (ra *RepositoryAnalyzer) AnalyzeRepository(ctx context.Context, repositoryPath string, filePaths []string) (*RepositoryAnalysis, error)
AnalyzeRepository performs comprehensive repository analysis
type RepositoryStructure ¶
type RepositoryStructure struct {
RootPath string
PrimaryLanguage string
Languages map[Language]int // Count of files per language
HighRiskZones map[string][]string // Zone name -> file paths
FileContexts map[string]*FileContext
Dependencies map[string][]string // Package dependencies
// contains filtered or unexported fields
}
RepositoryStructure represents the analyzed structure of a repository
func (*RepositoryStructure) GetFileContext ¶
func (rs *RepositoryStructure) GetFileContext(filePath string) *FileContext
GetFileContext returns the context for a specific file
func (*RepositoryStructure) IsTestFile ¶
func (rs *RepositoryStructure) IsTestFile(filePath string) bool
IsTestFile checks if a file is a test file based on repository analysis
type RiskZoneInfo ¶
type RiskZoneInfo struct {
Zone string `json:"zone"`
RiskLevel RiskLevel `json:"risk_level"`
FileCount int `json:"file_count"`
Description string `json:"description"`
FilePaths []string `json:"file_paths"`
SecurityHints int `json:"security_hints"`
}
RiskZoneInfo provides detailed information about risk zones