Skip to content

Commit 77b0f91

Browse files
authored
CM-44180 - Add proper support for disabled modules (#85)
1 parent dea2db0 commit 77b0f91

File tree

20 files changed

+132
-100
lines changed

20 files changed

+132
-100
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT
9090
9191
- name: Upload artifact
92-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
9393
with:
9494
name: ${{ steps.artifact.outputs.filename }}
9595
path: ./build/distributions/content/*/*
@@ -125,7 +125,7 @@ jobs:
125125
#
126126
# - name: Collect Tests Result
127127
# if: ${{ failure() }}
128-
# uses: actions/upload-artifact@v3
128+
# uses: actions/upload-artifact@v4
129129
# with:
130130
# name: tests-result
131131
# path: ${{ github.workspace }}/build/reports/tests
@@ -205,7 +205,7 @@ jobs:
205205

206206
- name: Collect Plugin Verifier Result
207207
if: ${{ always() }}
208-
uses: actions/upload-artifact@v3
208+
uses: actions/upload-artifact@v4
209209
with:
210210
name: pluginVerifier-result
211211
path: ${{ github.workspace }}/build/reports/pluginVerifier

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## [Unreleased]
66

7+
- Add proper support for disabled modules
8+
79
## [2.4.1] - 2025-01-29
810

911
- Fix usage of internal API in 2025.1

src/main/kotlin/com/cycode/plugin/annotators/annotationAppliers/IacApplier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class IacApplier(private val scanResults: ScanResultsService) : AnnotationApplie
2121
}
2222

2323
override fun apply(psiFile: PsiFile, holder: AnnotationHolder) {
24-
val latestScanResult = scanResults.getIacResults()
24+
val latestScanResult = scanResults.iacResults
2525
if (latestScanResult !is CliResult.Success) {
2626
return
2727
}

src/main/kotlin/com/cycode/plugin/annotators/annotationAppliers/SastApplier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SastApplier(private val scanResults: ScanResultsService) : AnnotationAppli
2020
}
2121

2222
override fun apply(psiFile: PsiFile, holder: AnnotationHolder) {
23-
val latestScanResult = scanResults.getSastResults()
23+
val latestScanResult = scanResults.sastResults
2424
if (latestScanResult !is CliResult.Success) {
2525
return
2626
}

src/main/kotlin/com/cycode/plugin/annotators/annotationAppliers/ScaApplier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ScaApplier(private val scanResults: ScanResultsService) : AnnotationApplie
3131
}
3232

3333
override fun apply(psiFile: PsiFile, holder: AnnotationHolder) {
34-
val latestScanResult = scanResults.getScaResults()
34+
val latestScanResult = scanResults.scaResults
3535
if (latestScanResult !is CliResult.Success) {
3636
return
3737
}

src/main/kotlin/com/cycode/plugin/annotators/annotationAppliers/SecretApplier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SecretApplier(private val scanResults: ScanResultsService) : AnnotationApp
3131
}
3232

3333
override fun apply(psiFile: PsiFile, holder: AnnotationHolder) {
34-
val latestScanResult = scanResults.getSecretResults()
34+
val latestScanResult = scanResults.secretResults
3535
if (latestScanResult !is CliResult.Success) {
3636
return
3737
}

src/main/kotlin/com/cycode/plugin/cli/models/StatusResult.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.cycode.plugin.cli.models
22

33
data class SupportedModulesStatus(
4-
// TODO(MarshalX): respect enabled/disabled scanning modules
54
val secretScanning: Boolean,
65
val scaScanning: Boolean,
76
val iacScanning: Boolean,

src/main/kotlin/com/cycode/plugin/components/toolWindow/CycodeToolWindowFactory.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.cycode.plugin.components.toolWindow.components.loadingContentTab.Load
77
import com.cycode.plugin.components.toolWindow.components.scanContentTab.ScanContentTab
88
import com.cycode.plugin.icons.PluginIcons
99
import com.cycode.plugin.services.cycode
10-
import com.cycode.plugin.services.pluginState
10+
import com.cycode.plugin.services.pluginLocalState
1111
import com.intellij.openapi.application.ApplicationManager
1212
import com.intellij.openapi.application.WriteAction
1313
import com.intellij.openapi.project.DumbAware
@@ -75,21 +75,21 @@ private fun createToolWindowContent(component: JPanel): Content {
7575

7676
fun getRightPanelDependingOnState(project: Project): JPanel {
7777
val service = cycode(project)
78-
val pluginState = pluginState()
78+
val pluginLocalState = pluginLocalState(project)
7979

80-
if (!pluginState.cliInstalled) {
80+
if (!pluginLocalState.cliInstalled) {
8181
return LoadingContentTab().getContent(service)
8282
}
8383

84-
return if (pluginState.cliAuthed) {
84+
return if (pluginLocalState.cliAuthed) {
8585
ScanContentTab().getContent(service)
8686
} else {
8787
AuthContentTab().getContent(service)
8888
}
8989
}
9090

9191
fun updateToolWindowStateForAllProjects() {
92-
// we are using this method to sync the state of the tool window for all open projects
92+
// we are using this method to sync the state of the tool window for all open projects,
9393
// for example, after changing the auth state
9494
ApplicationManager.getApplication().runReadAction {
9595
val projects = ProjectManager.getInstance().openProjects

src/main/kotlin/com/cycode/plugin/components/toolWindow/components/cycodeActionToolBar/actions/RunAllAction.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.cycode.plugin.components.toolWindow.components.cycodeActionToolBar.a
33
import com.cycode.plugin.CycodeBundle
44
import com.cycode.plugin.cli.CliScanType
55
import com.cycode.plugin.services.cycode
6-
import com.cycode.plugin.services.pluginState
6+
import com.cycode.plugin.services.pluginLocalState
77
import com.intellij.icons.AllIcons
88
import com.intellij.openapi.actionSystem.ActionUpdateThread
99
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -27,16 +27,25 @@ class RunAllAction :
2727
// we can provide "stop" action only after that
2828
val project = e.project ?: return
2929
val service = cycode(project)
30+
val pluginLocalState = pluginLocalState(project)
3031

31-
service.startScanForCurrentProject(CliScanType.Secret)
32-
service.startScanForCurrentProject(CliScanType.Sca)
33-
service.startScanForCurrentProject(CliScanType.Iac)
34-
service.startScanForCurrentProject(CliScanType.Sast)
32+
if (pluginLocalState.isSecretScanningEnabled) {
33+
service.startScanForCurrentProject(CliScanType.Secret)
34+
}
35+
if (pluginLocalState.isScaScanningEnabled) {
36+
service.startScanForCurrentProject(CliScanType.Sca)
37+
}
38+
if (pluginLocalState.isIacScanningEnabled) {
39+
service.startScanForCurrentProject(CliScanType.Iac)
40+
}
41+
if (pluginLocalState.isSastScanningEnabled) {
42+
service.startScanForCurrentProject(CliScanType.Sast)
43+
}
3544
}
3645

3746
override fun update(e: AnActionEvent) {
3847
e.presentation.isEnabled = e.project != null &&
3948
!e.project!!.isDisposed &&
40-
pluginState().cliAuthed
49+
pluginLocalState(e.project).cliAuthed
4150
}
4251
}

src/main/kotlin/com/cycode/plugin/components/toolWindow/components/scanContentTab/ScanContentTab.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.cycode.plugin.cli.CliScanType
55
import com.cycode.plugin.components.Component
66
import com.cycode.plugin.components.common.createClickableLabel
77
import com.cycode.plugin.services.CycodeService
8+
import com.cycode.plugin.services.pluginLocalState
89
import com.intellij.util.ui.JBUI
910
import java.awt.GridBagConstraints
1011
import java.awt.GridBagLayout
@@ -27,24 +28,31 @@ class ScanContentTab : Component<CycodeService>() {
2728
}
2829

2930
override fun getContent(service: CycodeService): JPanel {
31+
// do not get local state on class level because will be outdated
32+
val pluginLocalState = pluginLocalState(service.project)
33+
3034
addComponentToPanel(createClickableLabel(CycodeBundle.message("scanTabTitleLabel")))
3135
addComponentToPanel(
3236
JButton(CycodeBundle.message("scanTabSecretsBtn")).apply {
37+
isEnabled = pluginLocalState.isSecretScanningEnabled
3338
addActionListener { service.startScanForCurrentProject(CliScanType.Secret) }
3439
},
3540
)
3641
addComponentToPanel(
3742
JButton(CycodeBundle.message("scanTabScaBtn")).apply {
43+
isEnabled = pluginLocalState.isScaScanningEnabled
3844
addActionListener { service.startScanForCurrentProject(CliScanType.Sca) }
3945
},
4046
)
4147
addComponentToPanel(
4248
JButton(CycodeBundle.message("scanTabIacBtn")).apply {
49+
isEnabled = pluginLocalState.isIacScanningEnabled
4350
addActionListener { service.startScanForCurrentProject(CliScanType.Iac) }
4451
},
4552
)
4653
addComponentToPanel(
4754
JButton(CycodeBundle.message("scanTabSastBtn")).apply {
55+
isEnabled = pluginLocalState.isSastScanningEnabled
4856
addActionListener { service.startScanForCurrentProject(CliScanType.Sast) }
4957
},
5058
)

src/main/kotlin/com/cycode/plugin/components/toolWindow/components/treeView/TreeView.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TreeView(
182182
}
183183

184184
private fun createSecretDetectionNodes() {
185-
val secretDetections = scanResults.getSecretResults()
185+
val secretDetections = scanResults.secretResults
186186
if (secretDetections !is CliResult.Success) {
187187
return
188188
}
@@ -201,7 +201,7 @@ class TreeView(
201201
}
202202

203203
private fun createScaDetectionNodes() {
204-
val scaDetections = scanResults.getScaResults()
204+
val scaDetections = scanResults.scaResults
205205
if (scaDetections !is CliResult.Success) {
206206
return
207207
}
@@ -220,7 +220,7 @@ class TreeView(
220220
}
221221

222222
private fun createIacDetectionNodes() {
223-
val iacDetections = scanResults.getIacResults()
223+
val iacDetections = scanResults.iacResults
224224
if (iacDetections !is CliResult.Success) {
225225
return
226226
}
@@ -239,7 +239,7 @@ class TreeView(
239239
}
240240

241241
private fun createSastDetectionNodes() {
242-
val sastDetections = scanResults.getSastResults()
242+
val sastDetections = scanResults.sastResults
243243
if (sastDetections !is CliResult.Success) {
244244
return
245245
}

src/main/kotlin/com/cycode/plugin/components/toolWindow/components/violationCardContentTab/iacViolationCardContentTab/IacViolationCardContentTab.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import com.cycode.plugin.components.toolWindow.components.violationCardContentTa
1111
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.iacViolationCardContentTab.components.shortSummary.IacShortSummary
1212
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.iacViolationCardContentTab.components.summary.IacSummary
1313
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.iacViolationCardContentTab.components.title.IacTitle
14-
import com.cycode.plugin.services.pluginState
14+
import com.cycode.plugin.services.pluginLocalState
1515
import com.intellij.openapi.project.Project
1616
import javax.swing.JComponent
1717

1818
class IacViolationCardContentTab(val project: Project) : CommonViolationCardContentTab() {
1919
fun getContent(detection: IacDetection): JComponent {
20-
val pluginState = pluginState()
20+
val pluginLocalState = pluginLocalState(project)
2121

2222
val titlePanel = IacTitle().getContent(detection)
2323
val shortSummaryPanel = IacShortSummary().getContent(detection)
@@ -35,7 +35,7 @@ class IacViolationCardContentTab(val project: Project) : CommonViolationCardCont
3535
cycodeGuidelines,
3636
)
3737

38-
if (pluginState.isAiLargeLanguageModelEnabled) {
38+
if (pluginLocalState.isAiLargeLanguageModelEnabled) {
3939
val aiRemediationComponent = CardHtmlSummary(CycodeBundle.message("violationCardAiRemediationTitle"))
4040
val actionsPanel = IacActions(project).addContent(detection, aiRemediationComponent)
4141
componentsToRender.add(aiRemediationComponent.getContent())

src/main/kotlin/com/cycode/plugin/components/toolWindow/components/violationCardContentTab/sastViolationCardContentTab/SastViolationCardContentTab.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import com.cycode.plugin.components.toolWindow.components.violationCardContentTa
1111
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.sastViolationCardContentTab.components.shortSummary.SastShortSummary
1212
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.sastViolationCardContentTab.components.summary.SastSummary
1313
import com.cycode.plugin.components.toolWindow.components.violationCardContentTab.sastViolationCardContentTab.components.title.SastTitle
14-
import com.cycode.plugin.services.pluginState
14+
import com.cycode.plugin.services.pluginLocalState
1515
import com.intellij.openapi.project.Project
1616
import javax.swing.JComponent
1717

1818
class SastViolationCardContentTab(val project: Project) : CommonViolationCardContentTab() {
1919
fun getContent(detection: SastDetection): JComponent {
20-
val pluginState = pluginState()
20+
val pluginLocalState = pluginLocalState(project)
2121

2222
val titlePanel = SastTitle().getContent(detection)
2323
val shortSummaryPanel = SastShortSummary().getContent(detection)
@@ -35,7 +35,7 @@ class SastViolationCardContentTab(val project: Project) : CommonViolationCardCon
3535
cycodeGuidelines,
3636
)
3737

38-
if (pluginState.isAiLargeLanguageModelEnabled) {
38+
if (pluginLocalState.isAiLargeLanguageModelEnabled) {
3939
val aiRemediationComponent = CardHtmlSummary(CycodeBundle.message("violationCardAiRemediationTitle"))
4040
val actionsPanel = SastActions(project).addContent(detection, aiRemediationComponent)
4141
componentsToRender.add(aiRemediationComponent.getContent())

src/main/kotlin/com/cycode/plugin/listeners/FileSaveListener.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import com.cycode.plugin.cli.CliScanType
55
import com.cycode.plugin.cli.isSupportedIacFile
66
import com.cycode.plugin.cli.isSupportedPackageFile
77
import com.cycode.plugin.services.cycode
8+
import com.cycode.plugin.services.pluginLocalState
89
import com.cycode.plugin.services.pluginSettings
9-
import com.cycode.plugin.services.pluginState
1010
import com.intellij.openapi.diagnostic.thisLogger
1111
import com.intellij.openapi.editor.Document
1212
import com.intellij.openapi.fileEditor.FileDocumentManager
@@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit
2020

2121
class FileSaveListener(private val project: Project) : FileDocumentManagerListener {
2222
private val service = cycode(project)
23-
private val pluginState = pluginState()
23+
private val pluginLocalState = pluginLocalState(project)
2424
private val pluginSettings = pluginSettings()
2525
private val collectedPathsToScan = mutableSetOf<String>() // we use a set to avoid duplicates
2626

@@ -33,21 +33,21 @@ class FileSaveListener(private val project: Project) : FileDocumentManagerListen
3333
val pathsToScan = excludeNotExistingPaths(collectedPathsToScan.toMutableList())
3434
collectedPathsToScan.clear()
3535

36-
if (!pluginState.cliAuthed) {
36+
if (!pluginLocalState.cliAuthed) {
3737
return
3838
}
3939

40-
if (pathsToScan.isNotEmpty()) {
40+
if (pluginLocalState.isSecretScanningEnabled && pathsToScan.isNotEmpty()) {
4141
service.startScan(CliScanType.Secret, pathsToScan, onDemand = false)
4242
}
4343

4444
val scaPathsToScan = excludeNonScaRelatedPaths(pathsToScan)
45-
if (scaPathsToScan.isNotEmpty()) {
45+
if (pluginLocalState.isScaScanningEnabled && scaPathsToScan.isNotEmpty()) {
4646
service.startScan(CliScanType.Sca, scaPathsToScan, onDemand = false)
4747
}
4848

4949
val iacPathsToScan = excludeNonIacRelatedPaths(pathsToScan)
50-
if (iacPathsToScan.isNotEmpty()) {
50+
if (pluginLocalState.isIacScanningEnabled && iacPathsToScan.isNotEmpty()) {
5151
service.startScan(CliScanType.Iac, iacPathsToScan, onDemand = false)
5252
}
5353
}
@@ -78,7 +78,7 @@ class FileSaveListener(private val project: Project) : FileDocumentManagerListen
7878
override fun beforeDocumentSaving(document: Document) {
7979
thisLogger().debug("FileSaveListener.beforeDocumentSaving")
8080

81-
if (!pluginSettings.scanOnSave || !pluginState.cliAuthed) {
81+
if (!pluginSettings.scanOnSave || !pluginLocalState.cliAuthed) {
8282
return
8383
}
8484

0 commit comments

Comments
 (0)