-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass environment variables from host to exec based tasks #970
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package env | |
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
|
@@ -305,6 +306,29 @@ func (t *TaskEnvironment) AppendEnvvars(m map[string]string) *TaskEnvironment { | |
return t | ||
} | ||
|
||
func (t *TaskEnvironment) AppendHostEnvvars(filter []string) *TaskEnvironment { | ||
hostEnv := os.Environ() | ||
if t.Env == nil { | ||
t.Env = make(map[string]string, len(hostEnv)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is always going to be some Env, can we do this in the factory method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That guard is if you are building the map for the first time |
||
} | ||
|
||
// Index the filtered environment variables. | ||
index := make(map[string]struct{}, len(filter)) | ||
for _, f := range filter { | ||
index[f] = struct{}{} | ||
} | ||
|
||
for _, e := range hostEnv { | ||
parts := strings.Split(e, "=") | ||
key, value := parts[0], parts[1] | ||
if _, filtered := index[key]; !filtered { | ||
t.Env[key] = value | ||
} | ||
} | ||
|
||
return t | ||
} | ||
|
||
func (t *TaskEnvironment) ClearEnvvars() *TaskEnvironment { | ||
t.Env = nil | ||
return t | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,6 +370,17 @@ documentation [here](/docs/drivers/index.html) | |
If the whitelist is empty, all drivers are fingerprinted and enabled where | ||
applicable. | ||
|
||
* `env.blacklist`: Nomad passes the host environment variables to `exec`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this an array of strings instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, options is a map[string]string |
||
`raw_exec` and `java` tasks. `env.blacklist` is a comma seperated list of | ||
environment variable keys not to pass to these tasks. If specified, the | ||
defaults are overriden. The following are the default: | ||
|
||
* `CONSUL_TOKEN` | ||
* `VAULT_TOKEN` | ||
* `ATLAS_TOKEN` | ||
* `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | ||
* `GOOGLE_APPLICATION_CREDENTIALS` | ||
|
||
* `fingerprint.whitelist`: A comma separated list of whitelisted fingerprinters. | ||
If specified, fingerprinters not in the whitelist will be disabled. If the | ||
whitelist is empty, all fingerprinters are used. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment