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

Commit

Permalink
Merge pull request #114 from bridgecrewio/BCE-36632-Added-additional-…
Browse files Browse the repository at this point in the history
…telemetry

BCE-36632 - Added additional telemetry data to the plugin
  • Loading branch information
ChananM authored Aug 29, 2024
2 parents e931086 + 2cb4001 commit 7b9385b
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 144 deletions.
29 changes: 22 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

# checkov-jetbrains-idea Changelog

## [Unreleased]
## [0.0.11-beta]
## [0.0.10-beta]
## [0.0.9-beta]
## [0.0.6-beta]
## [0.0.5-beta]
## [1.0.21] - 2024-08-29

### Added

- Added the following data to Prisma Cloid analytics

- Extension version
- VS Code version
- Operating system
- Checkov version

### Fixed

- Fixed installation issues with pip when using externally managed python installation
- Stabilized build time of the application and added support for multiple IDE versions
- Fixed various crashes

## [0.0.3-beta]
### Added
* updated platform build range

* Updated platform build range
*

## [0.0.1]
### Added

- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
24 changes: 14 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask

fun properties(key: String) = project.findProperty(key).toString()

plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.8.0"
id("org.jetbrains.kotlin.jvm") version "1.9.25"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.10.1"
id("org.jetbrains.intellij") version "1.17.4"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "1.3.1"
// Gradle Qodana Plugin
id("org.jetbrains.qodana") version "0.1.13"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
kotlin("plugin.serialization") version "1.8.0"
kotlin("plugin.serialization") version "1.9.25"
}

group = properties("pluginGroup")
Expand All @@ -27,21 +28,20 @@ version = properties("pluginVersion")
// Configure project's dependencies
repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation("com.beust:klaxon:5.6")
implementation("com.google.code.gson:gson:2.10.1")
implementation("org.json:json:20230227")
implementation("org.json:json:20231013")
implementation("commons-io:commons-io:2.11.0")
implementation("io.github.java-diff-utils:java-diff-utils:4.12")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testImplementation("org.junit.platform:junit-platform-engine:1.9.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter:5.8.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.0")
}


// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
Expand Down Expand Up @@ -79,6 +79,10 @@ tasks {
}
}

withType<BaseKtLintCheckTask>().configureEach {
enabled = false
}

wrapper {
gradleVersion = properties("gradleVersion")
}
Expand Down Expand Up @@ -142,6 +146,6 @@ tasks {
}

runPluginVerifier {
ideVersions.set(listOf("IC-2020.3.4", "IC-2021.1.3", "IC-2021.2.4"))
ideVersions.set(listOf("IC-2020.3.4", "IC-2021.1.3", "IC-2021.2.4", "IC-2024.1.6"))
}
}
}
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

pluginGroup = com.github.bridgecrewio.prismajetbrainsidea
pluginName = prismacloud-jetbrains-idea
pluginVersion = 1.0.18
pluginSinceBuild = 203
pluginVersion=1.0.21
pluginSinceBuild=241
# 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
pluginVerifierIdeVersions = 2020.3.4, 2021.1.3, 2021.2.4
pluginVerifierIdeVersions=2020.3.4, 2021.1.3, 2021.2.4, 2024.1.6

platformType = IC
platformVersion = 2021.2.4
platformVersion=2024.1.6
platformDownloadSources = true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand All @@ -21,7 +21,7 @@ platformPlugins =
kotlin.stdlib.default.dependency = false

# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion = 11
javaVersion=17

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 7.3
gradleVersion=7.6.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PostStartupActivity : StartupActivity {
project.service<AnalyticsService>().startSchedulerReleasingAnalytics()
// project.service<ResultsCacheService>().setMockCheckovResultsFromExampleFile() // MOCK
}

})

PluginInstaller.addStateListener(object : PluginStateListener {
Expand Down Expand Up @@ -69,4 +68,4 @@ class PostStartupActivity : StartupActivity {
private fun sendAnalyticsPluginUninstalled(project: Project){
project.service<AnalyticsService>().pluginUninstalled()
}
}
}
33 changes: 27 additions & 6 deletions src/main/kotlin/com/bridgecrew/analytics/AnalyticsDataEvents.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package com.bridgecrew.analytics

import com.bridgecrew.cache.InMemCache
import com.bridgecrew.settings.PLUGIN_NAME
import com.bridgecrew.settings.PrismaSettingsState
import com.google.gson.annotations.Expose
import kotlinx.serialization.*
import java.util.*
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.extensions.PluginId
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.json.JsonObject
import java.util.*


@OptIn(ExperimentalSerializationApi::class)
@Serializable
sealed class AnalyticsData(@EncodeDefault val pluginName: String = PLUGIN_NAME){
sealed class AnalyticsData(@EncodeDefault val pluginName: String = PLUGIN_NAME) {

@EncodeDefault
val installationId: String = PrismaSettingsState().getInstance()!!.installationId

@EncodeDefault
var pluginVersion: String? =
PluginManagerCore.getPlugin(PluginId.getId("com.github.bridgecrewio.prismacloud"))?.version

@EncodeDefault
var ideVersion: String? =
ApplicationInfo.getInstance().fullApplicationName + " / " + ApplicationInfo.getInstance().build

@EncodeDefault
var operatingSystem: String? = System.getProperty("os.name") + " " + System.getProperty("os.version")

@EncodeDefault
var checkovVersion: String? = InMemCache.get("checkovVersion")

@Serializable
lateinit var eventType: String

Expand Down Expand Up @@ -51,8 +73,7 @@ data class FullScanAnalyticsData(@Transient val scanNumber: Int = 0): AnalyticsD
@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class PluginInstallAnalyticsData(
@EncodeDefault
override val eventData: JsonObject = JsonObject(mapOf())
@EncodeDefault override val eventData: JsonObject = JsonObject(mapOf())
) : AnalyticsData()

@Serializable
Expand All @@ -63,4 +84,4 @@ data class FullScanFrameworkScanTimeData(
@Serializable(with = DateSerializer::class)
var endTime: Date = Date()
var totalTimeSeconds = 0L
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/com/bridgecrew/analytics/AnalyticsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import kotlinx.serialization.*
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import kotlinx.serialization.json.Json


@Service
Expand Down Expand Up @@ -211,4 +212,4 @@ class AnalyticsService(val project: Project) {
analyticsData.eventType = EventTypeEnum.ON_PLUGIN_UNINSTALL
analyticsEventData.add(Json.encodeToString(analyticsData))
}
}
}
9 changes: 6 additions & 3 deletions src/main/kotlin/com/bridgecrew/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ package com.bridgecrew.api
import com.bridgecrew.settings.DEFAULT_REPORTING_INTERVAL
import com.bridgecrew.settings.PLUGIN_NAME
import com.intellij.openapi.diagnostic.logger
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.IOException
import java.net.URI
import java.net.http.HttpClient
Expand Down Expand Up @@ -135,4 +138,4 @@ class ApiClient(private val username: String, private val password: String, priv
return LoginResponse("")
}
}
}
}
9 changes: 5 additions & 4 deletions src/main/kotlin/com/bridgecrew/cache/CacheDataAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.bridgecrew.cache

import com.intellij.openapi.project.Project

class CacheDataAnalytics (private val project: Project){
fun load(analyticsEventData: MutableList<String>){
class CacheDataAnalytics(private val project: Project) {

fun load(analyticsEventData: MutableList<String>) {
val data = CacheDataAnalyticsStorage(project).readDataFromFile()
if(data.isNullOrEmpty()){
return
Expand All @@ -15,8 +16,8 @@ class CacheDataAnalytics (private val project: Project){
CacheDataAnalyticsStorage(project).clear()
}

fun stash(analyticsEventData: MutableList<String>){
fun stash(analyticsEventData: MutableList<String>) {
val data = analyticsEventData.joinToString("\n")
CacheDataAnalyticsStorage(project).writeDataToFile(data)
}
}
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/bridgecrew/cache/InMemCache.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bridgecrew.cache

object InMemCache {

private val cache: MutableMap<String, String> = mutableMapOf()

fun get(key: String): String? {
return cache[key]
}

fun set(key: String, value: String) {
cache[key] = value
}
}
Loading

0 comments on commit 7b9385b

Please sign in to comment.