Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from bridgecrewio/fix-global-checkov
Browse files Browse the repository at this point in the history
check checkov and checkov.cmd as global commands
  • Loading branch information
orhovy authored Dec 23, 2021
2 parents e0d9bcc + 8fe1cad commit f7cbea3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = com.github.bridgecrewio.checkovjetbrainsidea
pluginName = checkov-jetbrains-idea
pluginVersion = 0.0.14
pluginVersion = 0.0.15
pluginSinceBuild = 201
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import org.apache.commons.io.FilenameUtils
import java.io.File
import java.nio.file.Paths
private val LOG = logger<PipCheckovService>()

Expand All @@ -32,11 +31,13 @@ class PipCheckovService(val project: Project) : CheckovService {
fun setCheckovPath(project: Project){
// check if checkov installed globally
isCheckovInstalledGloablly(project)

// after this check, will check how to run checkov
}
private fun isCheckovInstalledGloablly(project: Project){
val cmds =arrayListOf("checkov.cmd","-v")
project.service<CliService>().run(cmds,project,::updateGlobalCheckov, ::updateGlobalCheckov)
LOG.info("Checking global checkov installation with `checkov`")
val cmds =arrayListOf("checkov","-v")
project.service<CliService>().run(cmds,project,::checkGlobalCheckovCmd, ::checkGlobalCheckovCmd)
}

private fun getPythonUserBasePath(project: Project) {
Expand Down Expand Up @@ -82,7 +83,7 @@ class PipCheckovService(val project: Project) : CheckovService {
}
}

private fun updateGlobalCheckov(output: String, exitCode: Int, project: Project) {
private fun updateCheckovInstalledGlobally(output: String, exitCode: Int, project: Project) {
if (exitCode != 0 || output.contains("[ERROR]")) {
LOG.info("Checkov is not installed globally, running local command")
project.service<CliService>().isCheckovInstalledGlobally = false
Expand All @@ -92,6 +93,18 @@ class PipCheckovService(val project: Project) : CheckovService {
}
getPythonUserBasePath(project)
}

private fun checkGlobalCheckovCmd(output: String, exitCode: Int, project: Project) {
if (exitCode != 0 || output.contains("[ERROR]")) {
LOG.info("Checking global checkov installation with `checkov.cmd`")
val cmds =arrayListOf("checkov.cmd","-v")
project.service<CliService>().run(cmds,project,::updateCheckovInstalledGlobally, ::updateCheckovInstalledGlobally)
} else {
LOG.info("Checkov installed globally, will use it")
project.service<CliService>().isCheckovInstalledGlobally = true
}
getPythonUserBasePath(project)
}
}
}

0 comments on commit f7cbea3

Please sign in to comment.