Skip to content

Commit 5db1f52

Browse files
bastiandoetschackenick-y-snyk
authored
feat: consume org from folderConfig [IDE-1368] (#327)
* feat: add organization to project properties * fix: imports, pmd violations * fix: bump jackson deps * fix: bump core-text dep * fix: bump lang3 dep * fix: a few bugs with NPEs * fix: add checkbox * fix: add selection listeners to property page * fix: handle auto org correctly * fix: remove validation, so we can set an empty org in project settings and use global org * fix: remove unneeded org logic * fix: update the UI labels and make pref page behave even if ls has not started * fix: added a context menu for open project preferences * fix: clean up UI for auto org Added help text to Snyk Code Security checkbox: "Snyk Code scans must be enabled for the organization to run." Removed disableSnykCodeIfOrgDisabled() method and all calls to it Snyk Code checkbox is always selectable, regardless of SAST/org status Removed conditional logic in toggleIgnoresButtons() that hid filters based on CCI status Open Issues and Ignored Issues filters are always visible Updated tooltips in plugin.xml to mention: "Note: This filter will only take effect if Code Consistent Ignores (CCI) is enabled for the organization." * fix: remove LCE from sast settings * fix: remove (CCI) from tooltips * fix: fix linter on generic exception * fix: remove tooltip from checkbox * fix: add back the org enabled for code * fix: fixed duplicate of code must be enabled label. * fix: disable auto org by default * fix: display Snyk Code disabled in the tree view [IDE 1538] (#339) fix: error html view --------- Co-authored-by: Knut Funkel <knut.funkel@snyk.io> Co-authored-by: nick-y-snyk <nikita.yasnohorodskyi@snyk.io>
1 parent 0478940 commit 5db1f52

32 files changed

+978
-487
lines changed

plugin/META-INF/MANIFEST.MF

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Automatic-Module-Name: io.snyk.eclipse.plugin.tests
2929
Bundle-ActivationPolicy: lazy
3030
Bundle-ClassPath: .,
3131
target/dependency/commons-codec-1.17.0.jar,
32-
target/dependency/commons-lang3-3.19.0.jar,
33-
target/dependency/commons-text-1.10.0.jar,
32+
target/dependency/commons-lang3-3.18.0.jar,
33+
target/dependency/commons-text-1.14.0.jar,
3434
target/dependency/commons-logging-1.3.4.jar,
3535
target/dependency/httpclient-4.5.14.jar,
3636
target/dependency/httpcore-4.4.16.jar,
37-
target/dependency/jackson-annotations-2.16.2.jar,
38-
target/dependency/jackson-core-2.16.2.jar,
39-
target/dependency/jackson-databind-2.16.2.jar,
37+
target/dependency/jackson-annotations-2.20.jar,
38+
target/dependency/jackson-core-2.20.0.jar,
39+
target/dependency/jackson-databind-2.20.0.jar,
4040
target/dependency/javax.inject-1.jar

plugin/build.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ bin.includes = plugin.xml,\
88
OSGI-INF/l10n/bundle.properties,\
99
OSGI-INF/,\
1010
target/dependency/commons-codec-1.17.0.jar,\
11-
target/dependency/commons-lang3-3.19.0.jar,\
11+
target/dependency/commons-lang3-3.18.0.jar,\
1212
target/dependency/commons-logging-1.3.4.jar,\
1313
target/dependency/httpclient-4.5.14.jar,\
1414
target/dependency/httpcore-4.4.16.jar,\
15-
target/dependency/jackson-annotations-2.16.2.jar,\
16-
target/dependency/jackson-core-2.16.2.jar,\
17-
target/dependency/jackson-databind-2.16.2.jar,\
15+
target/dependency/jackson-annotations-2.20.jar,\
16+
target/dependency/jackson-core-2.20.0.jar,\
17+
target/dependency/jackson-databind-2.20.0.jar,\
1818
target/dependency/javax.inject-1.jar,\
19-
target/dependency/commons-text-1.10.0.jar
19+
target/dependency/commons-text-1.14.0.jar
2020
src.includes =src/,\
2121
icons/

plugin/io.snyk.eclipse.plugin.eml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<lib name="commons-codec-1.17.0.jar" scope="COMPILE">
88
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-codec-1.17.0.jar!/"/>
99
</lib>
10-
<lib name="commons-lang3-3.19.0.jar" scope="COMPILE">
11-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-lang3-3.19.0.jar!/"/>
10+
<lib name="commons-lang3-3.18.0.jar" scope="COMPILE">
11+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-lang3-3.18.0.jar!/"/>
1212
</lib>
1313
<lib name="commons-logging-1.3.4.jar" scope="COMPILE">
1414
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-logging-1.3.4.jar!/"/>
@@ -19,23 +19,23 @@
1919
<lib name="httpcore-4.4.16.jar" scope="COMPILE">
2020
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpcore-4.4.16.jar!/"/>
2121
</lib>
22-
<lib name="jackson-annotations-2.16.2.jar" scope="COMPILE">
23-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-annotations-2.16.2.jar!/"/>
22+
<lib name="jackson-annotations-2.20.jar" scope="COMPILE">
23+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-annotations-2.20.jar!/"/>
2424
</lib>
25-
<lib name="jackson-core-2.16.2.jar" scope="COMPILE">
26-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-core-2.16.2.jar!/"/>
25+
<lib name="jackson-core-2.20.0.jar" scope="COMPILE">
26+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-core-2.20.0.jar!/"/>
2727
</lib>
28-
<lib name="jackson-databind-2.16.2.jar" scope="COMPILE">
29-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-databind-2.16.2.jar!/"/>
28+
<lib name="jackson-databind-2.20.0.jar" scope="COMPILE">
29+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-databind-2.20.0.jar!/"/>
3030
</lib>
3131
<lib name="javax.inject-1.jar" scope="COMPILE">
3232
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/javax.inject-1.jar!/"/>
3333
</lib>
3434
<levels>
35-
<level name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.16.2" value="project"/>
36-
<level name="Maven: com.fasterxml.jackson.core:jackson-core:2.16.2" value="project"/>
37-
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.16.2" value="project"/>
38-
<level name="Maven: org.apache.commons:commons-lang3:3.19.0" value="project"/>
35+
<level name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.20" value="project"/>
36+
<level name="Maven: com.fasterxml.jackson.core:jackson-core:2.20.0" value="project"/>
37+
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.20.0" value="project"/>
38+
<level name="Maven: org.apache.commons:commons-lang3:3.18.0" value="project"/>
3939
<level name="Maven: org.apache.httpcomponents:httpcore:4.4.16" value="project"/>
4040
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.14" value="project"/>
4141
<level name="Maven: commons-logging:commons-logging:1.2" value="project"/>

plugin/plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@
314314
commandId="io.snyk.eclipse.plugin.commands.snykShowOpenIgnored"
315315
icon="icons/enabled.png"
316316
style="push"
317-
tooltip="Show Open Issues">
317+
tooltip="Show Open Issues. Note: This filter will only take effect if Code Consistent Ignores is enabled for the organization.">
318318
</command>
319319
<command
320320
commandId="io.snyk.eclipse.plugin.commands.snykShowIgnored"
321321
icon="icons/enabled.png"
322322
style="push"
323-
tooltip="Show Ignored">
323+
tooltip="Show Ignored. Note: This filter will only take effect if Code Consistent Ignores is enabled for the organization.">
324324
</command>
325325
<command
326326
commandId="io.snyk.eclipse.plugin.commands.snykFilterNetNewIssues"

plugin/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@
1717
<dependency>
1818
<groupId>com.fasterxml.jackson.core</groupId>
1919
<artifactId>jackson-annotations</artifactId>
20-
<version>2.16.2</version>
20+
<version>2.20</version>
2121
<type>jar</type>
2222
</dependency>
2323
<dependency>
2424
<groupId>com.fasterxml.jackson.core</groupId>
2525
<artifactId>jackson-core</artifactId>
26-
<version>2.16.2</version>
26+
<version>2.20.0</version>
2727
<type>jar</type>
2828
</dependency>
2929
<dependency>
3030
<groupId>com.fasterxml.jackson.core</groupId>
3131
<artifactId>jackson-databind</artifactId>
32-
<version>2.16.2</version>
32+
<version>2.20.0</version>
3333
<type>jar</type>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.apache.commons</groupId>
3737
<artifactId>commons-lang3</artifactId>
38-
<version>3.19.0</version>
38+
<version>3.18.0</version>
3939
<type>jar</type>
4040
</dependency>
4141
<dependency>
4242
<groupId>org.apache.commons</groupId>
4343
<artifactId>commons-text</artifactId>
44-
<version>1.10.0</version>
44+
<version>1.14.0</version>
4545
<type>jar</type>
4646
</dependency>
4747
<dependency>

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.snyk.eclipse.plugin.preferences.Preferences;
1919
import io.snyk.eclipse.plugin.utils.ResourceUtils;
2020
import io.snyk.eclipse.plugin.utils.SnykLogger;
21+
import io.snyk.languageserver.protocolextension.messageObjects.PresentableError;
2122

2223
public class BaseHtmlProvider {
2324
private final Random random = new Random();
@@ -206,17 +207,41 @@ public ITheme getCurrentTheme() {
206207
currentTheme = themeManager.getCurrentTheme();
207208
return currentTheme;
208209
}
209-
public String getErrorHtml(String errorMessage, String path) {
210-
String escapedErrorMessage = errorMessage == null ? "Unknown error" : StringEscapeUtils.escapeHtml3((errorMessage));
211-
String escapedPath = path == null ? "Unknown path" : StringEscapeUtils.escapeHtml3(path);
210+
public String getErrorHtml(PresentableError presentableError) {
211+
StringBuilder errorDetails = new StringBuilder(256);
212+
213+
if (presentableError == null) {
214+
errorDetails.append("<tr><td><strong>error:</strong></td><td>Unknown error</td></tr>");
215+
} else {
216+
// Filter out showNotification and treeNodeSuffix - they're not for display
217+
if (presentableError.getCode() != null && presentableError.getCode() != 0) {
218+
errorDetails.append(String.format("<tr><td><strong>code:</strong></td><td>%d</td></tr>%n", presentableError.getCode()));
219+
}
220+
221+
if (presentableError.getError() != null && !presentableError.getError().isBlank()) {
222+
String escapedError = StringEscapeUtils.escapeHtml4(presentableError.getError());
223+
errorDetails.append(String.format("<tr><td><strong>error:</strong></td><td>%s</td></tr>%n", escapedError));
224+
}
225+
226+
if (presentableError.getPath() != null && !presentableError.getPath().isBlank()) {
227+
String escapedPath = StringEscapeUtils.escapeHtml4(presentableError.getPath());
228+
errorDetails.append(String.format("<tr><td><strong>path:</strong></td><td>%s</td></tr>%n", escapedPath));
229+
}
230+
231+
if (presentableError.getCommand() != null && !presentableError.getCommand().isBlank()) {
232+
String escapedCommand = StringEscapeUtils.escapeHtml4(presentableError.getCommand());
233+
errorDetails.append(String.format("<tr><td><strong>command:</strong></td><td>%s</td></tr>%n", escapedCommand));
234+
}
235+
}
236+
212237
var html = String.format("""
213238
<!DOCTYPE html>
214239
<html lang="en">
215240
<head>
216241
<meta http-equiv='Content-Type' content='text/html; charset=unicode' />
217242
<meta charset="UTF-8">
218243
<meta name="viewport" content="width=device-width, initial-scale=1.0">
219-
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-ideNonce'; style-src 'self' 'nonce-ideNonce';">
244+
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-ideNonce'; style-src 'self' 'nonce-ideNonce';">
220245
<title>Snyk for Eclipse</title>
221246
<style nonce=ideNonce>
222247
body {
@@ -228,27 +253,29 @@ public String getErrorHtml(String errorMessage, String path) {
228253
display: flex;
229254
align-items: center;
230255
}
231-
.logo {
232-
margin-right: 20px;
256+
table {
257+
border-spacing: 10px 5px;
258+
}
259+
td {
260+
vertical-align: top;
261+
padding: 5px;
262+
}
263+
td:first-child {
264+
width: 100px;
233265
}
234266
</style>
235267
</head>
236268
<body>
237269
<div class="container">
238270
<div>
239-
<p><strong>An error occurred:</strong></p>
240-
<p>
241271
<table>
242-
<tr><td width="150" >Error message:</td><td id="errorContainer">%s</td></tr>
243-
<tr></tr>
244-
<tr><td width="150" >Path:</td><td id="pathContainer">%s</td></tr>
272+
%s
245273
</table>
246-
</p>
247274
</div>
248275
</div>
249276
</body>
250277
</html>
251-
""",escapedErrorMessage, escapedPath);
278+
""", errorDetails.toString());
252279
return replaceCssVariables(html);
253280
}
254281
}

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

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.eclipse.ui.IWorkbenchPreferencePage;
2424

2525
import io.snyk.eclipse.plugin.utils.SnykLogger;
26-
import io.snyk.languageserver.SnykLanguageServer;
2726
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
2827

2928
public class PreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@@ -52,7 +51,7 @@ protected void createFieldEditors() {
5251

5352
addField(new LabelFieldEditor(
5453
"If you're using SSO with Snyk and OAuth2, the custom endpoint configuration is automatically populated.\n"
55-
+ "Otherwise, for public regional instances, see the docs: ",
54+
+ "Otherwise, for public regional instances, see the docs: ",
5655
getFieldEditorParent()));
5756
Link link = new Link(this.getFieldEditorParent(), SWT.NONE);
5857

@@ -91,25 +90,40 @@ protected void createFieldEditors() {
9190
addField(space());
9291
addField(new LabelFieldEditor("The following options involve the Snyk Language Server.",
9392
getFieldEditorParent()));
94-
addField(new LabelFieldEditor(
95-
"Activating Snyk Code will cause upload of source code to Snyk or the given endpoint address.",
96-
getFieldEditorParent()));
9793
addField(space());
9894
addField(new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "Snyk Open Source enabled",
9995
getFieldEditorParent()));
10096
snykCodeSecurityCheckbox = new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_CODE_SECURITY,
101-
"Snyk Code Security enabled", getFieldEditorParent());
97+
"Snyk Code Security enabled\nNote: Code must be enabled for your organization to run.", getFieldEditorParent());
10298
addField(snykCodeSecurityCheckbox);
103-
10499
addField(new BooleanFieldEditor(Preferences.ACTIVATE_SNYK_IAC, "Snyk Infrastructure-as-Code enabled",
105100
getFieldEditorParent()));
106101

102+
103+
107104
addField(space());
108105
addField(new BooleanFieldEditor(Preferences.SCANNING_MODE_AUTOMATIC, "Scan automatically on start-up and save",
109106
getFieldEditorParent()));
110107
addField(space());
111108
addField(new LabelFieldEditor("Advanced options:", getFieldEditorParent()));
112-
addField(new StringFieldEditor(Preferences.ORGANIZATION_KEY, "Organization:", WIDTH, getFieldEditorParent()));
109+
110+
// Add label with tooltip text below orgEditor
111+
addField(new LabelFieldEditor(
112+
"Specify the organization (ID or name) for Snyk to run scans against.\n"
113+
+ "Organization selection follows this order:\n"
114+
+ "1. Project-specific settings (if configured)\n"
115+
+ "2. This global setting (if the project-specific setting is empty)\n"
116+
+ "3. Your web account's preferred organization (if both above are empty)\n"
117+
+ "Manual organization settings override automatic organization selection.",
118+
getFieldEditorParent()));
119+
120+
final var orgEditor = new StringFieldEditor(Preferences.ORGANIZATION_KEY, "Organization:", WIDTH, getFieldEditorParent());
121+
orgEditor.setEnabled(true, getFieldEditorParent());
122+
orgEditor.getTextControl(getFieldEditorParent()).setToolTipText(
123+
"Specify the organization (ID or name) for Snyk to run scans against. If the organization is provided manually, automatic organization selection is overridden. If the organization value is blank or invalid, the preferred organization defined in your web account settings will be used.");
124+
addField(orgEditor);
125+
126+
113127
addField(new StringFieldEditor(Preferences.ADDITIONAL_PARAMETERS, "Additional Parameters:", WIDTH,
114128
getFieldEditorParent()));
115129
addField(new StringFieldEditor(Preferences.ADDITIONAL_ENVIRONMENT, "Additional Environment:", WIDTH,
@@ -148,7 +162,6 @@ protected void createFieldEditors() {
148162
StringFieldEditor trustedFoldersEditor = new StringFieldEditor(Preferences.TRUSTED_FOLDERS, "Trusted Folders:",
149163
WIDTH, getFieldEditorParent());
150164
addField(trustedFoldersEditor);
151-
disableSnykCodeIfOrgDisabled();
152165
}
153166

154167
private SelectionAdapter authenticateSelectionAdapter() {
@@ -187,7 +200,6 @@ private FieldEditor space() {
187200
@Override
188201
public boolean performOk() {
189202
boolean superOK = super.performOk();
190-
disableSnykCodeIfOrgDisabled();
191203
CompletableFuture.runAsync(() -> {
192204
SnykExtendedLanguageClient lc = SnykExtendedLanguageClient.getInstance();
193205
lc.updateConfiguration();
@@ -196,37 +208,4 @@ public boolean performOk() {
196208
return superOK;
197209
}
198210

199-
private void disableSnykCodeIfOrgDisabled() {
200-
CompletableFuture.runAsync(() -> {
201-
SnykLanguageServer.waitForInit();
202-
boolean isSastEnabled;
203-
try {
204-
isSastEnabled = SnykExtendedLanguageClient.getInstance().getSastEnabled();
205-
} catch (Exception e) {
206-
SnykLogger.logError(e);
207-
return;
208-
}
209-
210-
String message = "Snyk Code disabled, because it is not enabled for your organization. After you close this preference page, it will stay disabled.";
211-
final var enabled = isSastEnabled;
212-
Display.getCurrent().asyncExec(new Runnable() {
213-
boolean showMessage;
214-
boolean checkBoxValue;
215-
216-
@Override
217-
public void run() {
218-
checkBoxValue = snykCodeSecurityCheckbox != null && snykCodeSecurityCheckbox.getBooleanValue();
219-
if (checkBoxValue && !enabled) {
220-
snykCodeSecurityCheckbox
221-
.setLabelText(snykCodeSecurityCheckbox.getLabelText() + " (" + message + ")");
222-
showMessage = true;
223-
}
224-
225-
if (showMessage)
226-
SnykLogger.logInfo(message);
227-
}
228-
});
229-
});
230-
}
231-
232211
}

plugin/src/main/java/io/snyk/eclipse/plugin/preferences/TokenFieldEditor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.eclipse.jface.preference.IPreferenceStore;
44
import org.eclipse.jface.preference.StringFieldEditor;
55
import org.eclipse.swt.widgets.Composite;
6+
import org.eclipse.swt.widgets.Text;
67

78
public class TokenFieldEditor extends StringFieldEditor {
89
private Preferences preferences;
@@ -11,8 +12,15 @@ protected TokenFieldEditor(Preferences preferences, String name, String labelTex
1112
super(name, labelText, 60, parent);
1213
this.preferences = preferences;
1314
super.setPreferenceStore(preferences.getSecureStore());
14-
getTextControl().setEchoChar('*');
15+
this.getTextControl().setEchoChar('*');
1516
}
17+
18+
@Override
19+
protected final Text getTextControl() {
20+
return super.getTextControl();
21+
}
22+
23+
1624

1725
public void emptyTextfield() {
1826
setStringValue("");

0 commit comments

Comments
 (0)