From be801a6bf453f7fbefe88eb5ef3f6f6fa4ce82e1 Mon Sep 17 00:00:00 2001 From: Ilya Siamionau Date: Wed, 31 Jan 2024 12:07:27 +0100 Subject: [PATCH] CM-31957 - Fix scan results sharing between projects --- CHANGELOG.md | 8 +++++++- gradle.properties | 2 +- .../com/cycode/plugin/annotators/CycodeAnnotator.kt | 8 +++++++- .../models/scanResult/secret/SecretDetectionDetails.kt | 2 +- .../plugin/intentions/CycodeIgnoreIntentionQuickFix.kt | 3 +-- src/main/kotlin/com/cycode/plugin/services/CliService.kt | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a3c45..dc93eb6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] +## [1.1.4] - 2024-01-31 + +- Fix scan results sharing across projects + ## [1.1.3] - 2024-01-30 - Fix work with many opened projects @@ -30,6 +34,8 @@ The first public release of the plugin. +[1.1.4]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.1.4 + [1.1.3]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.1.3 [1.1.2]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.1.2 @@ -42,4 +48,4 @@ The first public release of the plugin. [1.0.0]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.0.0 -[Unreleased]: https://github.com/cycodehq/intellij-platform-plugin/compare/v1.1.3...HEAD +[Unreleased]: https://github.com/cycodehq/intellij-platform-plugin/compare/v1.1.4...HEAD diff --git a/gradle.properties b/gradle.properties index 9147cf8..dc6dbf2 100755 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.cycode.plugin pluginName = Cycode pluginRepositoryUrl = https://github.com/cycodehq/intellij-platform-plugin # SemVer format -> https://semver.org -pluginVersion = 1.1.3 +pluginVersion = 1.1.4 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 211.1 diff --git a/src/main/kotlin/com/cycode/plugin/annotators/CycodeAnnotator.kt b/src/main/kotlin/com/cycode/plugin/annotators/CycodeAnnotator.kt index 2a53acb..bf7f6a1 100644 --- a/src/main/kotlin/com/cycode/plugin/annotators/CycodeAnnotator.kt +++ b/src/main/kotlin/com/cycode/plugin/annotators/CycodeAnnotator.kt @@ -7,6 +7,7 @@ import com.cycode.plugin.cli.getPackageFileForLockFile import com.cycode.plugin.cli.isSupportedLockFile import com.cycode.plugin.intentions.CycodeIgnoreIntentionQuickFix import com.cycode.plugin.intentions.CycodeIgnoreType +import com.cycode.plugin.services.ScanResultsService import com.cycode.plugin.services.scanResults import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.ExternalAnnotator @@ -17,7 +18,9 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiFile class CycodeAnnotator : DumbAware, ExternalAnnotator() { - private val scanResults = scanResults() + private fun getScanResults(psiFile: PsiFile): ScanResultsService { + return scanResults(psiFile.project) + } override fun collectInformation(file: PsiFile): PsiFile = file override fun doAnnotate(psiFile: PsiFile?) {} @@ -38,6 +41,7 @@ class CycodeAnnotator : DumbAware, ExternalAnnotator() { } private fun validateSecretTextRange(textRange: TextRange, psiFile: PsiFile): Boolean { + val scanResults = getScanResults(psiFile) val detectedSubstr = psiFile.text.substring(textRange.startOffset, textRange.endOffset) val detectedSegment = scanResults.getDetectedSegment(CliScanType.Secret, textRange) if (detectedSegment == null) { @@ -83,6 +87,7 @@ class CycodeAnnotator : DumbAware, ExternalAnnotator() { } private fun applyAnnotationsForSecrets(psiFile: PsiFile, holder: AnnotationHolder) { + val scanResults = getScanResults(psiFile) val latestScanResult = scanResults.getSecretResults() if (latestScanResult !is CliResult.Success) { return @@ -153,6 +158,7 @@ class CycodeAnnotator : DumbAware, ExternalAnnotator() { } private fun applyAnnotationsForSca(psiFile: PsiFile, holder: AnnotationHolder) { + val scanResults = getScanResults(psiFile) val latestScanResult = scanResults.getScaResults() if (latestScanResult !is CliResult.Success) { return diff --git a/src/main/kotlin/com/cycode/plugin/cli/models/scanResult/secret/SecretDetectionDetails.kt b/src/main/kotlin/com/cycode/plugin/cli/models/scanResult/secret/SecretDetectionDetails.kt index 85b6366..8c2977d 100644 --- a/src/main/kotlin/com/cycode/plugin/cli/models/scanResult/secret/SecretDetectionDetails.kt +++ b/src/main/kotlin/com/cycode/plugin/cli/models/scanResult/secret/SecretDetectionDetails.kt @@ -12,7 +12,7 @@ data class SecretDetectionDetails( val committedAt: String, // TODO(MarshalX): actually DateTime. annotate? val filePath: String, val fileName: String, - val fileExtension: String, + val fileExtension: String?, val customRemediationGuidelines: String?, var detectedValue: String? = null, // custom field out of CLI JSON schema. TODO(MarshalX): add from CLI side? ) : ScanDetectionDetailsBase { diff --git a/src/main/kotlin/com/cycode/plugin/intentions/CycodeIgnoreIntentionQuickFix.kt b/src/main/kotlin/com/cycode/plugin/intentions/CycodeIgnoreIntentionQuickFix.kt index de8302a..aa1585c 100644 --- a/src/main/kotlin/com/cycode/plugin/intentions/CycodeIgnoreIntentionQuickFix.kt +++ b/src/main/kotlin/com/cycode/plugin/intentions/CycodeIgnoreIntentionQuickFix.kt @@ -26,8 +26,6 @@ class CycodeIgnoreIntentionQuickFix( private val value: String ) : BaseIntentionAction(), PriorityAction, Iconable { - private val scanResults = scanResults() - override fun getText(): String { with(type) { return when (this) { @@ -57,6 +55,7 @@ class CycodeIgnoreIntentionQuickFix( private fun applyIgnoreInUi(project: Project) { // exclude results from the local DB and restart the code analyzer + val scanResults = scanResults(project) when (type) { CycodeIgnoreType.VALUE -> scanResults.excludeResults(byValue = value) CycodeIgnoreType.RULE -> scanResults.excludeResults(byRuleId = value) diff --git a/src/main/kotlin/com/cycode/plugin/services/CliService.kt b/src/main/kotlin/com/cycode/plugin/services/CliService.kt index 2c23f4d..c919397 100644 --- a/src/main/kotlin/com/cycode/plugin/services/CliService.kt +++ b/src/main/kotlin/com/cycode/plugin/services/CliService.kt @@ -22,7 +22,7 @@ class CliService(private val project: Project) { private val pluginState = pluginState() private val pluginSettings = pluginSettings() - private val scanResults = scanResults() + private val scanResults = scanResults(project) private val cli = CliWrapper(pluginSettings.cliPath, getProjectRootDirectory())