Add property to protect sensitive data in http reports

#KT-53773 Fixed
This commit is contained in:
nataliya.valtman
2022-08-29 15:22:19 +02:00
committed by Space
parent 35116696b2
commit d22cccdc4d
5 changed files with 36 additions and 13 deletions
@@ -97,6 +97,9 @@ internal class PropertiesProvider private constructor(private val project: Proje
val buildReportHttpPassword: String?
get() = this.property("kotlin.build.report.http.password")
val buildReportHttpVerboseEnvironment: Boolean
get() = property("kotlin.build.report.http.verbose_environment")?.toBoolean() ?: false
val buildReportBuildScanCustomValuesLimit: Int
get() = property("kotlin.build.report.build_scan.custom_values_limit")?.toInt() ?: 1000
@@ -12,6 +12,7 @@ import java.text.SimpleDateFormat
import java.util.*
//Sensitive data. This object is used directly for statistic via http
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC")}
data class CompileStatisticsData(
val version: Int = 2,
val projectName: String?,
@@ -32,11 +33,8 @@ data class CompileStatisticsData(
val buildTimesMetrics: Map<BuildTime, Long>,
val performanceMetrics: Map<BuildPerformanceMetric, Long>,
val type: String = BuildDataType.TASK_DATA.name
) {
companion object {
private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC")}
}
}
)
enum class StatTag {
ABI_SNAPSHOT,
@@ -58,7 +56,7 @@ enum class BuildDataType {
data class GradleBuildStartParameters(
val tasks: List<String>,
val excludedTasks: Set<String>,
val currentDir: String,
val currentDir: String?,
val projectProperties: List<String>,
val systemProperties: List<String>,
) : java.io.Serializable
@@ -70,7 +68,10 @@ data class BuildFinishStatisticsData(
val buildUuid: String = "Unset",
val label: String?,
val totalTime: Long,
val type: String = BuildDataType.BUILD_DATA.name
val type: String = BuildDataType.BUILD_DATA.name,
val finishTime: Long,
val timestamp: String = formatter.format(finishTime),
val hostName: String? = "Unset",
)
@@ -93,7 +93,7 @@ abstract class BuildReportsService : BuildService<BuildReportsService.Parameters
}
//It's expected that bad internet connection can cause a significant delay for big project
executorService.shutdownNow()
executorService.shutdown()
}
override fun onFinish(event: FinishEvent?) {
@@ -111,16 +111,34 @@ abstract class BuildReportsService : BuildService<BuildReportsService.Parameters
}
private fun reportBuildFinish() {
val finishTime = System.nanoTime()
val buildFinishData = BuildFinishStatisticsData(
projectName = parameters.projectName.get(),
startParameters = parameters.startParameters.get(),
startParameters = parameters.startParameters.get()
.includeVerboseEnvironment(parameters.reportingSettings.get().httpReportSettings?.verboseEnvironment ?: false),
buildUuid = buildUuid,
label = parameters.label.orNull,
totalTime = (System.nanoTime() - startTime) / 1_000_000
totalTime = (finishTime - startTime) / 1_000_000,
finishTime = finishTime,
hostName = hostName
)
sendDataViaHttp(buildFinishData)
}
private fun GradleBuildStartParameters.includeVerboseEnvironment(verboseEnvironment: Boolean): GradleBuildStartParameters {
return if (verboseEnvironment) {
this
} else {
GradleBuildStartParameters(
tasks = this.tasks,
excludedTasks = this.excludedTasks,
currentDir = null,
projectProperties = emptyList(),
systemProperties = emptyList()
)
}
}
private fun addHttpReport(event: FinishEvent?) {
if (parameters.reportingSettings.get().httpReportSettings != null) {
if (event is TaskFinishEvent) {
@@ -34,7 +34,8 @@ data class FileReportSettings(
data class HttpReportSettings(
val url: String,
val password: String?,
val user: String?
val user: String?,
val verboseEnvironment: Boolean
) : Serializable {
companion object {
const val serialVersionUID: Long = 0
@@ -42,7 +43,7 @@ data class HttpReportSettings(
}
data class BuildScanSettings(
val customValueLimit: Int
val customValueLimit: Int,
): Serializable {
companion object {
const val serialVersionUID: Long = 0
@@ -32,7 +32,7 @@ internal fun reportingSettings(rootProject: Project): ReportingSettings {
?: throw IllegalStateException("Can't configure http report: '${properties.buildReportHttpUrlProperty}' property is mandatory")
val password = properties.buildReportHttpPassword
val user = properties.buildReportHttpUser
HttpReportSettings(url, password, user)
HttpReportSettings(url, password, user, properties.buildReportHttpVerboseEnvironment)
} else {
null
}