Skip to content

Commit 24e801a

Browse files
committed
fix: fix README.md, rename to IGNORE_PATTERN and update IgnorePatternDetector
1 parent 211e8d5 commit 24e801a

File tree

7 files changed

+59
-136
lines changed

7 files changed

+59
-136
lines changed

README.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ public class TrustifyExample {
177177

178178
<h3>Excluding Packages</h3>
179179
<p>
180-
Excluding a package from any analysis can be achieved by marking the package for exclusion using either the <code>trustify-da-ignore</code> syntax or the legacy <code>exhortignore</code>.
180+
Excluding a package from any analysis can be achieved by marking the package for exclusion using either the <code>trustify-da-ignore</code> syntax.
181+
182+
Although both `trustify-da-ignore` and `exhortignore` patterns work identically and can be used interchangeably. The `trustify-da-ignore` syntax is recommended for new projects, while `exhortignore` continues to be supported for backwards compatibility. You can gradually migrate your projects or use both patterns in the same manifest.
183+
181184
</p>
182185

183186
<ul>
@@ -220,19 +223,14 @@ Excluding a package from any analysis can be achieved by marking the package for
220223
"mongoose": "^5.9.18"
221224
},
222225
"trustify-da-ignore": [
223-
"mongoose"
224-
],
225-
"exhortignore": [
226226
"jsonwebtoken"
227227
]
228228
}
229229
```
230-
231-
Both arrays can coexist in the same package.json file.
232230
</li>
233231

234232
<li>
235-
<em>Golang</em> users can add comments in <em>go.mod</em>:
233+
<em>Golang</em> users can add in go.mod a comment with //trustify-da-ignore next to the package to be ignored, or to "piggyback" on existing comment ( e.g - //indirect) , for example:
236234

237235
```go
238236
module github.com/RHEcosystemAppEng/SaaSi/deployer
@@ -242,31 +240,31 @@ go 1.19
242240
require (
243241
github.com/gin-gonic/gin v1.9.1
244242
github.com/google/uuid v1.1.2
245-
github.com/jessevdk/go-flags v1.5.0 //exhortignore
246-
github.com/kr/pretty v0.3.1 //trustify-da-ignore
243+
github.com/jessevdk/go-flags v1.5.0 //trustify-da-ignore
244+
github.com/kr/pretty v0.3.1
247245
gopkg.in/yaml.v2 v2.4.0
248246
k8s.io/apimachinery v0.26.1
249247
k8s.io/client-go v0.26.1
250248
)
251249

252250
require (
253-
github.com/davecgh/go-spew v1.1.1 // indirect exhortignore
251+
github.com/davecgh/go-spew v1.1.1 // indirect trustify-da-ignore
254252
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
255253
github.com/go-logr/logr v1.2.3 // indirect trustify-da-ignore
256254
)
257255
```
258256
</li>
259257

260258
<li>
261-
<em>Python pip</em> users can add comments in <em>requirements.txt</em>:
259+
<em>Python pip</em> users can add in requirement text a comment with #trustify-da-ignore(or # trustify-da-ignore) to the right of the same artifact to be ignored, for example:
262260

263261
```properties
264262
anyio==3.6.2
265263
asgiref==3.4.1
266264
beautifulsoup4==4.12.2
267265
certifi==2023.7.22
268266
chardet==4.0.0
269-
click==8.0.4 #exhortignore
267+
click==8.0.4 #trustify-da-ignore
270268
contextlib2==21.6.0
271269
fastapi==0.75.1
272270
Flask==2.0.3
@@ -292,7 +290,8 @@ zipp==3.6.0
292290
</li>
293291

294292
<li>
295-
<em>Gradle</em> users can add comments in <em>build.gradle</em>:
293+
<em>Gradle</em> users can add in build.gradle a comment with //trustify-da-ignore next to the package to be ignored:
294+
```build.gradle
296295
297296
```groovy
298297
plugins {
@@ -307,8 +306,7 @@ repositories {
307306
}
308307
309308
dependencies {
310-
implementation "groupId:artifactId:version" // exhortignore
311-
implementation "anotherGroup:anotherArtifact:version" // trustify-da-ignore
309+
implementation "groupId:artifactId:version" // trustify-da-ignore
312310
}
313311
314312
test {
@@ -319,9 +317,6 @@ test {
319317

320318
</ul>
321319

322-
#### Migration from exhortignore to trustify-da-ignore
323-
Both `exhortignore` and `trustify-da-ignore` patterns work identically and can be used interchangeably. The `trustify-da-ignore` syntax is recommended for new projects, while `exhortignore` continues to be supported for backwards compatibility. You can gradually migrate your projects or use both patterns in the same manifest.
324-
325320
#### Ignore Strategies - experimental
326321

327322
You can specify the method to ignore dependencies in manifest (globally), by setting the environment variable `TRUSTIFY_DA_IGNORE_METHOD` to one of the following values:

src/main/java/io/github/guacsec/trustifyda/providers/JavaMavenProvider.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private List<DependencyAggregator> getDependencies(final Path manifestPath) thro
278278
if (!Objects.isNull(dependencyAggregator)) {
279279
// if we hit an ignore comment, mark aggregator to be ignored
280280
if (reader.getEventType() == XMLStreamConstants.COMMENT
281-
&& IgnorePatternDetector.isIgnoreComment(reader.getText())) {
281+
&& isIgnoreComment(reader.getText())) {
282282
dependencyAggregator.ignored = true;
283283
continue;
284284
}
@@ -492,4 +492,17 @@ public static String normalizePath(String thePath) {
492492
}
493493
return result;
494494
}
495+
496+
/**
497+
* Checks if a comment text exactly matches an ignore pattern. Used for XML comment detection in
498+
* pom.xml files.
499+
*
500+
* @param commentText the comment text to check (will be stripped of whitespace)
501+
* @return true if the comment exactly matches an ignore pattern
502+
*/
503+
private boolean isIgnoreComment(String commentText) {
504+
String stripped = commentText.strip();
505+
return IgnorePatternDetector.IGNORE_PATTERN.equals(stripped)
506+
|| IgnorePatternDetector.LEGACY_IGNORE_PATTERN.equals(stripped);
507+
}
495508
}

src/main/java/io/github/guacsec/trustifyda/providers/PythonPipProvider.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,26 @@ private void handleIgnoredDependencies(String manifestContent, Sbom sbom) {
169169
}
170170
}
171171

172+
/**
173+
* Checks if a text line contains a Python pip ignore pattern. Handles both '#exhortignore' and
174+
* '#trustify-da-ignore' with optional spacing.
175+
*
176+
* @param line the line to check
177+
* @return true if the line contains a Python pip ignore pattern
178+
*/
179+
private boolean containsPythonIgnorePattern(String line) {
180+
return line.contains("#" + IgnorePatternDetector.IGNORE_PATTERN)
181+
|| line.contains("# " + IgnorePatternDetector.IGNORE_PATTERN)
182+
|| line.contains("#" + IgnorePatternDetector.LEGACY_IGNORE_PATTERN)
183+
|| line.contains("# " + IgnorePatternDetector.LEGACY_IGNORE_PATTERN);
184+
}
185+
172186
private Set<PackageURL> getIgnoredDependencies(String requirementsDeps) {
173187

174188
String[] requirementsLines = requirementsDeps.split(System.lineSeparator());
175189
Set<PackageURL> collected =
176190
Arrays.stream(requirementsLines)
177-
.filter(IgnorePatternDetector::containsPythonIgnorePattern)
191+
.filter(this::containsPythonIgnorePattern)
178192
.map(PythonPipProvider::extractDepFull)
179193
.map(this::splitToNameVersion)
180194
.map(dep -> toPurl(dep[0], dep[1]))

src/main/java/io/github/guacsec/trustifyda/providers/javascript/model/Manifest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
21-
import com.fasterxml.jackson.databind.node.ArrayNode;
2221
import com.github.packageurl.PackageURL;
2322
import io.github.guacsec.trustifyda.providers.JavaScriptProvider;
23+
import io.github.guacsec.trustifyda.utils.IgnorePatternDetector;
2424
import java.io.IOException;
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
@@ -68,18 +68,18 @@ private Set<String> loadDependencies(JsonNode content) {
6868
}
6969

7070
private Set<String> loadIgnored(JsonNode content) {
71-
var names = new HashSet<String>();
72-
if (content != null) {
73-
processIgnoreArray(content, "exhortignore", names);
74-
processIgnoreArray(content, "trustify-da-ignore", names);
71+
if (content == null) {
72+
return Collections.emptySet();
7573
}
76-
return names.isEmpty() ? Collections.emptySet() : Collections.unmodifiableSet(names);
77-
}
78-
79-
private void processIgnoreArray(JsonNode content, String key, Set<String> names) {
80-
var ignore = (ArrayNode) content.get(key);
81-
if (ignore != null && !ignore.isEmpty()) {
82-
ignore.forEach(n -> names.add(n.asText()));
74+
var node = content.get(IgnorePatternDetector.IGNORE_PATTERN);
75+
if (node == null || node.isEmpty()) {
76+
node = content.get(IgnorePatternDetector.LEGACY_IGNORE_PATTERN);
77+
}
78+
if (node != null && !node.isEmpty()) {
79+
var names = new HashSet<String>();
80+
node.forEach(n -> names.add(n.asText()));
81+
return Collections.unmodifiableSet(names);
8382
}
83+
return Collections.emptySet();
8484
}
8585
}

src/main/java/io/github/guacsec/trustifyda/utils/IgnorePatternDetector.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class IgnorePatternDetector {
2424

2525
public static final String LEGACY_IGNORE_PATTERN = "exhortignore";
26-
public static final String NEW_IGNORE_PATTERN = "trustify-da-ignore";
26+
public static final String IGNORE_PATTERN = "trustify-da-ignore";
2727

2828
/**
2929
* Checks if a text line contains any ignore pattern (exhortignore or trustify-da-ignore). Used
@@ -33,32 +33,6 @@ public class IgnorePatternDetector {
3333
* @return true if the text contains any ignore pattern
3434
*/
3535
public static boolean containsIgnorePattern(String text) {
36-
return text.contains(LEGACY_IGNORE_PATTERN) || text.contains(NEW_IGNORE_PATTERN);
37-
}
38-
39-
/**
40-
* Checks if a comment text exactly matches an ignore pattern. Used for XML comment detection in
41-
* pom.xml files.
42-
*
43-
* @param commentText the comment text to check (will be stripped of whitespace)
44-
* @return true if the comment exactly matches an ignore pattern
45-
*/
46-
public static boolean isIgnoreComment(String commentText) {
47-
String stripped = commentText.strip();
48-
return LEGACY_IGNORE_PATTERN.equals(stripped) || NEW_IGNORE_PATTERN.equals(stripped);
49-
}
50-
51-
/**
52-
* Checks if a text line contains a Python pip ignore pattern. Handles both '#exhortignore' and
53-
* '#trustify-da-ignore' with optional spacing.
54-
*
55-
* @param line the line to check
56-
* @return true if the line contains a Python pip ignore pattern
57-
*/
58-
public static boolean containsPythonIgnorePattern(String line) {
59-
return line.contains("#" + LEGACY_IGNORE_PATTERN)
60-
|| line.contains("# " + LEGACY_IGNORE_PATTERN)
61-
|| line.contains("#" + NEW_IGNORE_PATTERN)
62-
|| line.contains("# " + NEW_IGNORE_PATTERN);
36+
return text.contains(LEGACY_IGNORE_PATTERN) || text.contains(IGNORE_PATTERN);
6337
}
6438
}

src/test/java/io/github/guacsec/trustifyda/utils/IgnorePatternDetectorTest.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/test/resources/tst_manifests/golang/go_mod_with_all_ignore/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/devfile-samples/devfile-sample-go-basic
33
go 1.19
44

55
require(
6-
github.com/labstack/echo/v4 v4.1.18-0.20201215153152-4422e3b66b9f //exhortignore
7-
github.com/russellhaering/goxmldsig v1.1.0 //exhortignore
8-
github.com/gin-gonic/gin v1.6.0 //exhortignore
6+
github.com/labstack/echo/v4 v4.1.18-0.20201215153152-4422e3b66b9f //trustify-da-ignore
7+
github.com/russellhaering/goxmldsig v1.1.0 //trustify-da-ignore
8+
github.com/gin-gonic/gin v1.6.0 //trustify-da-ignore
99
github.com/miekg/dns v1.0.4-0.20180125103619-43913f2f4fbd //trustify-da-ignore
1010
github.com/ipld/go-car v0.3.0 //trustify-da-ignore
1111
go.elastic.co/apm v1.11.0 //trustify-da-ignore

0 commit comments

Comments
 (0)