4 Commits

Author SHA1 Message Date
Joachim Hill-Grannec
e0157d9bc2 Merge pull request #84 from BnMcG/noissue-repos-environment-interpolation
Allow environment variable interpolation in Helm repository configuration
2020-03-31 22:29:47 -06:00
Ben Magee
1f2da68bbb Remove built binary 2020-03-31 23:39:02 +01:00
Ben Magee
7e2f982af7 Update docs 2020-03-31 23:33:54 +01:00
Ben Magee
0502d76c63 Interpolate environment variables in the AddRepos configuration parameter 2020-03-31 23:07:28 +01:00
3 changed files with 11 additions and 3 deletions

View File

@@ -95,7 +95,7 @@ values_files: [ "./over_9,000.yml" ]
values_files: [ "./over_9", "000.yml" ] values_files: [ "./over_9", "000.yml" ]
``` ```
### Interpolating secrets into the `values` and `string_values` settings ### Interpolating secrets into the `values`, `string_values` and `add_repos` settings
If you want to send secrets to your charts, you can use syntax similar to shell variable interpolation--either `$VARNAME` or `$${VARNAME}`. The double dollar-sign is necessary when using curly brackets; using curly brackets with a single dollar-sign will trigger Drone's string substitution (which can't use arbitrary environment variables). If an environment variable is not set, it will be treated as if it were set to the empty string. If you want to send secrets to your charts, you can use syntax similar to shell variable interpolation--either `$VARNAME` or `$${VARNAME}`. The double dollar-sign is necessary when using curly brackets; using curly brackets with a single dollar-sign will trigger Drone's string substitution (which can't use arbitrary environment variables). If an environment variable is not set, it will be treated as if it were set to the empty string.

View File

@@ -2,11 +2,12 @@ package env
import ( import (
"fmt" "fmt"
"github.com/kelseyhightower/envconfig"
"io" "io"
"os" "os"
"regexp" "regexp"
"strings" "strings"
"github.com/kelseyhightower/envconfig"
) )
var ( var (
@@ -119,6 +120,10 @@ func (cfg *Config) loadValuesSecrets() {
cfg.Values = findVar.ReplaceAllStringFunc(cfg.Values, replacer) cfg.Values = findVar.ReplaceAllStringFunc(cfg.Values, replacer)
cfg.StringValues = findVar.ReplaceAllStringFunc(cfg.StringValues, replacer) cfg.StringValues = findVar.ReplaceAllStringFunc(cfg.StringValues, replacer)
for i := 0; i < len(cfg.AddRepos); i++ {
cfg.AddRepos[i] = findVar.ReplaceAllStringFunc(cfg.AddRepos[i], replacer)
}
} }
func (cfg Config) logDebug() { func (cfg Config) logDebug() {

View File

@@ -2,10 +2,11 @@ package env
import ( import (
"fmt" "fmt"
"github.com/stretchr/testify/suite"
"os" "os"
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/suite"
) )
type ConfigTestSuite struct { type ConfigTestSuite struct {
@@ -191,12 +192,14 @@ func (suite *ConfigTestSuite) TestNewConfigWithValuesSecrets() {
suite.setenv("SECRET_RINGS", "1") suite.setenv("SECRET_RINGS", "1")
suite.setenv("PLUGIN_VALUES", "fire=$SECRET_FIRE,water=${SECRET_WATER}") suite.setenv("PLUGIN_VALUES", "fire=$SECRET_FIRE,water=${SECRET_WATER}")
suite.setenv("PLUGIN_STRING_VALUES", "rings=${SECRET_RINGS}") suite.setenv("PLUGIN_STRING_VALUES", "rings=${SECRET_RINGS}")
suite.setenv("PLUGIN_ADD_REPOS", "testrepo=https://user:${SECRET_FIRE}@testrepo.test")
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{}) cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
suite.Require().NoError(err) suite.Require().NoError(err)
suite.Equal("fire=Eru_Ilúvatar,water=", cfg.Values) suite.Equal("fire=Eru_Ilúvatar,water=", cfg.Values)
suite.Equal("rings=1", cfg.StringValues) suite.Equal("rings=1", cfg.StringValues)
suite.Equal(fmt.Sprintf("testrepo=https://user:%s@testrepo.test", os.Getenv("SECRET_FIRE")), cfg.AddRepos[0])
} }
func (suite *ConfigTestSuite) TestValuesSecretsWithDebugLogging() { func (suite *ConfigTestSuite) TestValuesSecretsWithDebugLogging() {