-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't hand the keys to the kingdom to plugin scripts
- Loading branch information
1 parent
64bdb22
commit 51c60bc
Showing
3 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
components/script-execution/src/main/kotlin/vdi/components/script/environment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package vdi.components.script | ||
|
||
/** | ||
* Array of environment variables that are 'safe' to pass through to the plugin | ||
* scripts. | ||
* | ||
* Any environment variable that does not appear in this array will not be | ||
* passed through from the server environment to the plugin environment. | ||
*/ | ||
private val SafeKeys = arrayOf( | ||
"_", | ||
"GUS_HOME", | ||
"HOSTNAME", | ||
"JAVA_HOME", | ||
"LANG", | ||
"LD_LIBRARY_PATH", | ||
"ORACLE_HOME", | ||
"PATH", | ||
"SITE_BUILD", | ||
"TEMPLATE_DB_NAME", | ||
"TEMPLATE_DB_USER", | ||
"TZ", | ||
) | ||
|
||
private val BaseMap: Map<String, String> = HashMap<String, String>(SafeKeys.size) | ||
.apply { SafeKeys.forEach { key -> System.getenv(key)?.also { put(key, it) } } } | ||
|
||
/** | ||
* Executes the given function with a mutable copy of the available, safe | ||
* environment variables | ||
* | ||
* @param T Type of the value returned by the given function. | ||
* | ||
* @param fn Function to execute with a safe, mutable environment map. | ||
* | ||
* @return The value returned by fn. | ||
*/ | ||
inline fun <T> withScriptEnvironment(fn: (env: MutableMap<String, String>) -> T) = fn(cloneEnvironment()) | ||
|
||
/** | ||
* Creates a mutable copy of the safe environment variables. | ||
*/ | ||
fun cloneEnvironment(): MutableMap<String, String> = HashMap<String, String>(24).apply { putAll(BaseMap) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ include( | |
":components:script-execution", | ||
) | ||
|
||
include(":service") | ||
include(":service") |