Skip to content

Commit 260554d

Browse files
authored
Support disable/enable Code Quality Scan (#204)
* Support disable/enable Code Quality Scan * Support disable/enable Code Quality Scan (signed)
1 parent 2d8132b commit 260554d

7 files changed

Lines changed: 75 additions & 50 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/properties/PreferencesPage.java

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
2020

2121
public class PreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
22-
private BooleanFieldEditor snykCodeSecurityCheckbox;
22+
private BooleanFieldEditor snykCodeSecurityCheckbox, snykCodeQualityCheckbox;
2323

2424
public PreferencesPage() {
2525
super(GRID);
@@ -34,69 +34,81 @@ public void init(IWorkbench workbench) {
3434
@Override
3535
protected void createFieldEditors() {
3636
TokenFieldEditor tokenField = new TokenFieldEditor(Preferences.getInstance(), Preferences.AUTH_TOKEN_KEY,
37-
"Token:", getFieldEditorParent());
37+
"Token:", getFieldEditorParent());
3838

39-
addField(new BooleanFieldEditor(Preferences.USE_TOKEN_AUTH, "Use token authentication. It is recommended to keep this turned off, as the default OAuth2 authentication is more secure.",
39+
addField(new BooleanFieldEditor(Preferences.USE_TOKEN_AUTH,
40+
"Use token authentication. It is recommended to keep this turned off, as the default OAuth2 authentication is more secure.",
4041
getFieldEditorParent()));
4142

4243
addField(tokenField);
4344
addField(new StringFieldEditor(Preferences.PATH_KEY, "Path:", 80, getFieldEditorParent()));
4445
addField(new StringFieldEditor(Preferences.ENDPOINT_KEY, "Custom Endpoint:", 80, getFieldEditorParent()));
45-
addField(new BooleanFieldEditor(Preferences.INSECURE_KEY, "Allow unknown certificate authorities",
46-
getFieldEditorParent()));
46+
addField(new BooleanFieldEditor(Preferences.INSECURE_KEY, "Allow unknown certificate authorities",
47+
getFieldEditorParent()));
4748

4849
addField(space());
49-
addField(new LabelFieldEditor("The following options involve the Snyk Language Server.", getFieldEditorParent()));
50+
addField(new LabelFieldEditor("The following options involve the Snyk Language Server.",
51+
getFieldEditorParent()));
5052
addField(new LabelFieldEditor(
51-
"Activating Snyk Code will cause upload of source code to Snyk or the given endpoint address.",
52-
getFieldEditorParent()));
53+
"Activating Snyk Code will cause upload of source code to Snyk or the given endpoint address.",
54+
getFieldEditorParent()));
5355
addField(space());
5456
addField(new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "Snyk Open Source enabled",
55-
getFieldEditorParent()));
56-
snykCodeSecurityCheckbox = new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_CODE, "Snyk Code enabled",
57-
getFieldEditorParent());
58-
57+
getFieldEditorParent()));
58+
snykCodeSecurityCheckbox = new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "Snyk Code Security enabled",
59+
getFieldEditorParent());
5960
addField(snykCodeSecurityCheckbox);
61+
snykCodeQualityCheckbox = new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_CODE_QUALITY, "Snyk Code Quality enabled",
62+
getFieldEditorParent());
63+
addField(snykCodeQualityCheckbox);
6064

6165
addField(new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_IAC, "Snyk Infrastructure-as-Code enabled",
62-
getFieldEditorParent()));
66+
getFieldEditorParent()));
6367

6468
addField(space());
65-
addField(new BooleanFieldEditor(Preferences.SCANNING_MODE_AUTOMATIC, "Scan automatically on start-up and save", getFieldEditorParent()));
69+
addField(new BooleanFieldEditor(Preferences.SCANNING_MODE_AUTOMATIC, "Scan automatically on start-up and save",
70+
getFieldEditorParent()));
6671
addField(space());
6772
addField(new LabelFieldEditor("Advanced options:", getFieldEditorParent()));
6873
addField(new StringFieldEditor(Preferences.ORGANIZATION_KEY, "Organization:", 80, getFieldEditorParent()));
6974
addField(
70-
new StringFieldEditor(Preferences.ADDITIONAL_PARAMETERS, "Additional Parameters:", 80, getFieldEditorParent()));
75+
new StringFieldEditor(Preferences.ADDITIONAL_PARAMETERS, "Additional Parameters:", 80,
76+
getFieldEditorParent()));
7177
addField(
72-
new StringFieldEditor(Preferences.ADDITIONAL_ENVIRONMENT, "Additional Environment:", 80, getFieldEditorParent()));
78+
new StringFieldEditor(Preferences.ADDITIONAL_ENVIRONMENT, "Additional Environment:", 80,
79+
getFieldEditorParent()));
7380

7481
addField(space());
7582
BooleanFieldEditor manageBinaries = new BooleanFieldEditor(Preferences.MANAGE_BINARIES_AUTOMATICALLY,
76-
"Update and install Snyk binaries automatically", getFieldEditorParent());
83+
"Update and install Snyk binaries automatically", getFieldEditorParent());
7784
manageBinaries.setPropertyChangeListener((PropertyChangeEvent propertyChangeEvent) -> {
7885
System.out.println("managed bionaries changed");
7986
});
8087
addField(manageBinaries);
81-
addField(new StringFieldEditor(Preferences.CLI_BASE_URL, "Base URL for CLI download:", 80, getFieldEditorParent()));
82-
addField(new FileFieldEditor(Preferences.CLI_PATH, "Snyk CLI (incl. Language Server):", getFieldEditorParent()));
88+
addField(new StringFieldEditor(Preferences.CLI_BASE_URL, "Base URL for CLI download:", 80,
89+
getFieldEditorParent()));
90+
addField(
91+
new FileFieldEditor(Preferences.CLI_PATH, "Snyk CLI (incl. Language Server):", getFieldEditorParent()));
8392

8493
addField(space());
8594

8695
addField(
87-
new BooleanFieldEditor(Preferences.SEND_ERROR_REPORTS, "Send error reports to Snyk", getFieldEditorParent()));
96+
new BooleanFieldEditor(Preferences.SEND_ERROR_REPORTS, "Send error reports to Snyk",
97+
getFieldEditorParent()));
8898
addField(
89-
new BooleanFieldEditor(Preferences.ENABLE_TELEMETRY, "Send usage statistics to Snyk", getFieldEditorParent()));
99+
new BooleanFieldEditor(Preferences.ENABLE_TELEMETRY, "Send usage statistics to Snyk",
100+
getFieldEditorParent()));
90101

91102
addField(space());
92103

93104
addField(new LabelFieldEditor(
94-
"Only trusted paths are scanned by Snyk. The Trusted Folders setting allows to specify, which \n"
95-
+ "paths are safe to scan. Every path below a given path is considered safe to scan. \n"
96-
+ "Please separate entries with \"" + File.pathSeparator + "\".",
97-
getFieldEditorParent()));
98-
StringFieldEditor trustedFoldersEditor = new StringFieldEditor(Preferences.TRUSTED_FOLDERS, "Trusted Folders:", 80, getFieldEditorParent());
99-
addField(trustedFoldersEditor);
105+
"Only trusted paths are scanned by Snyk. The Trusted Folders setting allows to specify, which \n"
106+
+ "paths are safe to scan. Every path below a given path is considered safe to scan. \n"
107+
+ "Please separate entries with \"" + File.pathSeparator + "\".",
108+
getFieldEditorParent()));
109+
StringFieldEditor trustedFoldersEditor = new StringFieldEditor(Preferences.TRUSTED_FOLDERS, "Trusted Folders:",
110+
80, getFieldEditorParent());
111+
addField(trustedFoldersEditor);
100112
disableSnykCodeIfOrgDisabled();
101113
}
102114

@@ -131,13 +143,14 @@ public void run() {
131143
boolean showMessage = false;
132144
boolean checkBoxValue;
133145
try {
134-
checkBoxValue = snykCodeSecurityCheckbox != null && snykCodeSecurityCheckbox.getBooleanValue();
146+
checkBoxValue = snykCodeSecurityCheckbox != null && snykCodeSecurityCheckbox.getBooleanValue();
135147
} catch (NullPointerException e) {
136-
// this can happen, if the UI checkbox is not initialized fully, we return then
137-
return;
148+
// this can happen, if the UI checkbox is not initialized fully, we return then
149+
return;
138150
}
139151
if (checkBoxValue && !isSastEnabled) {
140-
snykCodeSecurityCheckbox.setLabelText(snykCodeSecurityCheckbox.getLabelText() + " (" + message + ")");
152+
snykCodeSecurityCheckbox
153+
.setLabelText(snykCodeSecurityCheckbox.getLabelText() + " (" + message + ")");
141154
showMessage = true;
142155
}
143156

plugin/src/main/java/io/snyk/eclipse/plugin/properties/preferences/Preferences.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
3535
public static final String INSECURE_KEY = "insecure";
3636
public static final String CLI_PATH = "cli-path";
3737
public static final String CLI_BASE_URL = "cli-base-url";
38-
public static final String ACTIVATE_SNYK_CODE = "ACTIVATE_SNYK_CODE";
38+
public static final String ACTIVATE_SNYK_CODE_SECURITY = "ACTIVATE_SNYK_CODE_SECURITY";
39+
public static final String ACTIVATE_SNYK_CODE_QUALITY = "ACTIVATE_SNYK_CODE_QUALITY";
3940
public static final String ACTIVATE_SNYK_OPEN_SOURCE = "ACTIVATE_SNYK_OPEN_SOURCE";
4041
public static final String ACTIVATE_SNYK_IAC = "ACTIVATE_SNYK_IAC";
4142
public static final String ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS";
@@ -55,8 +56,11 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
5556

5657
Preferences(PreferenceStore store) {
5758
this.store = store;
58-
if (getPref(ACTIVATE_SNYK_CODE) == null) {
59-
store(ACTIVATE_SNYK_CODE, "false");
59+
if (getPref(ACTIVATE_SNYK_CODE_SECURITY) == null) {
60+
store(ACTIVATE_SNYK_CODE_SECURITY, "false");
61+
}
62+
if (getPref(ACTIVATE_SNYK_CODE_QUALITY) == null) {
63+
store(ACTIVATE_SNYK_CODE_QUALITY, "false");
6064
}
6165
if (getPref(ACTIVATE_SNYK_OPEN_SOURCE) == null) {
6266
store(ACTIVATE_SNYK_OPEN_SOURCE, "true");

plugin/src/main/java/io/snyk/languageserver/LsConfigurationUpdater.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public void configurationChanged() {
2727
Settings getCurrentSettings() {
2828
Preferences preferences = Preferences.getInstance();
2929
String activateSnykOpenSource = preferences.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, Boolean.TRUE.toString());
30-
String activateSnykCode = preferences.getPref(Preferences.ACTIVATE_SNYK_CODE, Boolean.FALSE.toString());
30+
String activateSnykCodeSecurity = preferences.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY, Boolean.FALSE.toString());
31+
String activateSnykCodeQuality = preferences.getPref(Preferences.ACTIVATE_SNYK_CODE_QUALITY, Boolean.FALSE.toString());
3132
String activateSnykIac = preferences.getPref(Preferences.ACTIVATE_SNYK_IAC, Boolean.TRUE.toString());
3233
String insecure = preferences.getPref(Preferences.INSECURE_KEY, Boolean.FALSE.toString());
3334
String endpoint = preferences.getPref(Preferences.ENDPOINT_KEY, "");
@@ -56,15 +57,16 @@ Settings getCurrentSettings() {
5657
if (useTokenAuth) {
5758
authMethod = "token";
5859
}
59-
return new Settings(activateSnykOpenSource, activateSnykCode, activateSnykIac, insecure, endpoint, additionalParams,
60+
return new Settings(activateSnykOpenSource, activateSnykCodeSecurity, activateSnykCodeQuality, activateSnykIac, insecure, endpoint, additionalParams,
6061
additionalEnv, path, sendErrorReports, enableTelemetry, organization, manageBinariesAutomatically, cliPath,
6162
token, integrationName, integrationVersion, automaticAuthentication, trustedFolders, enableTrustedFolderFeature,
6263
scanningMode, authMethod);
6364
}
6465

6566
static class Settings {
6667
private final String activateSnykOpenSource;
67-
private final String activateSnykCode;
68+
private final String activateSnykCodeSecurity;
69+
private final String activateSnykCodeQuality;
6870
private final String activateSnykIac;
6971

7072
private final String insecure;
@@ -91,13 +93,14 @@ static class Settings {
9193
private final String requiredProtocolVersion = LsBinaries.REQUIRED_LS_PROTOCOL_VERSION;
9294
private final String authenticationMethod;
9395

94-
public Settings(String activateSnykOpenSource, String activateSnykCode, String activateSnykIac, String insecure,
96+
public Settings(String activateSnykOpenSource, String activateSnykCodeSecurity, String activateSnykCodeQuality, String activateSnykIac, String insecure,
9597
String endpoint, String additionalParams, String additionalEnv, String path, String sendErrorReports,
9698
String enableTelemetry, String organization, String manageBinariesAutomatically, String cliPath, String token,
9799
String integrationName, String integrationVersion, String automaticAuthentication, String[] trustedFolders,
98100
String enableTrustedFoldersFeature, String scanningMode, String authMethod) {
99101
this.activateSnykOpenSource = activateSnykOpenSource;
100-
this.activateSnykCode = activateSnykCode;
102+
this.activateSnykCodeSecurity = activateSnykCodeSecurity;
103+
this.activateSnykCodeQuality = activateSnykCodeQuality;
101104
this.activateSnykIac = activateSnykIac;
102105
this.insecure = insecure;
103106
this.endpoint = endpoint;
@@ -127,8 +130,12 @@ public String getActivateSnykOpenSource() {
127130
return activateSnykOpenSource;
128131
}
129132

130-
public String getActivateSnykCode() {
131-
return activateSnykCode;
133+
public String getActivateSnykCodeSecurity() {
134+
return activateSnykCodeSecurity;
135+
}
136+
137+
public String getActivateSnykCodeQuality() {
138+
return activateSnykCodeQuality;
132139
}
133140

134141
public String getActivateSnykIac() {

plugin/src/main/java/io/snyk/languageserver/LsRuntimeEnvironment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public void addAdditionalParamsAndEnv(Map<String, String> env) {
103103
}
104104

105105
void addProductEnablement(Map<String, String> env) {
106-
env.put(Preferences.ACTIVATE_SNYK_CODE, Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_CODE));
106+
env.put(Preferences.ACTIVATE_SNYK_CODE_SECURITY, Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY));
107+
env.put(Preferences.ACTIVATE_SNYK_CODE_QUALITY, Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_CODE_QUALITY));
107108
env.put(Preferences.ACTIVATE_SNYK_IAC, Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_IAC));
108109
env.put(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE));
109110
}

tests/src/test/java/io/snyk/eclipse/plugin/properties/preferences/PreferencesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void test_DefaultPreferences() {
2828
Preferences prefs = Preferences.getInstance(new InMemoryPreferenceStore());
2929
LsRuntimeEnvironment lsRuntimeEnv = new LsRuntimeEnvironment();
3030

31-
assertEquals("false", prefs.getPref(Preferences.ACTIVATE_SNYK_CODE));
31+
assertEquals("false", prefs.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY));
3232
assertEquals("true", prefs.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE));
3333
assertEquals("true", prefs.getPref(Preferences.ACTIVATE_SNYK_IAC));
3434
assertEquals("true", prefs.getPref(Preferences.SEND_ERROR_REPORTS));
@@ -76,7 +76,7 @@ void test_ExistingOrgInEnvironment_IsStoredInPreferences() {
7676
void test_GetBoolean_returnsBooleanProperty() {
7777
Preferences prefs = Preferences.getInstance(new InMemoryPreferenceStore());
7878

79-
assertFalse(prefs.getBooleanPref(Preferences.ACTIVATE_SNYK_CODE));
79+
assertFalse(prefs.getBooleanPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY));
8080
assertTrue(prefs.getBooleanPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE));
8181
}
8282

tests/src/test/java/io/snyk/languageserver/LsConfigurationUpdaterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void testGetSettings() {
3737
var settings = new LsConfigurationUpdater().getCurrentSettings();
3838

3939
assertEquals("iac", settings.getActivateSnykIac());
40-
assertEquals("code", settings.getActivateSnykCode());
40+
assertEquals("code", settings.getActivateSnykCodeSecurity());
4141
assertEquals("oss", settings.getActivateSnykOpenSource());
4242
assertEquals("true", settings.getInsecure());
4343
assertEquals("endpoint", settings.getEndpoint());
@@ -63,9 +63,9 @@ private void setupPreferenceMock() {
6363
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_IAC, "true")).thenReturn("iac");
6464
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_IAC, "false")).thenReturn("iac");
6565
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_IAC, "")).thenReturn("iac");
66-
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE, "true")).thenReturn("code");
67-
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE, "false")).thenReturn("code");
68-
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE, "")).thenReturn("code");
66+
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true")).thenReturn("code");
67+
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "false")).thenReturn("code");
68+
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "")).thenReturn("code");
6969
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "true")).thenReturn("oss");
7070
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "false")).thenReturn("oss");
7171
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "")).thenReturn("oss");

tests/src/test/java/io/snyk/languageserver/LsRuntimeEnvironmentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ void testAddProductEnablementEnablesDisablesProducts() throws StorageException {
7878
HashMap<String, String> env = new HashMap<>();
7979

8080
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_IAC)).thenReturn("iac");
81-
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE)).thenReturn("code");
81+
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY)).thenReturn("code");
8282
when(preferenceMock.getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE)).thenReturn("oss");
8383

8484
environment.addProductEnablement(env);
8585

8686
assertEquals("oss", env.get(Preferences.ACTIVATE_SNYK_OPEN_SOURCE));
8787
assertEquals("iac", env.get(Preferences.ACTIVATE_SNYK_IAC));
88-
assertEquals("code", env.get(Preferences.ACTIVATE_SNYK_CODE));
88+
assertEquals("code", env.get(Preferences.ACTIVATE_SNYK_CODE_SECURITY));
8989
}
9090

9191
@Test

0 commit comments

Comments
 (0)