|
27 | 27 | import org.eclipse.ui.PlatformUI; |
28 | 28 |
|
29 | 29 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 30 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
30 | 31 | import com.fasterxml.jackson.databind.ObjectMapper; |
31 | 32 |
|
32 | 33 | import io.snyk.eclipse.plugin.SnykStartup; |
|
39 | 40 | import io.snyk.languageserver.protocolextension.messageObjects.SnykIsAvailableCliParams; |
40 | 41 | import io.snyk.languageserver.protocolextension.messageObjects.SnykTrustedFoldersParams; |
41 | 42 |
|
| 43 | + |
42 | 44 | @SuppressWarnings("restriction") |
43 | 45 | public class SnykExtendedLanguageClient extends LanguageClientImpl { |
44 | 46 | private final ProgressManager progressMgr = new ProgressManager(); |
@@ -102,6 +104,22 @@ public void triggerAuthentication() { |
102 | 104 | public void trustWorkspaceFolders() { |
103 | 105 | executeCommand("snyk.trustWorkspaceFolders", new ArrayList<>()); |
104 | 106 | } |
| 107 | + |
| 108 | + public boolean getSastEnabled() { |
| 109 | + ExecuteCommandParams params = new ExecuteCommandParams("snyk.getSettingsSastEnabled", new ArrayList<>()); |
| 110 | + try { |
| 111 | + CompletableFuture<Object> lsSastSettings = getConnectedLanguageServer().getWorkspaceService().executeCommand(params); |
| 112 | + ObjectMapper mapper = new ObjectMapper(); |
| 113 | + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| 114 | + SastSettings sastSettings = mapper.convertValue(lsSastSettings.get(), SastSettings.class); |
| 115 | + |
| 116 | + return sastSettings.sastEnabled; |
| 117 | + } catch (Exception e) { |
| 118 | + SnykLogger.logError(e); |
| 119 | + } |
| 120 | + |
| 121 | + return false; |
| 122 | + } |
105 | 123 |
|
106 | 124 | @JsonNotification(value = "$/snyk.hasAuthenticated") |
107 | 125 | public void hasAuthenticated(HasAuthenticatedParam param) { |
@@ -216,5 +234,33 @@ public boolean refreshOAuthToken() { |
216 | 234 | var newToken = future.completeOnTimeout(token, 2, TimeUnit.SECONDS).join(); |
217 | 235 | return !token.equals(newToken); |
218 | 236 | } |
219 | | - |
| 237 | + |
| 238 | + static class SastSettings { |
| 239 | + public boolean sastEnabled; |
| 240 | + |
| 241 | + public LocalCodeEngine localCodeEngine; |
| 242 | + |
| 243 | + public boolean reportFalsePositivesEnabled; |
| 244 | + |
| 245 | + public String org; |
| 246 | + |
| 247 | + public boolean autofixEnabled; |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * SAST local code engine configuration. |
| 252 | + */ |
| 253 | + static class LocalCodeEngine { |
| 254 | + public boolean enabled; |
| 255 | + |
| 256 | + public String url; |
| 257 | + } |
| 258 | + |
| 259 | + public static <T> T convertInstanceOfObject(Object o, Class<T> clazz) { |
| 260 | + try { |
| 261 | + return clazz.cast(o); |
| 262 | + } catch(ClassCastException e) { |
| 263 | + return null; |
| 264 | + } |
| 265 | + } |
220 | 266 | } |
0 commit comments