Skip to content

Commit 3f2e1eb

Browse files
authored
Filter Scans on Tags (#49)
* Deprecate fileProtocol.group and add ability to filter on tags * Add tags scan documentation example * Update parent version and bump pom minor version * Update copyright to 2021 * Update NOTICE description * Fix flatten config specs with config update
1 parent 99691e1 commit 3f2e1eb

File tree

65 files changed

+174
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+174
-266
lines changed

.test/bad-parent-2.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
file-protocols:
33
- name: Maven Parent
44
description: Maven Parent is correct
5-
group: maven
65
tags:
76
- maven
87
- parent

.test/bad-parent.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
file-protocols:
33
- name: Maven Parent
44
description: Maven Parent is correct
5-
group: maven
65
tags:
76
- maven
87
- parent

.test/glob-example.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
file-protocols:
33
- name: Maven Parent
44
description: Maven Parent is correct
5-
group: maven
65
tags:
76
- maven
87
- parent

.test/override.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
file-protocols:
33
- name: Maven Parent
44
description: Maven Parent is correct
5-
group: maven
65
tags:
76
- maven
87
- parent
@@ -11,7 +10,6 @@ file-protocols:
1110
- enforcer: .maven.MavenParentEquals
1211
expected-coordinates: com.optum.sourcehawk:sourcehawk-jar-parent
1312

14-
1513
# Composable recursive source hawk configs (Must be public repo)
1614
config-locations:
1715
- .test/bad-parent.yml

.test/tags.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
file-protocols:
3+
- name: Maven Parent
4+
description: Maven Parent is correct
5+
tags:
6+
- maven
7+
- parent
8+
repository-path: pom.xml
9+
enforcers:
10+
- enforcer: .maven.MavenParentEquals
11+
expected-coordinates: com.optum.sourcehawk:sourcehawk-jar-parent
12+
- name: Lombok
13+
description: Lombok config is correct
14+
tags:
15+
- config
16+
- lombok
17+
repository-path: lombok.config
18+
enforcers:
19+
- enforcer: .common.StringPropertyEquals
20+
property-name: config.stopBubbling
21+
expected-property-value: false

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
sourcehawk
22

3-
Copyright 2020 Optum
3+
Copyright 2021 Optum
44

55
Project Description:
66
====================
7-
Sourcehawk is a source code compliance as code automation suite of tools.
7+
Sourcehawk is an extensible compliance as code automation tool which enables teams to run tailored compliance scans on their source code.
88

99
Contributors:
1010
@brianwyka - Project Lead

bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>com.optum.sourcehawk</groupId>
1010
<artifactId>sourcehawk</artifactId>
11-
<version>0.5.1-SNAPSHOT</version>
11+
<version>0.6.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<artifactId>sourcehawk-bom</artifactId>

cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<artifactId>sourcehawk</artifactId>
1010
<groupId>com.optum.sourcehawk</groupId>
11-
<version>0.5.1-SNAPSHOT</version>
11+
<version>0.6.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<artifactId>sourcehawk-cli</artifactId>

cli/src/main/asciidoc/_scan-examples.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ sourcehawk scan --config-file-url https://raw.githubsercontent.com/optum/sourceh
2525
sourcehawk scan -f MARKDOWN --fail-on-warnings > sourcehawk-scan-results.md
2626
----
2727

28+
.Scan only the provided tags to limit the scope
29+
[source,sh]
30+
----
31+
sourcehawk scan --tags "config" --tags "build"
32+
----
33+
2834
.Output in JSON format and pretty print with jq
2935
[source,sh]
3036
----

cli/src/main/java/com/optum/sourcehawk/cli/AbstractExecCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ protected ExecOptions buildExecOptions() {
4848
.map(Object::toString)
4949
.ifPresent(builder::configurationFileLocation);
5050
Optional.ofNullable(exec.verbosity).ifPresent(builder::verbosity);
51+
Optional.ofNullable(exec.tags).ifPresent(builder::tags);
5152
Optional.ofNullable(exec.outputFormat).ifPresent(builder::outputFormat);
5253
if (exec.outputFormat == OutputFormat.JSON || exec.outputFormat == OutputFormat.MARKDOWN) {
5354
builder.verbosity(Verbosity.ZERO);
5455
}
55-
builder.failOnWarnings(exec.failOnWarnings);
56-
return builder.build();
56+
return builder.failOnWarnings(exec.failOnWarnings)
57+
.build();
5758
}
5859

5960
/**

cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.net.URL;
1111
import java.nio.file.Path;
12+
import java.util.List;
1213

1314
/**
1415
* Command option definitions
@@ -28,6 +29,12 @@ static class Exec {
2829
@CommandLine.ArgGroup
2930
ConfigFile configFile;
3031

32+
@CommandLine.Option(
33+
names = {"-t", "--tags"},
34+
description = "Tags of file protocols to limit the scope of execution"
35+
)
36+
List<String> tags;
37+
3138
@CommandLine.Option(
3239
names = {"-v", "--verbosity"},
3340
description = "Verbosity of output, valid values: ${COMPLETION-CANDIDATES}",

cli/src/test/groovy/com/optum/sourcehawk/cli/BitbucketScanSubCommandSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BitbucketScanSubCommandSpec extends Specification {
6161
def "commandLine.execute bitbucket server - custom configuration file (failed)"() {
6262
given:
6363
CommandLine commandLine = new CommandLine(new ScanCommand())
64-
String[] args = ["-c", "target/test-classes/sourcehawk-basic2.yml", "bitbucket", "-S", bitbucketServerUrl, "project/repo@develop" ]
64+
String[] args = ["-c", "src/test/resources/sourcehawk-basic2.yml", "bitbucket", "-S", bitbucketServerUrl, "project/repo@develop" ]
6565
clientAndServer
6666
.when(HttpRequest.request()
6767
.withMethod("HEAD")

cli/src/test/groovy/com/optum/sourcehawk/cli/ScanCommandSpec.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class ScanCommandSpec extends CliBaseSpecification {
4141
[ "--config-file", "sourcehawk.yml", repositoryRoot.toString() ] as String[],
4242
[ "-v", "HIGH", repositoryRoot.toString() ] as String[],
4343
[ "--verbosity", "HIGH", repositoryRoot.toString() ] as String[],
44+
[ "-t", "maven", repositoryRoot.toString() ] as String[],
45+
[ "-t", "maven", "-t", "lombok", repositoryRoot.toString() ] as String[],
46+
[ "--tags", "maven", repositoryRoot.toString() ] as String[],
47+
[ "--tags", "maven", "--tags", "lombok", repositoryRoot.toString() ] as String[],
4448
[ "-f", "JSON", repositoryRoot.toString() ] as String[],
4549
[ "--output-format", "JSON", repositoryRoot.toString() ] as String[],
4650
[ "-w", repositoryRoot.toString() ] as String[],
Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
file-protocols:
22
- name: "Maven Pom"
33
description: "maven pom.xml has correct configuration"
4-
group: "maven"
54
repository-path: "pom.xml"
65
required: true
76
tags:
@@ -11,28 +10,8 @@ file-protocols:
1110
- enforcer: ".xml.XPathEquals"
1211
expectations:
1312
//project/ciManagement/system/text(): "github"
14-
- name: "License"
15-
description: null
16-
group: null
17-
repository-path: "LICENSE"
18-
required: true
19-
tags: []
20-
severity: "ERROR"
21-
enforcers: []
22-
- name: "Individual Contributor License"
23-
description: null
24-
group: null
25-
repository-path: "INDIVIDUAL_CONTRIBUTOR_LICENSE.md"
26-
required: true
27-
tags: []
28-
severity: "ERROR"
29-
enforcers:
30-
- enforcer: ".common.ContainsLineMatchingAt"
31-
expected-line-pattern: "(.*)Individual Contributor License Agreement(.*)"
32-
expected-line-number: 1
3313
- name: "Lombok Config"
3414
description: "Lombok Configured appropriately"
35-
group: "lombok"
3615
repository-path: "lombok.config"
3716
required: true
3817
tags:
@@ -48,7 +27,6 @@ file-protocols:
4827
expected-property-value: true
4928
- name: "Notice"
5029
description: null
51-
group: null
5230
repository-path: "NOTICE.txt"
5331
required: true
5432
tags: []
@@ -57,18 +35,15 @@ file-protocols:
5735
- enforcer: ".common.ContainsLineAt"
5836
expected-line: "sourcehawk"
5937
expected-line-number: 1
60-
- enforcer: ".common.ContainsLineAt"
61-
expected-line: "Copyright 2020 Optum"
38+
- enforcer: ".common.ContainsLineMatchingAt"
39+
expected-line-pattern: "Copyright (.*) Optum"
6240
expected-line-number: 3
63-
- enforcer: ".common.ContainsLine"
64-
expected-line: "Project Description:"
6541
- enforcer: ".common.ContainsLine"
6642
expected-line: "@brianwyka - Project Lead"
6743
- enforcer: ".common.ContainsLine"
6844
expected-line: "@ctoestriech - Project Lead"
6945
- name: "Maven Wrapper"
7046
description: "Maven build wrapper"
71-
group: "lombok"
7247
repository-path: ".mvn/wrapper/maven-wrapper.properties"
7348
required: true
7449
tags:
@@ -79,35 +54,3 @@ file-protocols:
7954
- enforcer: ".common.StringPropertyEquals"
8055
property-name: "distributionUrl"
8156
expected-property-value: "https://apache.claz.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip"
82-
- name: "Code of Conduct"
83-
description: null
84-
group: null
85-
repository-path: "CODE_OF_CONDUCT.md"
86-
required: true
87-
tags: []
88-
severity: "ERROR"
89-
enforcers:
90-
- enforcer: ".common.ContainsLine"
91-
expected-line: "# Contributor Covenant Code of Conduct"
92-
- enforcer: ".common.ContainsLine"
93-
expected-line: "[homepage]: http://contributor-covenant.org"
94-
- enforcer: ".common.ContainsLine"
95-
expected-line: "[email]: mailto:[email protected]"
96-
- name: "Attribution"
97-
description: null
98-
group: null
99-
repository-path: "attribution.txt"
100-
required: true
101-
tags: []
102-
severity: "ERROR"
103-
enforcers: []
104-
- name: "Contributing"
105-
description: null
106-
group: null
107-
repository-path: "CONTRIBUTING.md"
108-
required: true
109-
tags: []
110-
severity: "ERROR"
111-
enforcers:
112-
- enforcer: ".common.ContainsLine"
113-
expected-line: "[email]: mailto:[email protected]"
Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
file-protocols:
22
- name: "Maven Banned Deps"
33
description: "Maven pom.xml banned deps check"
4-
group: "maven"
54
repository-path: "pom.xml"
65
required: true
76
tags:
@@ -14,7 +13,6 @@ file-protocols:
1413
special.skip: true
1514
- name: "Maven Pom"
1615
description: "maven pom.xml has correct configuration"
17-
group: "maven"
1816
repository-path: "pom.xml"
1917
required: true
2018
tags:
@@ -24,28 +22,8 @@ file-protocols:
2422
- enforcer: ".xml.XPathEquals"
2523
expectations:
2624
//project/ciManagement/type/text(): "ghe"
27-
- name: "License"
28-
description: null
29-
group: null
30-
repository-path: "LICENSE"
31-
required: true
32-
tags: []
33-
severity: "ERROR"
34-
enforcers: []
35-
- name: "Individual Contributor License"
36-
description: null
37-
group: null
38-
repository-path: "INDIVIDUAL_CONTRIBUTOR_LICENSE.md"
39-
required: true
40-
tags: []
41-
severity: "ERROR"
42-
enforcers:
43-
- enforcer: ".common.ContainsLineMatchingAt"
44-
expected-line-pattern: "(.*)Individual Contributor License Agreement(.*)"
45-
expected-line-number: 1
4625
- name: "Lombok Config"
4726
description: "Lombok Configured appropriately"
48-
group: "lombok"
4927
repository-path: "lombok.config"
5028
required: true
5129
tags:
@@ -61,7 +39,6 @@ file-protocols:
6139
expected-property-value: false
6240
- name: "Notice"
6341
description: null
64-
group: null
6542
repository-path: "NOTICE.txt"
6643
required: true
6744
tags: []
@@ -70,26 +47,22 @@ file-protocols:
7047
- enforcer: ".common.ContainsLineAt"
7148
expected-line: "sourcehawk"
7249
expected-line-number: 1
73-
- enforcer: ".common.ContainsLineAt"
74-
expected-line: "Copyright 2020 Optum"
50+
- enforcer: ".common.ContainsLineMatchingAt"
51+
expected-line-pattern: "Copyright (.*) Optum"
7552
expected-line-number: 3
76-
- enforcer: ".common.ContainsLine"
77-
expected-line: "Project Description:"
7853
- enforcer: ".common.ContainsLine"
7954
expected-line: "@brianwyka - Project Lead"
8055
- enforcer: ".common.ContainsLine"
8156
expected-line: "@ctoestriech - Project Lead"
8257
- name: "Maven Wrapper"
8358
description: "Maven Wrapper exists"
84-
group: null
8559
repository-path: ".mvn/wrapper/maven-wrapper.jar"
8660
required: true
8761
tags: []
8862
severity: "ERROR"
8963
enforcers: []
9064
- name: "Maven Wrapper"
9165
description: "Maven build wrapper"
92-
group: "lombok"
9366
repository-path: ".mvn/wrapper/maven-wrapper.properties"
9467
required: true
9568
tags:
@@ -100,35 +73,3 @@ file-protocols:
10073
- enforcer: ".common.StringPropertyEquals"
10174
property-name: "distributionUrl"
10275
expected-property-value: "https://apache.claz.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip"
103-
- name: "Code of Conduct"
104-
description: null
105-
group: null
106-
repository-path: "CODE_OF_CONDUCT.md"
107-
required: true
108-
tags: []
109-
severity: "ERROR"
110-
enforcers:
111-
- enforcer: ".common.ContainsLine"
112-
expected-line: "# Contributor Covenant Code of Conduct"
113-
- enforcer: ".common.ContainsLine"
114-
expected-line: "[homepage]: http://contributor-covenant.org"
115-
- enforcer: ".common.ContainsLine"
116-
expected-line: "[email]: mailto:[email protected]"
117-
- name: "Attribution"
118-
description: null
119-
group: null
120-
repository-path: "attribution.txt"
121-
required: true
122-
tags: []
123-
severity: "ERROR"
124-
enforcers: []
125-
- name: "Contributing"
126-
description: null
127-
group: null
128-
repository-path: "CONTRIBUTING.md"
129-
required: true
130-
tags: []
131-
severity: "ERROR"
132-
enforcers:
133-
- enforcer: ".common.ContainsLine"
134-
expected-line: "[email]: mailto:[email protected]"

cli/src/test/resources/repo-updates/sourcehawk.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
file-protocols:
33
- name: Lombok Config Override
44
description: Lombok Configured appropriately
5-
group: lombok
65
tags:
76
- lombok
87
- config

0 commit comments

Comments
 (0)