Skip to content

Commit

Permalink
feat: add baseURL as parameter to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Oct 4, 2023
1 parent 9d08422 commit 4b0e938
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.util.UUID
)
class SnykApplicationSettingsStateService : PersistentStateComponent<SnykApplicationSettingsStateService> {

var cliBaseDownloadURL: String = "https://static.snyk.io"
var cliPath: String = getPluginPath() + separator + Platform.current().snykWrapperFileName
var manageBinariesAutomatically: Boolean = true
var fileListenerEnabled: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -126,6 +127,7 @@ class SnykSettingsDialog(
manageBinariesAutomatically.isSelected = applicationSettings.manageBinariesAutomatically

cliPathTextBoxWithFileBrowser.text = applicationSettings.cliPath
cliBaseDownloadUrlTextField.text = applicationSettings.cliBaseDownloadURL
additionalParametersTextField.text = applicationSettings.getAdditionalParameters(project)
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -564,4 +575,5 @@ class SnykSettingsDialog(

fun getCliPath(): String = cliPathTextBoxWithFileBrowser.text
fun manageBinariesAutomatically() = manageBinariesAutomatically.isSelected
fun getCliBaseDownloadURL(): String = cliBaseDownloadUrlTextField.text
}

0 comments on commit 4b0e938

Please sign in to comment.