Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add code snip to filecontent #253

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@
title: Golang
extras: []
effort: 3
filecontent-codesnip-test:
description: ""
category: potential
incidents:
- uri: file:///analyzer-lsp/examples/customers-tomcat-legacy/Dockerfile
message: Found usage of openjdk base image
codeSnip: " 1 ########################################\n 2 # Build Image\n 3 ########################################\n 4 # FROM maven:3.6-jdk-8-slim as build\n 5 FROM maven:3.8-openjdk-11 as build\n 6 \n 7 WORKDIR /app\n 8 \n 9 # Establish the dependency layer\n10 COPY pom.xml .\n11 RUN mvn dependency:resolve\n12 \n13 # Add the source code and package\n14 COPY src ./src\n15 RUN mvn package\n16 "
lineNumber: 5
variables:
matchingText: FROM maven:3.8-openjdk-11 as build
extras: []
go-lang-ref-001:
description: ""
category: potential
Expand Down
4 changes: 4 additions & 0 deletions provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (p *builtintServiceClient) Evaluate(cap string, conditionInfo []byte) (prov
Variables: map[string]interface{}{
"matchingText": pieces[2],
},
CodeLocation: &provider.Location{
StartPosition: provider.Position{Line: float64(lineNumber)},
EndPosition: provider.Position{Line: float64(lineNumber)},
},
})
}
if len(response.Incidents) != 0 {
Expand Down
6 changes: 6 additions & 0 deletions rule-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,10 @@
when:
builtin.hasTags:
- Golang
- message: "Found usage of openjdk base image"
ruleID: filecontent-codesnip-test
when:
builtin.filecontent:
pattern: "^FROM.*openjdk-11.*"
filePattern: "Dockerfile"