Skip to content

Commit

Permalink
OrtMain: Initialize EnvironmentVariableFilter
Browse files Browse the repository at this point in the history
After loading the configuration, pass the properties related to
filtering environment variables to EnvironmentVariableFilter, so that
they are taken into account when creating new child processes.

Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
  • Loading branch information
oheger-bosch committed Oct 26, 2022
1 parent 79674e5 commit fbde14e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/src/funTest/kotlin/OrtMainFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import java.io.File
import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.utils.common.EnvironmentVariableFilter
import org.ossreviewtoolkit.utils.common.redirectStdout
import org.ossreviewtoolkit.utils.ort.normalizeVcsUrl
import org.ossreviewtoolkit.utils.test.createTestTempDir
Expand Down Expand Up @@ -162,6 +163,17 @@ class OrtMainFunTest : StringSpec() {
)
}
}

"EnvironmentVariableFilter is correctly initialized" {
val referenceConfigFile = File("../model/src/main/resources/reference.yml").absolutePath
runMain(
"-c",
referenceConfigFile,
"config"
)

EnvironmentVariableFilter.acceptVariable("PASSPORT") shouldBe true
}
}

private fun runMain(vararg args: String) =
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/kotlin/OrtMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.ossreviewtoolkit.cli.commands.*
import org.ossreviewtoolkit.cli.utils.logger
import org.ossreviewtoolkit.model.config.LicenseFilenamePatterns
import org.ossreviewtoolkit.model.config.OrtConfiguration
import org.ossreviewtoolkit.utils.common.EnvironmentVariableFilter
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.ort.Environment
Expand Down Expand Up @@ -187,6 +188,11 @@ class OrtMain : CliktCommand(name = ORT_NAME, invokeWithoutSubcommand = true) {
currentContext.findOrSetObject { GlobalOptions(ortConfiguration, forceOverwrite) }
LicenseFilenamePatterns.configure(ortConfiguration.licenseFilePatterns)

EnvironmentVariableFilter.init(
ortConfiguration.environmentVariablesExclusionPatterns,
ortConfiguration.allowedProcessEnvironmentVariables
)

if (helpAll) {
registeredSubcommands().forEach {
println(it.getFormattedHelp())
Expand Down

0 comments on commit fbde14e

Please sign in to comment.