Skip to content
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

Add support for Vault agent environment variables | VAULT-16059 #1741

Merged
merged 11 commits into from
May 9, 2023
22 changes: 20 additions & 2 deletions config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ type TemplateConfig struct {
// and causes an error if a relative path tries to traverse outside that
// prefix.
SandboxPath *string `mapstructure:"sandbox_path"`

// MapToEnvironmentVariable is the name of the environment variable
// this template config should map back to
// only applicable used when consul-template is used as a library
dhuckins marked this conversation as resolved.
Show resolved Hide resolved
MapToEnvironmentVariable *string `mapstructure:"-"`
}

// DefaultTemplateConfig returns a configuration that is populated with the
Expand Down Expand Up @@ -184,6 +189,8 @@ func (c *TemplateConfig) Copy() *TemplateConfig {

o.SandboxPath = c.SandboxPath

o.MapToEnvironmentVariable = c.MapToEnvironmentVariable

return &o
}

Expand Down Expand Up @@ -288,6 +295,10 @@ func (c *TemplateConfig) Merge(o *TemplateConfig) *TemplateConfig {
r.SandboxPath = o.SandboxPath
}

if o.MapToEnvironmentVariable != nil {
r.MapToEnvironmentVariable = o.MapToEnvironmentVariable
}

return r
}

Expand Down Expand Up @@ -410,7 +421,8 @@ func (c *TemplateConfig) GoString() string {
"LeftDelim:%s, "+
"RightDelim:%s, "+
"FunctionDenylist:%s, "+
"SandboxPath:%s"+
"SandboxPath:%s "+
"MapToEnvironmentVariable:%s"+
"}",
BoolGoString(c.Backup),
c.Command,
Expand All @@ -428,6 +440,7 @@ func (c *TemplateConfig) GoString() string {
StringGoString(c.RightDelim),
combineLists(c.FunctionDenylist, c.FunctionDenylistDeprecated),
StringGoString(c.SandboxPath),
StringGoString(c.MapToEnvironmentVariable),
)
}

Expand All @@ -444,9 +457,14 @@ func (c *TemplateConfig) Display() string {
source = String("(dynamic)")
}

destination := c.Destination
if StringPresent(c.MapToEnvironmentVariable) {
destination = c.MapToEnvironmentVariable
}

return fmt.Sprintf("%q => %q",
StringVal(source),
StringVal(c.Destination),
StringVal(destination),
)
}

Expand Down