Documentation
¶
Overview ¶
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.
Index ¶
- func ExtractLineFragment(line, substr string, key bool) string
- func GenerateSubstrings(ctx context.Context, key string, extracted [][]string, lines []string, ...) (string, string)
- func GetAdjacentVulnLines(idx, adj int, lines []string) *[]model.CodeLine
- func GetBracketValues(expr string, list [][]string, restOfString string) [][]string
- func GetLineBySearchLine(pathComponents []string, file *model.FileMetadata) (int, error)
- func SelectLineWithMinimumDistance(distances map[int]int, startingFrom int) int
- type DefaultDetectLineResponse
- type DetectLine
- func (d *DetectLine) Add(detector kindDetectLine, kind model.FileKind) *DetectLine
- func (d *DetectLine) DetectLine(ctx context.Context, file *model.FileMetadata, searchKey string) model.VulnerabilityLines
- func (d *DetectLine) DetectLineByPath(ctx context.Context, file *model.FileMetadata, path []string) model.VulnerabilityLines
- func (d *DetectLine) SetupLogs(logger *zerolog.Logger)
- type PathResolution
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLineFragment ¶
ExtractLineFragment will prepare substr for line detection
func GenerateSubstrings ¶
func GenerateSubstrings(ctx context.Context, key string, extracted [][]string, lines []string, currentLine int) (string, string)
GenerateSubstrings returns the substrings used for line searching depending on search key '.' is new line '=' is value in the same line '[]' is in the same line nolint:gocritic
func GetAdjacentVulnLines ¶
GetAdjacentVulnLines is used to get the lines adjacent to the line that contains the vulnerability adj is the amount of lines wanted
func GetBracketValues ¶
GetBracketValues gets values inside "{{ }}" ignoring any "{{" or "}}" inside
func GetLineBySearchLine ¶
func GetLineBySearchLine(pathComponents []string, file *model.FileMetadata) (int, error)
GetLineBySearchLine resolves the source line of a value identified by a structured path (a slice of keys and array indices) against the line metadata embedded in the parsed document.
The line metadata is JSON-normalised once here (parsers may store it as typed *model.LineObject maps or as generic maps) and then walked by lineFromPath, which understands every enabled platform's shape and applies deepest-match back-off. Returns 0 when no line can be resolved; callers treat any value <= 0 as a miss.
Types ¶
type DefaultDetectLineResponse ¶
type DefaultDetectLineResponse struct {
CurrentLine int
IsBreak bool
FoundAtLeastOne bool
ResolvedFile string
ResolvedFiles map[string]model.ResolvedFileSplit
}
DefaultDetectLineResponse is the default response for struct DetectLine
func (*DefaultDetectLineResponse) DetectCurrentLine ¶
func (d *DefaultDetectLineResponse) DetectCurrentLine(str1, str2 string, recurseCount int, lines []string, kind model.FileKind) (*DefaultDetectLineResponse, model.ResourceLine, model.ResourceLine, []string)
DetectCurrentLine uses levenshtein distance to find the most accurate line for the vulnerability nolint:gocritic
type DetectLine ¶
type DetectLine struct {
// contains filtered or unexported fields
}
DetectLine is a struct that associates a kindDetectLine to its FileKind
func NewDetectLine ¶
func NewDetectLine(outputLines int) *DetectLine
NewDetectLine creates a new DetectLine's reference
func (*DetectLine) Add ¶
func (d *DetectLine) Add(detector kindDetectLine, kind model.FileKind) *DetectLine
Add adds a new kindDetectLine to the caller and returns it
func (*DetectLine) DetectLine ¶
func (d *DetectLine) DetectLine(ctx context.Context, file *model.FileMetadata, searchKey string) model.VulnerabilityLines
DetectLine will use the correct kindDetectLine according to the files kind if file kind is not in detectors default detect line is called
func (*DetectLine) DetectLineByPath ¶
func (d *DetectLine) DetectLineByPath(ctx context.Context, file *model.FileMetadata, path []string) model.VulnerabilityLines
DetectLineByPath resolves a finding's line from a structured attribute path (built by the resource index from a resource's base path plus the rule's relative attribute path) using the line metadata recorded at parse time.
A single call to GetLineBySearchLine walks as deep along the path as possible and returns the deepest line found (back-off is intrinsic). If the file's kind detector also implements kindEnrichLine (currently Terraform), the plain line is augmented with the enclosing block, remediation and source locations so that migrated rules produce the same rich output as the legacy searchKey path.
func (*DetectLine) SetupLogs ¶
func (d *DetectLine) SetupLogs(logger *zerolog.Logger)
SetupLogs will change the logger feild to be used in kindDetectLine DetectLine method
type PathResolution ¶
type PathResolution struct {
Line int
MatchedElements int // path components consumed before the walk stopped
TotalElements int // total input path length
StructuralExact bool // true when all components were found in the tree
MetadataExact bool // true when the exact node carried its own line metadata
}
PathResolution captures the structured outcome of resolving a path against embedded line metadata. It allows callers to distinguish exact resolution from best-effort fallback without changing the return type of lineFromPath.
func ResolvePathWithStatus ¶
func ResolvePathWithStatus(root map[string]interface{}, path []string) PathResolution
ResolvePathWithStatus resolves path against the root document metadata and returns a PathResolution with full provenance. It delegates to lineFromPath and derives the status fields from the returned residuals.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |