From 4b0e93860a6b6dc4e6f94d91894e36fbc277e442 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Wed, 4 Oct 2023 11:58:33 +0200 Subject: [PATCH] feat: add baseURL as parameter to settings --- .../services/SnykApplicationSettingsStateService.kt | 1 + .../snyk/plugin/services/download/CliDownloader.kt | 13 +++++++++---- .../settings/SnykProjectSettingsConfigurable.kt | 4 +++- .../kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt | 12 ++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/services/SnykApplicationSettingsStateService.kt b/src/main/kotlin/io/snyk/plugin/services/SnykApplicationSettingsStateService.kt index cf11f82cc..b2c73ec30 100644 --- a/src/main/kotlin/io/snyk/plugin/services/SnykApplicationSettingsStateService.kt +++ b/src/main/kotlin/io/snyk/plugin/services/SnykApplicationSettingsStateService.kt @@ -27,6 +27,7 @@ import java.util.UUID ) class SnykApplicationSettingsStateService : PersistentStateComponent { + var cliBaseDownloadURL: String = "https://static.snyk.io" var cliPath: String = getPluginPath() + separator + Platform.current().snykWrapperFileName var manageBinariesAutomatically: Boolean = true var fileListenerEnabled: Boolean = true diff --git a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt index 962ba5e50..7f2b83836 100644 --- a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt +++ b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt @@ -2,6 +2,7 @@ package io.snyk.plugin.services.download import com.intellij.openapi.progress.ProgressIndicator import io.snyk.plugin.cli.Platform +import io.snyk.plugin.pluginSettings import io.snyk.plugin.services.download.HttpRequestHelper.createRequest import java.io.File import java.nio.file.AtomicMoveNotSupportedException @@ -13,10 +14,14 @@ import javax.xml.bind.DatatypeConverter class CliDownloader { companion object { - const val BASE_URL = "https://static.snyk.io" - const val LATEST_RELEASES_URL = "$BASE_URL/cli/latest/version" - val LATEST_RELEASE_DOWNLOAD_URL = "$BASE_URL/cli/latest/${Platform.current().snykWrapperFileName}" - val SHA256_DOWNLOAD_URL = "$BASE_URL/cli/latest/${Platform.current().snykWrapperFileName}.sha256" + val BASE_URL: String + get() = pluginSettings().cliBaseDownloadURL + val LATEST_RELEASES_URL: String + get() = "$BASE_URL/cli/latest/version" + val LATEST_RELEASE_DOWNLOAD_URL: String + get() = "$BASE_URL/cli/latest/${Platform.current().snykWrapperFileName}" + val SHA256_DOWNLOAD_URL: String + get() = "$BASE_URL/cli/latest/${Platform.current().snykWrapperFileName}.sha256" } fun calculateSha256(bytes: ByteArray): String { diff --git a/src/main/kotlin/io/snyk/plugin/settings/SnykProjectSettingsConfigurable.kt b/src/main/kotlin/io/snyk/plugin/settings/SnykProjectSettingsConfigurable.kt index a6c1bac0e..d32f32ea8 100644 --- a/src/main/kotlin/io/snyk/plugin/settings/SnykProjectSettingsConfigurable.kt +++ b/src/main/kotlin/io/snyk/plugin/settings/SnykProjectSettingsConfigurable.kt @@ -45,7 +45,8 @@ class SnykProjectSettingsConfigurable(val project: Project) : SearchableConfigur snykSettingsDialog.isScanTypeChanged() || snykSettingsDialog.isSeverityEnablementChanged() || snykSettingsDialog.manageBinariesAutomatically() != settingsStateService.manageBinariesAutomatically || - snykSettingsDialog.getCliPath() != settingsStateService.cliPath + snykSettingsDialog.getCliPath() != settingsStateService.cliPath || + snykSettingsDialog.getCliBaseDownloadURL() != settingsStateService.cliBaseDownloadURL private fun isCoreParamsModified() = isTokenModified() || isCustomEndpointModified() || @@ -83,6 +84,7 @@ class SnykProjectSettingsConfigurable(val project: Project) : SearchableConfigur settingsStateService.manageBinariesAutomatically = snykSettingsDialog.manageBinariesAutomatically() settingsStateService.cliPath = snykSettingsDialog.getCliPath().trim() + settingsStateService.cliBaseDownloadURL = snykSettingsDialog.getCliBaseDownloadURL().trim() snykSettingsDialog.saveScanTypeChanges() snykSettingsDialog.saveSeveritiesEnablementChanges() diff --git a/src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt b/src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt index 61fc4aea6..55bbc99a1 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt @@ -78,6 +78,7 @@ class SnykSettingsDialog( private val manageBinariesAutomatically: JCheckBox = JCheckBox() private val cliPathTextBoxWithFileBrowser = TextFieldWithBrowseButton() + private val cliBaseDownloadUrlTextField = JTextField() private val logger = Logger.getInstance(this::class.java) @@ -126,6 +127,7 @@ class SnykSettingsDialog( manageBinariesAutomatically.isSelected = applicationSettings.manageBinariesAutomatically cliPathTextBoxWithFileBrowser.text = applicationSettings.cliPath + cliBaseDownloadUrlTextField.text = applicationSettings.cliBaseDownloadURL additionalParametersTextField.text = applicationSettings.getAdditionalParameters(project) } } @@ -463,6 +465,15 @@ class SnykSettingsDialog( ) ) + cliBaseDownloadUrlTextField.toolTipText = "The default URL is https://static.snyk.io. " + + "for FIPS-enabled CLIs (only available for Windows and Linux), please use https://static.snyk.io/fips" + executableSettingsPanel.add( + UI.PanelFactory + .panel(cliBaseDownloadUrlTextField) + .withLabel("Base URL to download the CLI: ").createPanel(), + gb.nextLine() + ) + cliPathTextBoxWithFileBrowser.toolTipText = "The default path is ${getCliFile().canonicalPath}." val descriptor = FileChooserDescriptor(true, false, false, false, false, false) cliPathTextBoxWithFileBrowser.addBrowseFolderListener( @@ -564,4 +575,5 @@ class SnykSettingsDialog( fun getCliPath(): String = cliPathTextBoxWithFileBrowser.text fun manageBinariesAutomatically() = manageBinariesAutomatically.isSelected + fun getCliBaseDownloadURL(): String = cliBaseDownloadUrlTextField.text }