Scanner
π€ AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.testkit.quality.security.scanner
¶
Security vulnerability scanner implementation.
This module provides a high-level security scanning interface using bandit. The scanner can be configured with various verbosity levels to control output noise and is designed for integration with CI/CD pipelines.
Usage
Basic usage with default settings: >>> scanner = SecurityScanner() >>> result = scanner.analyze(Path("./src"))
With custom verbosity (quiet mode for CI): >>> scanner = SecurityScanner(config={'verbosity': 'quiet'}) >>> result = scanner.analyze(Path("./src"))
With custom thresholds: >>> config = { ... 'max_high_severity': 0, ... 'max_medium_severity': 5, ... 'min_score': 80.0, ... 'verbosity': 'normal' ... } >>> scanner = SecurityScanner(config) >>> result = scanner.analyze(Path("./src"))
Verbosity Levels
- 'quiet': Only show errors (best for CI/CD)
- 'normal': Show errors and warnings (default)
- 'verbose': Show all messages including debug info
Score Calculation
The security score starts at 100 and deducts points based on issue severity: - High severity: -10 points per issue - Medium severity: -5 points per issue - Low severity: -1 point per issue
The score is capped at 0 (cannot go negative).
Classes¶
SecurityScanner
¶
Security vulnerability scanner using bandit and other tools.
Provides high-level interface for security analysis with automatic artifact management and integration with the quality framework.
Configuration
max_high_severity: Maximum allowed high severity issues (default: 0) max_medium_severity: Maximum allowed medium severity issues (default: 5) min_score: Minimum security score to pass (default: 80.0) verbosity: Output verbosity ('quiet', 'normal', 'verbose') exclude: List of file patterns to exclude from scanning
Initialize security scanner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Security scanner configuration options |
None
|
Raises:
| Type | Description |
|---|---|
QualityToolError
|
If bandit is not available |
Source code in provide/testkit/quality/security/scanner.py
Functions¶
analyze
¶
Run security analysis on the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to analyze |
required |
**kwargs
|
Any
|
Additional options: - artifact_dir: Directory for output artifacts - verbosity: Override scanner's verbosity level |
{}
|
Returns:
| Type | Description |
|---|---|
QualityResult
|
QualityResult with security analysis data |
Source code in provide/testkit/quality/security/scanner.py
report
¶
Generate report from QualityResult (implements QualityTool protocol).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
QualityResult
|
Security result |
required |
format
|
str
|
Report format |
'terminal'
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted report |