diff --git a/.gitignore b/.gitignore index de81b0db..c4ebdc05 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ *.iml out/ +# Visual Studio Code +.vscode/ + # Gradle .gradle/ build/ + diff --git a/docs/config-from-project-properties.adoc b/docs/config-from-project-properties.adoc index ede29579..7185f827 100644 --- a/docs/config-from-project-properties.adoc +++ b/docs/config-from-project-properties.adoc @@ -74,6 +74,10 @@ number of seconds (e.g. `210`). Defaults to `$rootDir/.gradle/helm/cache`. | icon:check[] +| `helm.suppressEnvironmentLogging` +| If true, do not log the gradle environment at Info level. +| + |=== diff --git a/docs/configure-helm.adoc b/docs/configure-helm.adoc index 232b7ee2..102ea7ef 100644 --- a/docs/configure-helm.adoc +++ b/docs/configure-helm.adoc @@ -45,6 +45,10 @@ The following properties can be set on the `helm` extension in the Gradle build | `remoteTimeout` | Time to wait for any individual Kubernetes operation (like Jobs for hooks). | `--timeout` (on certain commands like `install`, `upgrade` or `uninstall`) + +| `suppressEnvironmentLogging` +| If true, do not log the gradle process environment at Info level. The default is false. +| |=== [NOTE] diff --git a/helm-plugin/api/helm-plugin.api b/helm-plugin/api/helm-plugin.api index 7b7833ec..122d65e4 100644 --- a/helm-plugin/api/helm-plugin.api +++ b/helm-plugin/api/helm-plugin.api @@ -25,6 +25,7 @@ public abstract interface class com/citi/gradle/plugins/helm/command/Configurabl public abstract fun getDebug ()Lorg/gradle/api/provider/Property; public abstract fun getExecutable ()Lorg/gradle/api/provider/Property; public abstract fun getExtraArgs ()Lorg/gradle/api/provider/ListProperty; + public abstract fun getSuppressEnvironmentLogging ()Lorg/gradle/api/provider/Property; public abstract fun getXdgCacheHome ()Lorg/gradle/api/file/DirectoryProperty; public abstract fun getXdgConfigHome ()Lorg/gradle/api/file/DirectoryProperty; public abstract fun getXdgDataHome ()Lorg/gradle/api/file/DirectoryProperty; @@ -74,6 +75,7 @@ public abstract interface class com/citi/gradle/plugins/helm/command/GlobalHelmO public abstract fun getDebug ()Lorg/gradle/api/provider/Provider; public abstract fun getExecutable ()Lorg/gradle/api/provider/Provider; public abstract fun getExtraArgs ()Lorg/gradle/api/provider/Provider; + public abstract fun getSuppressEnvironmentLogging ()Lorg/gradle/api/provider/Provider; public abstract fun getXdgCacheHome ()Lorg/gradle/api/provider/Provider; public abstract fun getXdgConfigHome ()Lorg/gradle/api/provider/Provider; public abstract fun getXdgDataHome ()Lorg/gradle/api/provider/Provider; @@ -111,6 +113,7 @@ public abstract interface class com/citi/gradle/plugins/helm/command/HelmExecSpe public abstract fun flag (Ljava/lang/String;ZZ)V public abstract fun option (Ljava/lang/String;Ljava/lang/Object;)V public abstract fun option (Ljava/lang/String;Lorg/gradle/api/provider/Provider;)V + public abstract fun suppressEnvironmentLogging (Z)V } public final class com/citi/gradle/plugins/helm/command/HelmExecSpec$DefaultImpls { @@ -123,6 +126,7 @@ public final class com/citi/gradle/plugins/helm/command/HelmExecSpec$DefaultImpl public static synthetic fun flag$default (Lcom/citi/gradle/plugins/helm/command/HelmExecSpec;Ljava/lang/String;ZZILjava/lang/Object;)V public static fun option (Lcom/citi/gradle/plugins/helm/command/HelmExecSpec;Ljava/lang/String;Ljava/lang/Object;)V public static fun option (Lcom/citi/gradle/plugins/helm/command/HelmExecSpec;Ljava/lang/String;Lorg/gradle/api/provider/Provider;)V + public static synthetic fun suppressEnvironmentLogging$default (Lcom/citi/gradle/plugins/helm/command/HelmExecSpec;ZILjava/lang/Object;)V } public abstract interface class com/citi/gradle/plugins/helm/command/HelmInstallFromRepositoryOptions : com/citi/gradle/plugins/helm/command/HelmInstallationOptions { @@ -170,6 +174,7 @@ public final class com/citi/gradle/plugins/helm/command/internal/DelegateGlobalH public fun getDebug ()Lorg/gradle/api/provider/Provider; public fun getExecutable ()Lorg/gradle/api/provider/Provider; public fun getExtraArgs ()Lorg/gradle/api/provider/Provider; + public fun getSuppressEnvironmentLogging ()Lorg/gradle/api/provider/Provider; public fun getXdgCacheHome ()Lorg/gradle/api/provider/Provider; public fun getXdgConfigHome ()Lorg/gradle/api/provider/Provider; public fun getXdgDataHome ()Lorg/gradle/api/provider/Provider; @@ -412,6 +417,7 @@ public abstract class com/citi/gradle/plugins/helm/command/tasks/AbstractHelmCom protected final fun getRegistryConfigFile ()Lorg/gradle/api/provider/Provider; protected final fun getRepositoryCacheDir ()Lorg/gradle/api/provider/Provider; protected final fun getRepositoryConfigFile ()Lorg/gradle/api/provider/Provider; + public final fun getSuppressEnvironmentLogging ()Lorg/gradle/api/provider/Provider; public final fun getXdgCacheHome ()Lorg/gradle/api/provider/Provider; public final fun getXdgConfigHome ()Lorg/gradle/api/provider/Provider; public final fun getXdgDataHome ()Lorg/gradle/api/provider/Provider; diff --git a/helm-plugin/build.gradle.kts b/helm-plugin/build.gradle.kts index c169d563..e8272a92 100644 --- a/helm-plugin/build.gradle.kts +++ b/helm-plugin/build.gradle.kts @@ -8,6 +8,7 @@ plugins { alias(libs.plugins.binaryCompatibilityValidator) } +val functionalTest by sourceSets.creating dependencies { @@ -26,10 +27,13 @@ dependencies { testImplementation(libs.unbrokenDomeTestUtils) testImplementation(libs.bundles.defaultTests) testRuntimeOnly(libs.junitEngine) + + "functionalTestImplementation"(project(":plugin-test-utils")) } gradlePlugin { + testSourceSets(functionalTest) plugins { create("helmCommandsPlugin") { id = "com.citi.helm-commands" @@ -50,4 +54,21 @@ gradlePlugin { apiValidation { ignoredPackages.add("com.citi.gradle.plugins.helm.dsl.internal") -} \ No newline at end of file +} + +val functionalTestTask = tasks.register("functionalTest") { + description = "Runs the integration tests." + group = "verification" + testClassesDirs = functionalTest.output.classesDirs + classpath = functionalTest.runtimeClasspath + mustRunAfter(tasks.test) + + val urlOverrideProperty = "com.citi.gradle.helm.plugin.distribution.url.prefix" + findProperty(urlOverrideProperty)?.let { urlOverride -> + systemProperty(urlOverrideProperty, urlOverride) + } +} + +tasks.build { + dependsOn(functionalTestTask) +} diff --git a/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/HelmExecutable.kt b/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/HelmExecutable.kt new file mode 100644 index 00000000..65660c93 --- /dev/null +++ b/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/HelmExecutable.kt @@ -0,0 +1,57 @@ +package com.citi.gradle.plugins.helm.tests.functional + +import java.io.File + +/** + * Helping class creating helm executable that does nothing + * + * Is needed to simulate real helm (we don't need to verify this) and ignore actions done by other parts of a plugin. + */ + +internal object HelmExecutable { + private val helmExecutablesDirectory = File("./src/functionalTest/resources/executable") + private val fileExtension = let { + val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true) + + if (isWindows) { + "bat" + } else { + "sh" + } + } + + private val executableDummyHelm = helmExecutablesDirectory.resolve("helm.$fileExtension") + + /** + * 2. Creates gradle parameter with path to that executable + */ + fun getExecutableParameterForHelm( + temporaryFolder: File + ): HelmExecutableParameter { + + val destinationExecutableFile = temporaryFolder.resolve("helm.$fileExtension") + + executableDummyHelm.copyTo(destinationExecutableFile) + destinationExecutableFile.setExecutable(true) + + return HelmExecutableParameter(destinationExecutableFile) + } + + private fun getAbsoluteNormalizedPath(file: File): String { + return file + .absoluteFile + .normalize() + .path + .replace('\\', '/') + } + + internal class HelmExecutableParameter( + path: File + ) { + val parameterValue = let { + val normalizedFilePath = getAbsoluteNormalizedPath(path) + + "-Phelm.executable=${normalizedFilePath}" + } + } +} \ No newline at end of file diff --git a/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/SuppressEnvironmentLoggingTest.kt b/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/SuppressEnvironmentLoggingTest.kt new file mode 100644 index 00000000..1a56d840 --- /dev/null +++ b/helm-plugin/src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/SuppressEnvironmentLoggingTest.kt @@ -0,0 +1,159 @@ +package com.citi.gradle.plugins.helm.tests.functional + +import com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters +import com.citi.gradle.plugins.helm.plugin.test.utils.GradleRunnerProvider +import io.kotest.matchers.string.shouldContain +import io.kotest.matchers.string.shouldNotContain +import java.io.File +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.io.TempDir +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource + +internal class SuppressEnvironmentLoggingTest { + + private val sourceDirectory = File("./src/functionalTest/resources/test/suppress-environment-logging") + + @TempDir + private lateinit var testProjectDir: File + + @BeforeEach + fun setup() { + sourceDirectory.copyRecursively(target = testProjectDir) + } + + @ParameterizedTest + @MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") + fun doNotSuppressEnvironmentLoggingByDefault(parameters: DefaultGradleRunnerParameters) { + // given + + selectBuildGradle("without-suppress") + + val helmExecutableParameter = + HelmExecutable.getExecutableParameterForHelm(testProjectDir) + + val arguments = listOf( + "helmPackage", + "--info", + helmExecutableParameter.parameterValue + ) + + val gradleRunner = GradleRunnerProvider + .createRunner(parameters) + .withProjectDir(testProjectDir) + .withArguments(arguments) + + // when + val result = gradleRunner.build() + + // then + val output = result.output + + output shouldContain "BUILD SUCCESSFUL" + output shouldContain "with environment:" + output shouldNotContain "(environment logging is suppressed)" + } + + @ParameterizedTest + @MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") + fun suppressEnvironmentLoggingWithCommandLineProperty(parameters: DefaultGradleRunnerParameters) { + // given + + selectBuildGradle("without-suppress") + + val helmExecutableParameter = + HelmExecutable.getExecutableParameterForHelm(testProjectDir) + + val arguments = listOf( + "helmPackage", + "--info", + "-Phelm.suppressEnvironmentLogging=true", + helmExecutableParameter.parameterValue + ) + + val gradleRunner = GradleRunnerProvider + .createRunner(parameters) + .withProjectDir(testProjectDir) + .withArguments(arguments) + + // when + val result = gradleRunner.build() + + // then + val output = result.output + + output shouldContain "BUILD SUCCESSFUL" + output shouldContain "(environment logging is suppressed)" + output shouldNotContain "with environment:" + } + + @ParameterizedTest + @MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") + fun doNotSuppressEnvironmentLoggingWithCommandLineProperty(parameters: DefaultGradleRunnerParameters) { + // given + + selectBuildGradle("without-suppress") + + val helmExecutableParameter = + HelmExecutable.getExecutableParameterForHelm(testProjectDir) + + val arguments = listOf( + "helmPackage", + "--info", + "-Phelm.suppressEnvironmentLogging=false", + helmExecutableParameter.parameterValue + ) + + val gradleRunner = GradleRunnerProvider + .createRunner(parameters) + .withProjectDir(testProjectDir) + .withArguments(arguments) + + // when + val result = gradleRunner.build() + + // then + val output = result.output + + output shouldContain "BUILD SUCCESSFUL" + output shouldContain "with environment:" + output shouldNotContain "(environment logging is suppressed)" + } + + @ParameterizedTest + @MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") + fun suppressEnvironmentLoggingWithDsl(parameters: DefaultGradleRunnerParameters) { + // given + + selectBuildGradle("with-suppress") + + val helmExecutableParameter = + HelmExecutable.getExecutableParameterForHelm(testProjectDir) + + val arguments = listOf( + "helmPackage", + "--info", + helmExecutableParameter.parameterValue + ) + + val gradleRunner = GradleRunnerProvider + .createRunner(parameters) + .withProjectDir(testProjectDir) + .withArguments(arguments) + + // when + val result = gradleRunner.build() + + // then + val output = result.output + + output shouldContain "BUILD SUCCESSFUL" + output shouldContain "(environment logging is suppressed)" + output shouldNotContain "with environment:" + } + + private fun selectBuildGradle(selection: String) { + File(testProjectDir, "build.gradle.$selection") + .copyTo(File(testProjectDir, "build.gradle")) + } +} diff --git a/helm-plugin/src/functionalTest/resources/executable/helm.bat b/helm-plugin/src/functionalTest/resources/executable/helm.bat new file mode 100644 index 00000000..17b1041c --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/executable/helm.bat @@ -0,0 +1 @@ +rem Dummy executable just to simulate real helm diff --git a/helm-plugin/src/functionalTest/resources/executable/helm.sh b/helm-plugin/src/functionalTest/resources/executable/helm.sh new file mode 100644 index 00000000..cf18a00d --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/executable/helm.sh @@ -0,0 +1 @@ +# Dummy executable just to simulate real helm diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.with-suppress b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.with-suppress new file mode 100644 index 00000000..864e6059 --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.with-suppress @@ -0,0 +1,7 @@ +plugins { + id 'com.citi.helm' +} + +helm { + suppressEnvironmentLogging = true +} diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.without-suppress b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.without-suppress new file mode 100644 index 00000000..255fab6a --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/build.gradle.without-suppress @@ -0,0 +1,3 @@ +plugins { + id 'com.citi.helm' +} diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/settings.gradle b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/settings.gradle new file mode 100644 index 00000000..e69de29b diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/Chart.yaml b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/Chart.yaml new file mode 100644 index 00000000..a62c0663 --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: dummy +description: A dummy helm chart +version: 0.0.1 +appVersion: "0.0.1" +type: application diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/templates/pod.yaml b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/templates/pod.yaml new file mode 100644 index 00000000..0e79d8a3 --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/templates/pod.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx +spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/values.yaml b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/values.yaml new file mode 100644 index 00000000..9ce06a81 --- /dev/null +++ b/helm-plugin/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/values.yaml @@ -0,0 +1 @@ +# dummy diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/GlobalHelmOptions.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/GlobalHelmOptions.kt index 3dce09ed..ed716bc7 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/GlobalHelmOptions.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/GlobalHelmOptions.kt @@ -20,6 +20,8 @@ interface GlobalHelmOptions : HelmOptions { val xdgConfigHome: Provider val xdgCacheHome: Provider + + val suppressEnvironmentLogging: Provider } @@ -75,4 +77,11 @@ interface ConfigurableGlobalHelmOptions : GlobalHelmOptions, ConfigurableHelmOpt * See [https://helm.sh/docs/helm/helm/] for details about how XDG base directories are used by the Helm CLI. */ override val xdgCacheHome: DirectoryProperty + + /** + * Indicates whether to suppress logging of the environment when a helm command is executed. When running + * in a containerized system the process environment often contains credentials, keys and other such + * confidential information that should not be logged. + */ + override val suppressEnvironmentLogging: Property } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecProvider.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecProvider.kt index fae79d21..833ee96d 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecProvider.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecProvider.kt @@ -136,11 +136,14 @@ internal class HelmExecProviderSupport( action: Action?, withExecSpec: (ExecSpec.() -> Unit)? = null ) = project.exec { execSpec -> - val helmExecSpec = DefaultHelmExecSpec(execSpec, command, subcommand) + val helmExecSpec = DefaultHelmExecSpec(execSpec, command, subcommand, false) withExecSpec?.invoke(execSpec) applyOptions(helmExecSpec) action?.execute(helmExecSpec) + // execHelmSync has never logged the environment so the default behavior is maintained + // and helmExecSpec.suppressEnvironmentLogging remains unused + if (logger.isInfoEnabled) { logger.info("Executing: {}", maskCommandLine(execSpec.commandLine)) } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecSpec.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecSpec.kt index 2e260ebd..b04081ae 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecSpec.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecSpec.kt @@ -144,6 +144,12 @@ interface HelmExecSpec { * a non-zero exit code. */ fun assertSuccess(assertSuccess: Boolean = true) + + /** + * If false (the default), the contents of the process environment will be dumped to the logs + * when the helm command is launched by the gradle daemon. + */ + fun suppressEnvironmentLogging(suppress: Boolean = false) } @@ -153,7 +159,8 @@ interface HelmExecSpec { internal class DefaultHelmExecSpec( private val execSpec: ExecSpec, command: String, - subcommand: String? + subcommand: String?, + var suppressEnvironmentLogging: Boolean ) : HelmExecSpec { init { @@ -182,4 +189,8 @@ internal class DefaultHelmExecSpec( override fun assertSuccess(assertSuccess: Boolean) { execSpec.isIgnoreExitValue = !assertSuccess } + + override fun suppressEnvironmentLogging(suppress: Boolean) { + suppressEnvironmentLogging = suppress; + } } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkAction.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkAction.kt index 0a26977c..d38bdb39 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkAction.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkAction.kt @@ -30,7 +30,12 @@ internal abstract class HelmExecWorkAction stdout?.let { spec.standardOutput = it } if (logger.isInfoEnabled) { - logger.info("Executing: {}\n with environment: {}", maskCommandLine(spec.commandLine), spec.environment) + if (parameters.suppressEnvironmentLogging.get()) { + logger.info("Executing: {}\n (environment logging is suppressed)", maskCommandLine(spec.commandLine)) + } + else { + logger.info("Executing: {}\n with environment: {}", maskCommandLine(spec.commandLine), spec.environment) + } } } } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkParameters.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkParameters.kt index f5d546c2..70a975cc 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkParameters.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/HelmExecWorkParameters.kt @@ -19,6 +19,8 @@ internal interface HelmExecWorkParameters : WorkParameters { val ignoreExitValue: Property val stdoutFile: RegularFileProperty + + val suppressEnvironmentLogging: Property } @@ -49,4 +51,8 @@ internal class WorkParametersHelmExecSpec( override fun assertSuccess(assertSuccess: Boolean) { params.ignoreExitValue.set(!assertSuccess) } + + override fun suppressEnvironmentLogging(suppress: Boolean) { + params.suppressEnvironmentLogging.set(suppress); + } } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/internal/GlobalHelmOptions.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/internal/GlobalHelmOptions.kt index 0d6ec467..7bb52d24 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/internal/GlobalHelmOptions.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/internal/GlobalHelmOptions.kt @@ -16,6 +16,7 @@ fun ConfigurableGlobalHelmOptions.conventionsFrom(source: GlobalHelmOptions) = a xdgDataHome.convention(source.xdgDataHome) xdgConfigHome.convention(source.xdgConfigHome) xdgCacheHome.convention(source.xdgCacheHome) + suppressEnvironmentLogging.convention(source.suppressEnvironmentLogging) } @@ -40,6 +41,9 @@ class DelegateGlobalHelmOptions( override val xdgCacheHome: Provider get() = provider.flatMap { it.xdgCacheHome } + + override val suppressEnvironmentLogging: Provider + get() = provider.flatMap { it.suppressEnvironmentLogging } } @@ -65,6 +69,8 @@ object GlobalHelmOptionsApplier : HelmOptionsApplier { environment("XDG_DATA_HOME", options.xdgDataHome) environment("XDG_CONFIG_HOME", options.xdgConfigHome) environment("XDG_CACHE_HOME", options.xdgCacheHome) + + suppressEnvironmentLogging(options.suppressEnvironmentLogging.getOrElse(false)) } } } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/tasks/AbstractHelmCommandTask.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/tasks/AbstractHelmCommandTask.kt index 7ab22fd5..e248f8ce 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/tasks/AbstractHelmCommandTask.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/command/tasks/AbstractHelmCommandTask.kt @@ -83,6 +83,10 @@ abstract class AbstractHelmCommandTask get() = globalOptions.flatMap { it.xdgCacheHome } + @get:Internal + final override val suppressEnvironmentLogging: Provider + get() = globalOptions.flatMap { it.suppressEnvironmentLogging } + @get:Internal protected val registryConfigFile: Provider get() = xdgConfigHome.map { it.file("helm/registry.json") } diff --git a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/dsl/HelmExtension.kt b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/dsl/HelmExtension.kt index 3b64c5e2..ea6617fb 100644 --- a/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/dsl/HelmExtension.kt +++ b/helm-plugin/src/main/kotlin/com/citi/gradle/plugins/helm/dsl/HelmExtension.kt @@ -147,6 +147,9 @@ private open class DefaultHelmExtension ) ) + final override val suppressEnvironmentLogging: Property = + objects.property() + .convention(project.booleanProviderFromProjectProperty("helm.suppressEnvironmentLogging")) final override val xdgCacheHome: DirectoryProperty = objects.directoryProperty() diff --git a/helm-plugin/src/test/kotlin/com/citi/gradle/plugins/helm/command/GlobalOptionsTests.kt b/helm-plugin/src/test/kotlin/com/citi/gradle/plugins/helm/command/GlobalOptionsTests.kt index fad35d42..dd9c3da8 100644 --- a/helm-plugin/src/test/kotlin/com/citi/gradle/plugins/helm/command/GlobalOptionsTests.kt +++ b/helm-plugin/src/test/kotlin/com/citi/gradle/plugins/helm/command/GlobalOptionsTests.kt @@ -92,6 +92,12 @@ object GlobalOptionsTests : AbstractOptionsTests({ } } + variant("with suppress environment logging flag") { + beforeEachTest { + project.helm.suppressEnvironmentLogging.set(true) + } + } + variant("with extra args") {