mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 13:27:18 +02:00
Replace interface{} by any (#901)
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
+18
-18
@@ -22,7 +22,7 @@ import (
|
||||
"github.com/helmfile/helmfile/pkg/yaml"
|
||||
)
|
||||
|
||||
type Values = map[string]interface{}
|
||||
type Values = map[string]any
|
||||
|
||||
var DisableInsecureFeaturesErr = DisableInsecureFeaturesError{envvar.DisableInsecureFeatures + " is active, insecure function calls are disabled"}
|
||||
|
||||
@@ -65,10 +65,10 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||
}
|
||||
if c.preRender || skipInsecureTemplateFunctions {
|
||||
// disable potential side-effect template calls
|
||||
funcMap["exec"] = func(string, []interface{}, ...string) (string, error) {
|
||||
funcMap["exec"] = func(string, []any, ...string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
funcMap["envExec"] = func(map[string]interface{}, string, []interface{}, ...string) (string, error) {
|
||||
funcMap["envExec"] = func(map[string]any, string, []any, ...string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
funcMap["readFile"] = func(string) (string, error) {
|
||||
@@ -83,7 +83,7 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||
}
|
||||
if disableInsecureFeatures {
|
||||
// disable insecure functions
|
||||
funcMap["exec"] = func(string, []interface{}, ...string) (string, error) {
|
||||
funcMap["exec"] = func(string, []any, ...string) (string, error) {
|
||||
return "", DisableInsecureFeaturesErr
|
||||
}
|
||||
funcMap["readFile"] = func(string) (string, error) {
|
||||
@@ -101,7 +101,7 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||
}
|
||||
|
||||
// TODO: in the next major version, remove this function.
|
||||
func (c *Context) EnvExec(envs map[string]interface{}, command string, args []interface{}, inputs ...string) (string, error) {
|
||||
func (c *Context) EnvExec(envs map[string]any, command string, args []any, inputs ...string) (string, error) {
|
||||
var input string
|
||||
if len(inputs) > 0 {
|
||||
input = inputs[0]
|
||||
@@ -192,7 +192,7 @@ func (c *Context) EnvExec(envs map[string]interface{}, command string, args []in
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
||||
func (c *Context) Exec(command string, args []interface{}, inputs ...string) (string, error) {
|
||||
func (c *Context) Exec(command string, args []any, inputs ...string) (string, error) {
|
||||
return c.EnvExec(nil, command, args, inputs...)
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (c *Context) ReadDirEntries(path string) ([]fs.DirEntry, error) {
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
func (c *Context) Tpl(text string, data interface{}) (string, error) {
|
||||
func (c *Context) Tpl(text string, data any) (string, error) {
|
||||
buf, err := c.RenderTemplateToBuffer(text, data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -279,7 +279,7 @@ func (c *Context) Tpl(text string, data interface{}) (string, error) {
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func ToYaml(v interface{}) (string, error) {
|
||||
func ToYaml(v any) (string, error) {
|
||||
data, err := yaml.Marshal(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -288,7 +288,7 @@ func ToYaml(v interface{}) (string, error) {
|
||||
}
|
||||
|
||||
func FromYaml(str string) (Values, error) {
|
||||
m := map[string]interface{}{}
|
||||
m := map[string]any{}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(str), &m); err != nil {
|
||||
return nil, fmt.Errorf("%s, offending yaml: %s", err, str)
|
||||
@@ -302,23 +302,23 @@ func FromYaml(str string) (Values, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func SetValueAtPath(path string, value interface{}, values Values) (Values, error) {
|
||||
var current interface{}
|
||||
func SetValueAtPath(path string, value any, values Values) (Values, error) {
|
||||
var current any
|
||||
current = values
|
||||
components := strings.Split(path, ".")
|
||||
pathToMap := components[:len(components)-1]
|
||||
key := components[len(components)-1]
|
||||
for _, k := range pathToMap {
|
||||
var elem interface{}
|
||||
var elem any
|
||||
|
||||
switch typedCurrent := current.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
v, exists := typedCurrent[k]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
||||
}
|
||||
elem = v
|
||||
case map[interface{}]interface{}:
|
||||
case map[any]any:
|
||||
v, exists := typedCurrent[k]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
||||
@@ -329,7 +329,7 @@ func SetValueAtPath(path string, value interface{}, values Values) (Values, erro
|
||||
}
|
||||
|
||||
switch typedElem := elem.(type) {
|
||||
case map[string]interface{}, map[interface{}]interface{}:
|
||||
case map[string]any, map[any]any:
|
||||
current = typedElem
|
||||
default:
|
||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, k)
|
||||
@@ -337,9 +337,9 @@ func SetValueAtPath(path string, value interface{}, values Values) (Values, erro
|
||||
}
|
||||
|
||||
switch typedCurrent := current.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
typedCurrent[key] = value
|
||||
case map[interface{}]interface{}:
|
||||
case map[any]any:
|
||||
typedCurrent[key] = value
|
||||
default:
|
||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, key)
|
||||
@@ -355,7 +355,7 @@ func RequiredEnv(name string) (string, error) {
|
||||
return "", fmt.Errorf("required env var `%s` is not set", name)
|
||||
}
|
||||
|
||||
func Required(warn string, val interface{}) (interface{}, error) {
|
||||
func Required(warn string, val any) (any, error) {
|
||||
if val == nil {
|
||||
return nil, fmt.Errorf(warn)
|
||||
} else if _, ok := val.(string); ok {
|
||||
|
||||
@@ -21,8 +21,8 @@ func TestCreateFuncMap(t *testing.T) {
|
||||
disableInsecureFeatures = false
|
||||
ctx := &Context{basePath: "."}
|
||||
funcMaps := ctx.createFuncMap()
|
||||
args := make([]interface{}, 0)
|
||||
outputExec, _ := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
||||
args := make([]any, 0)
|
||||
outputExec, _ := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||
require.Contains(t, outputExec, "context.go")
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ func TestCreateFuncMap_DisabledInsecureFeatures(t *testing.T) {
|
||||
disableInsecureFeatures = true
|
||||
ctx := &Context{basePath: "."}
|
||||
funcMaps := ctx.createFuncMap()
|
||||
args := make([]interface{}, 0)
|
||||
_, err1 := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
||||
args := make([]any, 0)
|
||||
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||
require.ErrorIs(t, err1, DisableInsecureFeaturesErr)
|
||||
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
||||
require.ErrorIs(t, err2, DisableInsecureFeaturesErr)
|
||||
@@ -53,8 +53,8 @@ func TestCreateFuncMap_SkipInsecureTemplateFunctions(t *testing.T) {
|
||||
skipInsecureTemplateFunctions = true
|
||||
ctx := &Context{basePath: "."}
|
||||
funcMaps := ctx.createFuncMap()
|
||||
args := make([]interface{}, 0)
|
||||
actual1, err1 := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
||||
args := make([]any, 0)
|
||||
actual1, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||
require.Equal(t, "", actual1)
|
||||
require.ErrorIs(t, err1, nil)
|
||||
actual2, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
||||
@@ -185,8 +185,8 @@ func TestToYaml_NestedMapInterfaceKey(t *testing.T) {
|
||||
})
|
||||
|
||||
// nolint: unconvert
|
||||
vals := Values(map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
vals := Values(map[string]any{
|
||||
"foo": map[any]any{
|
||||
"bar": "BAR",
|
||||
},
|
||||
})
|
||||
@@ -209,8 +209,8 @@ func TestToYaml(t *testing.T) {
|
||||
bar: BAR
|
||||
`
|
||||
// nolint: unconvert
|
||||
vals := Values(map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
vals := Values(map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "BAR",
|
||||
},
|
||||
})
|
||||
@@ -242,8 +242,8 @@ func TestFromYaml(t *testing.T) {
|
||||
t,
|
||||
true,
|
||||
// nolint: unconvert
|
||||
Values(map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
Values(map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "BAR",
|
||||
},
|
||||
}),
|
||||
@@ -255,8 +255,8 @@ func TestFromYaml(t *testing.T) {
|
||||
t,
|
||||
false,
|
||||
// nolint: unconvert
|
||||
Values(map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
Values(map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "BAR",
|
||||
},
|
||||
}),
|
||||
@@ -279,10 +279,10 @@ func TestFromYamlToJson(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetValueAtPath_OneComponent(t *testing.T) {
|
||||
input := map[string]interface{}{
|
||||
input := map[string]any{
|
||||
"foo": "",
|
||||
}
|
||||
expected := map[string]interface{}{
|
||||
expected := map[string]any{
|
||||
"foo": "FOO",
|
||||
}
|
||||
actual, err := SetValueAtPath("foo", "FOO", input)
|
||||
@@ -291,13 +291,13 @@ func TestSetValueAtPath_OneComponent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetValueAtPath_TwoComponents(t *testing.T) {
|
||||
input := map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
input := map[string]any{
|
||||
"foo": map[any]any{
|
||||
"bar": "",
|
||||
},
|
||||
}
|
||||
expected := map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
expected := map[string]any{
|
||||
"foo": map[any]any{
|
||||
"bar": "FOO_BAR",
|
||||
},
|
||||
}
|
||||
@@ -313,13 +313,13 @@ func TestTpl(t *testing.T) {
|
||||
input string
|
||||
expected string
|
||||
hasErr bool
|
||||
data map[string]interface{}
|
||||
data map[string]any
|
||||
}{
|
||||
{
|
||||
name: "simple",
|
||||
input: `foo: {{ .foo }}`,
|
||||
expected: `foo: Foo`,
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": "Foo",
|
||||
},
|
||||
},
|
||||
@@ -328,7 +328,7 @@ func TestTpl(t *testing.T) {
|
||||
input: `{{ .name }}
|
||||
end`,
|
||||
expected: "multiline\nend",
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"name": "multiline",
|
||||
},
|
||||
},
|
||||
@@ -350,12 +350,12 @@ end`,
|
||||
func TestRequired(t *testing.T) {
|
||||
type args struct {
|
||||
warn string
|
||||
val interface{}
|
||||
val any
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want interface{}
|
||||
want any
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -422,12 +422,12 @@ func TestExec(t *testing.T) {
|
||||
|
||||
// test that the command is executed
|
||||
expected := "foo\n"
|
||||
output, err := ctx.Exec("echo", []interface{}{"foo"}, "")
|
||||
output, err := ctx.Exec("echo", []any{"foo"}, "")
|
||||
require.Nilf(t, err, "Expected no error to be returned when executing command")
|
||||
require.Equalf(t, expected, output, "Expected %s to be returned when executing command", expected)
|
||||
|
||||
// test that the command is executed with no-zero exit code
|
||||
_, err = ctx.Exec("bash", []interface{}{"-c", "exit 1"}, "")
|
||||
_, err = ctx.Exec("bash", []any{"-c", "exit 1"}, "")
|
||||
require.Error(t, err, "Expected error to be returned when executing command with non-zero exit code")
|
||||
}
|
||||
|
||||
@@ -441,27 +441,27 @@ func TestEnvExec(t *testing.T) {
|
||||
testKey := "testkey"
|
||||
|
||||
// test that the command is executed with environment variables
|
||||
output, err := ctx.EnvExec(map[string]interface{}{testKey: "foo"}, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
output, err := ctx.EnvExec(map[string]any{testKey: "foo"}, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
|
||||
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
||||
|
||||
require.Equalf(t, expected, output, "Expected %s to be returned when executing command with environment variables", expected)
|
||||
|
||||
// test that the command is executed with invalid environment variables
|
||||
output, err = ctx.EnvExec(map[string]interface{}{testKey: 123}, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
output, err = ctx.EnvExec(map[string]any{testKey: 123}, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
|
||||
require.Errorf(t, err, "Expected error to be returned when executing command with invalid environment variables")
|
||||
require.Emptyf(t, output, "Expected empty string to be returned when executing command with invalid environment variables")
|
||||
|
||||
// test that the command is executed with no environment variables
|
||||
output, err = ctx.EnvExec(nil, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
output, err = ctx.EnvExec(nil, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
require.Nilf(t, err, "Expected no error to be returned when executing command with no environment variables")
|
||||
|
||||
require.Emptyf(t, output, "Expected empty string to be returned when executing command with no environment variables")
|
||||
|
||||
// test that the command is executed with os environment variables
|
||||
t.Setenv(testKey, "foo")
|
||||
output, err = ctx.EnvExec(nil, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
output, err = ctx.EnvExec(nil, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||
|
||||
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
||||
|
||||
|
||||
@@ -43,14 +43,14 @@ func (c *Context) newTemplate() *template.Template {
|
||||
return tmpl
|
||||
}
|
||||
|
||||
func (c *Context) RenderTemplateToBuffer(s string, data ...interface{}) (*bytes.Buffer, error) {
|
||||
func (c *Context) RenderTemplateToBuffer(s string, data ...any) (*bytes.Buffer, error) {
|
||||
var t, parseErr = c.newTemplate().Parse(s)
|
||||
if parseErr != nil {
|
||||
return nil, parseErr
|
||||
}
|
||||
|
||||
var tplString bytes.Buffer
|
||||
var d interface{}
|
||||
var d any
|
||||
if len(data) > 0 {
|
||||
d = data[0]
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ func TestRenderTemplate_WithData(t *testing.T) {
|
||||
bar: FOO_BAR
|
||||
`
|
||||
expectedFilename := "values.yaml"
|
||||
data := map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "FOO_BAR",
|
||||
},
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func TestRenderTemplate_AccessingMissingKeyWithGetOrNil(t *testing.T) {
|
||||
bar: <no value>
|
||||
`
|
||||
expectedFilename := "values.yaml"
|
||||
data := map[string]interface{}{}
|
||||
data := map[string]any{}
|
||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||
if filename != expectedFilename {
|
||||
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
||||
@@ -94,7 +94,7 @@ func TestRenderTemplate_Defaulting(t *testing.T) {
|
||||
bar: DEFAULT
|
||||
`
|
||||
expectedFilename := "values.yaml"
|
||||
data := map[string]interface{}{}
|
||||
data := map[string]any{}
|
||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||
if filename != expectedFilename {
|
||||
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
||||
@@ -111,7 +111,7 @@ func TestRenderTemplate_Defaulting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func renderTemplateToString(s string, data ...interface{}) (string, error) {
|
||||
func renderTemplateToString(s string, data ...any) (string, error) {
|
||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||
return nil, fmt.Errorf("unexpected call to readFile: filename=%s", filename)
|
||||
}}}
|
||||
@@ -126,7 +126,7 @@ func Test_renderTemplateToString(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
envs map[string]string
|
||||
data interface{}
|
||||
data any
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -184,7 +184,7 @@ func Test_renderTemplateToString(t *testing.T) {
|
||||
args: args{
|
||||
s: `{{ . | get "Foo" }}, {{ . | get "Bar" "2" }}`,
|
||||
envs: map[string]string{},
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"Foo": "1",
|
||||
},
|
||||
},
|
||||
@@ -253,14 +253,14 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s string
|
||||
data map[string]interface{}
|
||||
data map[string]any
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: ".foo is existed",
|
||||
s: `{{ required ".foo.bar is required" .foo }}`,
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": "bar",
|
||||
},
|
||||
want: "bar",
|
||||
@@ -269,8 +269,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
{
|
||||
name: ".foo.bar is existed",
|
||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||
data: map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "FOO_BAR",
|
||||
},
|
||||
},
|
||||
@@ -280,8 +280,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
{
|
||||
name: ".foo.bar is existed but value is nil",
|
||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||
data: map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": nil,
|
||||
},
|
||||
},
|
||||
@@ -290,8 +290,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
{
|
||||
name: ".foo.bar is existed but value is empty string",
|
||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||
data: map[string]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": map[string]any{
|
||||
"bar": "",
|
||||
},
|
||||
},
|
||||
@@ -300,7 +300,7 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
{
|
||||
name: ".foo is nil",
|
||||
s: `{{ required "foo is required" .foo }}`,
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": nil,
|
||||
},
|
||||
wantErr: true,
|
||||
@@ -308,7 +308,7 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||
{
|
||||
name: ".foo is a empty string",
|
||||
s: `{{ required "foo is required" .foo }}`,
|
||||
data: map[string]interface{}{
|
||||
data: map[string]any{
|
||||
"foo": "",
|
||||
},
|
||||
wantErr: true,
|
||||
|
||||
@@ -11,14 +11,14 @@ import (
|
||||
|
||||
// to generate mock run mockgen -source=expand_secret_ref.go -destination=expand_secrets_mock.go -package=tmpl
|
||||
type valClient interface {
|
||||
Eval(template map[string]interface{}) (map[string]interface{}, error)
|
||||
Eval(template map[string]any) (map[string]any, error)
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
var secretsClient valClient
|
||||
|
||||
func fetchSecretValue(path string) (string, error) {
|
||||
tmpMap := make(map[string]interface{})
|
||||
tmpMap := make(map[string]any)
|
||||
tmpMap["key"] = path
|
||||
resultMap, err := fetchSecretValues(tmpMap)
|
||||
if err != nil {
|
||||
@@ -38,7 +38,7 @@ func fetchSecretValue(path string) (string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func fetchSecretValues(values map[string]interface{}) (map[string]interface{}, error) {
|
||||
func fetchSecretValues(values map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
// below lines are for tests
|
||||
once.Do(func() {
|
||||
|
||||
@@ -15,10 +15,10 @@ func Test_fetchSecretValue(t *testing.T) {
|
||||
secretsClient = c
|
||||
|
||||
secretPath := "ref+vault://key/#path"
|
||||
expectArg := make(map[string]interface{})
|
||||
expectArg := make(map[string]any)
|
||||
expectArg["key"] = secretPath
|
||||
|
||||
valsResult := make(map[string]interface{})
|
||||
valsResult := make(map[string]any)
|
||||
valsResult["key"] = "key_value"
|
||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||
result, err := fetchSecretValue(secretPath)
|
||||
@@ -33,7 +33,7 @@ func Test_fetchSecretValue_error(t *testing.T) {
|
||||
secretsClient = c
|
||||
|
||||
secretPath := "ref+vault://key/#path"
|
||||
expectArg := make(map[string]interface{})
|
||||
expectArg := make(map[string]any)
|
||||
expectArg["key"] = secretPath
|
||||
|
||||
expectedErr := errors.New("some error")
|
||||
@@ -50,10 +50,10 @@ func Test_fetchSecretValue_no_key(t *testing.T) {
|
||||
secretsClient = c
|
||||
|
||||
secretPath := "ref+vault://key/#path"
|
||||
expectArg := make(map[string]interface{})
|
||||
expectArg := make(map[string]any)
|
||||
expectArg["key"] = secretPath
|
||||
|
||||
valsResult := make(map[string]interface{})
|
||||
valsResult := make(map[string]any)
|
||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||
result, err := fetchSecretValue(secretPath)
|
||||
assert.Error(t, err, "unexpected error occurred, map[] doesn't have 'key' key")
|
||||
@@ -67,10 +67,10 @@ func Test_fetchSecretValue_invalid_type(t *testing.T) {
|
||||
secretsClient = c
|
||||
|
||||
secretPath := "ref+vault://key/#path"
|
||||
expectArg := make(map[string]interface{})
|
||||
expectArg := make(map[string]any)
|
||||
expectArg["key"] = secretPath
|
||||
|
||||
valsResult := make(map[string]interface{})
|
||||
valsResult := make(map[string]any)
|
||||
valsResult["key"] = 10
|
||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||
result, err := fetchSecretValue(secretPath)
|
||||
|
||||
@@ -33,14 +33,14 @@ func (_m *MockvalClient) EXPECT() *MockvalClientMockRecorder {
|
||||
}
|
||||
|
||||
// Eval mocks base method
|
||||
func (_m *MockvalClient) Eval(template map[string]interface{}) (map[string]interface{}, error) {
|
||||
func (_m *MockvalClient) Eval(template map[string]any) (map[string]any, error) {
|
||||
ret := _m.ctrl.Call(_m, "Eval", template)
|
||||
ret0, _ := ret[0].(map[string]interface{})
|
||||
ret0, _ := ret[0].(map[string]any)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Eval indicates an expected call of Eval
|
||||
func (_mr *MockvalClientMockRecorder) Eval(arg0 interface{}) *gomock.Call {
|
||||
func (_mr *MockvalClientMockRecorder) Eval(arg0 any) *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Eval", reflect.TypeOf((*MockvalClient)(nil).Eval), arg0)
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
type FileRenderer struct {
|
||||
fs *filesystem.FileSystem
|
||||
Context *Context
|
||||
Data interface{}
|
||||
Data any
|
||||
}
|
||||
|
||||
func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data interface{}) *FileRenderer {
|
||||
func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data any) *FileRenderer {
|
||||
return &FileRenderer{
|
||||
fs: fs,
|
||||
Context: &Context{
|
||||
@@ -25,7 +25,7 @@ func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data interface{
|
||||
}
|
||||
}
|
||||
|
||||
func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
||||
func NewFirstPassRenderer(basePath string, data any) *FileRenderer {
|
||||
fs := filesystem.DefaultFileSystem()
|
||||
return &FileRenderer{
|
||||
fs: fs,
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||
)
|
||||
|
||||
var emptyEnvTmplData = map[string]interface{}{
|
||||
var emptyEnvTmplData = map[string]any{
|
||||
"Environment": environment.EmptyEnvironment,
|
||||
"Namespace": "",
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ func (e *noValueError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||
func get(path string, varArgs ...any) (any, error) {
|
||||
var defSet bool
|
||||
var def interface{}
|
||||
var obj interface{}
|
||||
var def any
|
||||
var obj any
|
||||
switch len(varArgs) {
|
||||
case 1:
|
||||
defSet = false
|
||||
@@ -35,14 +35,14 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||
return obj, nil
|
||||
}
|
||||
keys := strings.Split(path, ".")
|
||||
var v interface{}
|
||||
var v any
|
||||
var ok bool
|
||||
switch typedObj := obj.(type) {
|
||||
case *map[string]interface{}:
|
||||
case *map[string]any:
|
||||
obj = *typedObj
|
||||
}
|
||||
switch typedObj := obj.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
v, ok = typedObj[keys[0]]
|
||||
if !ok {
|
||||
if defSet {
|
||||
@@ -59,7 +59,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||
return nil, &noValueError{fmt.Sprintf("no value exist for key \"%s\" in %v", keys[0], typedObj)}
|
||||
}
|
||||
return v, nil
|
||||
case map[interface{}]interface{}:
|
||||
case map[any]any:
|
||||
v, ok = typedObj[keys[0]]
|
||||
if !ok {
|
||||
if defSet {
|
||||
@@ -70,7 +70,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||
default:
|
||||
maybeStruct := reflect.ValueOf(typedObj)
|
||||
if maybeStruct.Kind() != reflect.Struct {
|
||||
return nil, &noValueError{fmt.Sprintf("unexpected type(%v) of value for key \"%s\": it must be either map[string]interface{} or any struct", reflect.TypeOf(obj), keys[0])}
|
||||
return nil, &noValueError{fmt.Sprintf("unexpected type(%v) of value for key \"%s\": it must be either map[string]any or any struct", reflect.TypeOf(obj), keys[0])}
|
||||
} else if maybeStruct.NumField() < 1 {
|
||||
return nil, &noValueError{fmt.Sprintf("no accessible struct fields for key \"%s\"", keys[0])}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||
return get(strings.Join(keys[1:], "."), v)
|
||||
}
|
||||
|
||||
func getOrNil(path string, o interface{}) (interface{}, error) {
|
||||
func getOrNil(path string, o any) (any, error) {
|
||||
v, err := get(path, o)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestGetSimpleStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMap(t *testing.T) {
|
||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
||||
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||
|
||||
v1, err := get("Foo.Bar", obj)
|
||||
|
||||
@@ -79,7 +79,7 @@ func TestGetMap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMapPtr(t *testing.T) {
|
||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
||||
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||
objPrt := &obj
|
||||
|
||||
v1, err := get("Foo.Bar", objPrt)
|
||||
@@ -99,7 +99,7 @@ func TestGetMapPtr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGet_Default(t *testing.T) {
|
||||
obj := map[string]interface{}{"Foo": map[string]interface{}{}, "foo": 1}
|
||||
obj := map[string]any{"Foo": map[string]any{}, "foo": 1}
|
||||
|
||||
v1, err := get("Foo.Bar", "Bar", obj)
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestGetOrNilStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrNilMap(t *testing.T) {
|
||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
||||
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||
|
||||
v1, err := getOrNil("Foo.Bar", obj)
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ import (
|
||||
type templateTextRenderer struct {
|
||||
ReadText func(string) ([]byte, error)
|
||||
Context *Context
|
||||
Data interface{}
|
||||
Data any
|
||||
}
|
||||
|
||||
type TextRenderer interface {
|
||||
RenderTemplateText(text string) (string, error)
|
||||
}
|
||||
|
||||
func NewTextRenderer(fs *filesystem.FileSystem, basePath string, data interface{}) *templateTextRenderer {
|
||||
func NewTextRenderer(fs *filesystem.FileSystem, basePath string, data any) *templateTextRenderer {
|
||||
return &templateTextRenderer{
|
||||
ReadText: fs.ReadFile,
|
||||
Context: &Context{
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// TestTextRenderer tests the text renderer.
|
||||
func TestNewTextRenderer(t *testing.T) {
|
||||
tData := map[string]interface{}{
|
||||
tData := map[string]any{
|
||||
"foo": "bar",
|
||||
}
|
||||
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
||||
@@ -20,7 +20,7 @@ func TestNewTextRenderer(t *testing.T) {
|
||||
|
||||
// TestTextRenderer tests the text renderer.
|
||||
func TestTextRender(t *testing.T) {
|
||||
tData := map[string]interface{}{
|
||||
tData := map[string]any{
|
||||
"foot": "bart",
|
||||
}
|
||||
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
||||
|
||||
Reference in New Issue
Block a user