Skip to content

Commit fedd3fb

Browse files
SONARTEXT-14 Create generator to generate Java classes for every rule (#162)
1 parent 00a2f10 commit fedd3fb

10 files changed

+482
-36
lines changed

sonar-text-plugin/src/main/java/org/sonar/plugins/secrets/SecretsRulesDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static List<Class<?>> checks() {
5151
return List.of(
5252
AlibabaCloudAccessKeyCheck.class,
5353
AwsCheck.class,
54-
CommonKeyCheck.class,
5554
AzureStorageAccountKeyCheck.class,
55+
CommonKeyCheck.class,
5656
GoogleApiKeyCheck.class,
5757
GoogleCloudAccountKeyCheck.class,
5858
IbmApiKeyCheck.class,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SonarQube Text Plugin
3+
* Copyright (C) 2021-2023 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.plugins.secrets;
21+
22+
import java.util.Set;
23+
24+
public class SecretsSpecificationFilesDefinition {
25+
26+
private SecretsSpecificationFilesDefinition() {
27+
28+
}
29+
30+
public static Set<String> existingSecretSpecifications() {
31+
return Set.of(
32+
"alibaba.yaml",
33+
"aws.yaml",
34+
"azure.yaml",
35+
"clarifai.yaml",
36+
"django.yaml",
37+
"facebook.yaml",
38+
"gcp.yaml",
39+
"github.yaml",
40+
"gitlab.yaml",
41+
"google-api.yaml",
42+
"google-oauth2.yaml",
43+
"google-recaptcha.yaml",
44+
"ibm.yaml",
45+
"mongodb.yaml",
46+
"mws.yaml",
47+
"mysql.yaml",
48+
"odbc.yaml",
49+
"openweathermap.yaml",
50+
"postgresql.yaml",
51+
"pubkey-crypto.yaml",
52+
"rapidapi.yaml",
53+
"riot.yaml",
54+
"sendgrid.yaml",
55+
"sonarqube.yaml",
56+
"spotify.yaml",
57+
"ssh.yaml",
58+
"telegram.yaml",
59+
"wechat.yaml");
60+
}
61+
}

sonar-text-plugin/src/main/java/org/sonar/plugins/secrets/api/SpecificationLoader.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434
import org.sonar.plugins.secrets.configuration.model.Specification;
3535
import org.sonar.plugins.secrets.configuration.validation.SchemaValidationException;
3636

37+
import static org.sonar.plugins.secrets.SecretsSpecificationFilesDefinition.existingSecretSpecifications;
38+
3739
public class SpecificationLoader {
3840
private static final Logger LOG = Loggers.get(SpecificationLoader.class);
3941

4042
public static final String DEFAULT_SPECIFICATION_LOCATION = "org/sonar/plugins/secrets/configuration/";
4143
private final Map<String, List<Rule>> rulesMappedToKey;
4244

4345
public SpecificationLoader() {
44-
this(DEFAULT_SPECIFICATION_LOCATION, defaultSpecifications());
46+
this(DEFAULT_SPECIFICATION_LOCATION, existingSecretSpecifications());
4547
}
4648

4749
public SpecificationLoader(String specificationLocation, Set<String> specifications) {
@@ -77,39 +79,7 @@ public List<Rule> getRulesForKey(String key) {
7779
return rulesMappedToKey.getOrDefault(key, new ArrayList<>());
7880
}
7981

80-
Map<String, List<Rule>> getRulesMappedToKey() {
82+
public Map<String, List<Rule>> getRulesMappedToKey() {
8183
return rulesMappedToKey;
8284
}
83-
84-
public static Set<String> defaultSpecifications() {
85-
return Set.of(
86-
"alibaba.yaml",
87-
"aws.yaml",
88-
"azure.yaml",
89-
"clarifai.yaml",
90-
"django.yaml",
91-
"facebook.yaml",
92-
"gcp.yaml",
93-
"github.yaml",
94-
"gitlab.yaml",
95-
"google-api.yaml",
96-
"google-oauth2.yaml",
97-
"google-recaptcha.yaml",
98-
"ibm.yaml",
99-
"mongodb.yaml",
100-
"mws.yaml",
101-
"mysql.yaml",
102-
"odbc.yaml",
103-
"openweathermap.yaml",
104-
"postgresql.yaml",
105-
"pubkey-crypto.yaml",
106-
"rapidapi.yaml",
107-
"riot.yaml",
108-
"sendgrid.yaml",
109-
"sonarqube.yaml",
110-
"spotify.yaml",
111-
"ssh.yaml",
112-
"telegram.yaml",
113-
"wechat.yaml");
114-
}
11585
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SonarQube Text Plugin
3+
* Copyright (C) 2021-2023 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.plugins.secrets;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
class SecretsSpecificationFilesDefinitionTest {
27+
28+
@Test
29+
void e() {
30+
assertThat(SecretsSpecificationFilesDefinition.existingSecretSpecifications()).hasSizeGreaterThanOrEqualTo(28);
31+
}
32+
}

sonar-text-plugin/src/test/java/org/sonar/plugins/secrets/api/SpecificationLoaderTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ void shouldLoadRulesWithoutErrors() {
4343
Map<String, List<Rule>> rulesMappedToKey = specificationLoader.getRulesMappedToKey();
4444

4545
assertThat(rulesMappedToKey.values()).hasSize(SecretsRulesDefinition.checks().size());
46-
assertThat(rulesMappedToKey.values().stream().flatMap(Collection::stream)).hasSize(67);
4746
assertThat(logTester.getLogs()).isEmpty();
4847
}
4948

0 commit comments

Comments
 (0)