Skip to content

Commit

Permalink
feat: scan all products on startup if enabled (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu authored Apr 10, 2024
1 parent 0f33277 commit b532c4c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added
- force download of compatible CLI on mismatched LS protocol versions
- bumped LS protocol version to ensure built-in LS in CLI has necessary commands for global ignores
- (LS Preview) trigger scan on startup if auto-scan is enabled in Settings

## [2.7.13]
### Added
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/io/snyk/plugin/SnykPostStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class SnykPostStartupActivity : ProjectActivity {
getAmplitudeExperimentService().fetch(experimentUser)

if (isContainerEnabled()) {
getKubernetesImageCache(project)?.scanProjectForKubernetesFiles()
getKubernetesImageCache(project)?.cacheKubernetesFileFromProject()
}

if (settings.scanOnSave && isSnykCodeLSEnabled()) {
getSnykTaskQueueService(project)?.scan()
}

ExtensionPointsUtil.controllerManager.extensionList.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ScanTypesPanel(
correctLastProductDisabled(it)
settings.containerScanEnabled = this.isSelected
val imagesCache = getKubernetesImageCache(project)
if (this.isSelected) imagesCache?.scanProjectForKubernetesFiles() else imagesCache?.clear()
if (this.isSelected) imagesCache?.cacheKubernetesFileFromProject() else imagesCache?.clear()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class SnykToolWindowPanel(val project: Project) : JPanel(), Disposable {
if (isContainerEnabled()) {
getKubernetesImageCache(project)?.let {
it.clear()
it.scanProjectForKubernetesFiles()
it.cacheKubernetesFileFromProject()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/snyk/container/KubernetesImageCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KubernetesImageCache(val project: Project) {
images.clear()
}

fun scanProjectForKubernetesFiles() {
fun cacheKubernetesFileFromProject() {
val callable = Callable {
ProjectRootManager.getInstance(project).fileIndex.iterateContent { virtualFile ->
extractFromFileAndAddToCache(virtualFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class ScanTypesPanelTest : LightPlatform4TestCase() {
@Test
fun `KubernetesImageCache rescan after container enablement`() {
val cacheMock = setUpContainerScanTypePanelTests()
justRun { cacheMock.scanProjectForKubernetesFiles() }
justRun { cacheMock.cacheKubernetesFileFromProject() }

getContainerCheckBox(initialValue = false, switchSelection = true)

verify(exactly = 1) { cacheMock.scanProjectForKubernetesFiles() }
verify(exactly = 1) { cacheMock.cacheKubernetesFileFromProject() }
}

@Test
Expand Down

0 comments on commit b532c4c

Please sign in to comment.