Skip to content

Commit

Permalink
fix: remove remnants of false positive feature [IDE-134] (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Mar 4, 2024
1 parent c24b7ff commit b541b58
Show file tree
Hide file tree
Showing 15 changed files with 1 addition and 585 deletions.
3 changes: 0 additions & 3 deletions src/main/kotlin/io/snyk/plugin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ fun isFileListenerEnabled(): Boolean = pluginSettings().fileListenerEnabled

fun isSnykCodeLSEnabled(): Boolean = Registry.`is`("snyk.preview.snyk.code.ls.enabled", true)

fun isReportFalsePositivesEnabled(): Boolean = Registry.`is`("snyk.code.report.false.positives.enabled", false) &&
pluginSettings().reportFalsePositivesEnabled == true

fun getWaitForResultsTimeout(): Long =
Registry.intValue(
"snyk.timeout.results.waiting",
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/io/snyk/plugin/net/CliConfigService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ data class CliConfigSettings(

@SerializedName("localCodeEngine")
val localCodeEngine: LocalCodeEngine,

@SerializedName("reportFalsePositivesEnabled")
val reportFalsePositivesEnabled: Boolean
)

data class CliConfigSettingsError(
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/kotlin/io/snyk/plugin/net/SnykApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ class SnykApiClient(
) {
private val cliConfigServiceEndpoint: CliConfigService = retrofit.create(CliConfigService::class.java)
private val userServiceEndpoint: UserService = retrofit.create(UserService::class.java)
private val reportFalsePositiveEndpoint: ReportFalsePositiveRetrofitService =
retrofit.create(ReportFalsePositiveRetrofitService::class.java)

fun getUserId(): String? = executeRequest(UserService.apiName, userServiceEndpoint.userMe())?.id

fun sastSettings(org: String? = null): CliConfigSettings? =
executeRequest(CliConfigService.apiName, cliConfigServiceEndpoint.sast(org))

fun reportFalsePositive(payload: FalsePositivePayload): Boolean =
executeRequest(ReportFalsePositiveRetrofitService.apiName, reportFalsePositiveEndpoint.report(payload)) != null

private fun <T> executeRequest(apiName: String, retrofitCall: Call<T>, retryCounter: Int = 2): T? {
if (retryCounter < 0) return null
return try {
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/io/snyk/plugin/services/SnykApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.snyk.plugin.services
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import io.snyk.plugin.net.CliConfigSettings
import io.snyk.plugin.net.FalsePositivePayload
import io.snyk.plugin.net.RetrofitClientFactory
import io.snyk.plugin.net.SnykApiClient
import io.snyk.plugin.pluginSettings
Expand All @@ -20,9 +19,6 @@ class SnykApiService {
val userId: String?
get() = getSnykApiClient()?.getUserId()

fun reportFalsePositive(payload: FalsePositivePayload): Boolean =
getSnykApiClient()?.reportFalsePositive(payload) ?: false

private fun getSnykApiClient(): SnykApiClient? {
if (pluginSettings().token.isNullOrBlank()) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class SnykApplicationSettingsStateService : PersistentStateComponent<SnykApplica
var sastSettingsError: Boolean? = null
var localCodeEngineEnabled: Boolean? = null
var localCodeEngineUrl: String? = ""
var reportFalsePositivesEnabled: Boolean? = null
var usageAnalyticsEnabled = true
var crashReportingEnabled = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class SnykTaskQueueService(val project: Project) {
settings.sastOnServerEnabled = sastCliConfigSettings?.sastEnabled
settings.localCodeEngineEnabled = sastCliConfigSettings?.localCodeEngine?.enabled
settings.localCodeEngineUrl = sastCliConfigSettings?.localCodeEngine?.url
settings.reportFalsePositivesEnabled = sastCliConfigSettings?.reportFalsePositivesEnabled
when (settings.sastOnServerEnabled) {
true -> {
getSnykCode(project)?.scan()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,25 @@ import ai.deepcode.javaclient.core.SuggestionForFile
import ai.deepcode.javaclient.responses.ExampleCommitFix
import com.intellij.icons.AllIcons
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import com.intellij.ui.HyperlinkLabel
import com.intellij.ui.ScrollPaneFactory
import com.intellij.ui.components.JBTabbedPane
import com.intellij.uiDesigner.core.GridConstraints
import com.intellij.uiDesigner.core.GridLayoutManager
import com.intellij.util.ui.JBInsets
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import io.snyk.plugin.getSnykApiService
import io.snyk.plugin.isReportFalsePositivesEnabled
import io.snyk.plugin.navigateToSource
import io.snyk.plugin.net.FalsePositiveContext
import io.snyk.plugin.net.FalsePositivePayload
import io.snyk.plugin.snykcode.core.PDU
import io.snyk.plugin.snykcode.core.SnykCodeFile
import io.snyk.plugin.snykcode.getSeverityAsEnum
import io.snyk.plugin.ui.DescriptionHeaderPanel
import io.snyk.plugin.ui.SnykBalloonNotificationHelper
import io.snyk.plugin.ui.baseGridConstraintsAnchorWest
import io.snyk.plugin.ui.descriptionHeaderPanel
import io.snyk.plugin.ui.panelGridConstraints
import io.snyk.plugin.ui.toolwindow.ReportFalsePositiveDialog
import io.snyk.plugin.ui.toolwindow.ReportFalsePositiveDialog.Companion.FALSE_POSITIVE_REPORTED_TEXT
import io.snyk.plugin.ui.toolwindow.ReportFalsePositiveDialog.Companion.REPORT_FALSE_POSITIVE_TEXT
import java.awt.Color
import java.awt.Dimension
import java.awt.Font
import java.awt.Insets
import javax.swing.JButton
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
Expand Down Expand Up @@ -389,64 +378,4 @@ class SuggestionDescriptionPanel(
private fun getOverviewText(): String {
return suggestion.message
}

override fun getBottomRightButtons(): List<JButton> = mutableListOf<JButton>()
.apply {
if (isReportFalsePositivesEnabled()) add(reportFalsePositiveButton)
}
.toList()

private val reportFalsePositiveButton: JButton
get() = JButton(REPORT_FALSE_POSITIVE_TEXT).apply {
addActionListener {
val dialog = ReportFalsePositiveDialog(
project,
titlePanel(insets = JBUI.insetsBottom(10), indent = 0),
getRelatedPsiFiles()
)
if (dialog.showAndGet()) {
val payload = FalsePositivePayload(
topic = "False Positive",
message = suggestion.message,
context = FalsePositiveContext(
issueId = suggestion.id,
userPublicId = getSnykApiService().userId ?: "",
startLine = suggestionRange?.startRow ?: 1,
endLine = suggestionRange?.endRow ?: 1,
primaryFilePath = snykCodeFile.virtualFile.path,
vulnName = suggestion.rule,
fileContents = dialog.result
)
)
if (getSnykApiService().reportFalsePositive(payload)) {
this.isEnabled = false
this.text = FALSE_POSITIVE_REPORTED_TEXT
SnykBalloonNotificationHelper.showInfo(
"False Positive reported. Thank you!",
project
)
// todo(?): disable re-report per session/project/application/token/org
} else {
SnykBalloonNotificationHelper.showError(
"Unable to send report, please contact support@snyk.io for assistance",
project
)
}
}
}
}

private fun getRelatedPsiFiles(): Set<PsiFile> {
val markersWithUniqFiles = suggestionRange?.let { range ->
range.markers.values.flatten().distinctBy { it.file }
}
val filesFromMarkers: Set<SnykCodeFile> = markersWithUniqFiles
?.mapNotNull { PDU.instance.getFileByDeepcodedPath(it.file, project) }
?.map { PDU.toSnykCodeFile(it) }
?.toSet()
?: emptySet()
return (setOf(snykCodeFile) + filesFromMarkers)
.mapNotNull { PDU.toPsiFile(it) }
.toSet()
}
}
Loading

0 comments on commit b541b58

Please sign in to comment.