mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 05:02:24 +02:00
Revert "cleanup: remove all about v0.x" (#1918)
Revert "cleanup: remove all about v0.x (#1903)"
This reverts commit d7bcd5e998.
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/helmfile/helmfile/pkg/envvar"
|
||||
"github.com/helmfile/helmfile/pkg/helmexec"
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
"github.com/helmfile/helmfile/pkg/runtime"
|
||||
"github.com/helmfile/helmfile/pkg/yaml"
|
||||
)
|
||||
|
||||
@@ -36,10 +37,23 @@ func (e DisableInsecureFeaturesError) Error() string {
|
||||
|
||||
var (
|
||||
disableInsecureFeatures bool
|
||||
|
||||
// TODO: Remove this function once Helmfile v0.x
|
||||
skipInsecureTemplateFunctions bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
disableInsecureFeatures, _ = strconv.ParseBool(os.Getenv(envvar.DisableInsecureFeatures))
|
||||
|
||||
// TODO: Remove this function once Helmfile v0.x
|
||||
skipInsecureTemplateFunctions, _ = strconv.ParseBool(os.Getenv(envvar.SkipInsecureTemplateFunctions))
|
||||
skipInsecureTemplateFunctions = func() bool {
|
||||
if runtime.V1Mode {
|
||||
return false
|
||||
}
|
||||
b, _ := strconv.ParseBool(os.Getenv(envvar.SkipInsecureTemplateFunctions))
|
||||
return b
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *Context) createFuncMap() template.FuncMap {
|
||||
@@ -62,7 +76,7 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||
"fetchSecretValue": fetchSecretValue,
|
||||
"expandSecretRefs": fetchSecretValues,
|
||||
}
|
||||
if c.preRender {
|
||||
if c.preRender || skipInsecureTemplateFunctions {
|
||||
// disable potential side-effect template calls
|
||||
funcMap["exec"] = func(string, []any, ...string) (string, error) {
|
||||
return "", nil
|
||||
|
||||
@@ -46,6 +46,30 @@ func TestCreateFuncMap_DisabledInsecureFeatures(t *testing.T) {
|
||||
disableInsecureFeatures = currentVal
|
||||
}
|
||||
|
||||
// TODO: Remove this function once Helmfile v0.x
|
||||
func TestCreateFuncMap_SkipInsecureTemplateFunctions(t *testing.T) {
|
||||
if runtime.V1Mode {
|
||||
t.Logf("SkipInsecureTemplateFunctions is not supported in V1 mode")
|
||||
return
|
||||
}
|
||||
currentVal := skipInsecureTemplateFunctions
|
||||
|
||||
{
|
||||
skipInsecureTemplateFunctions = true
|
||||
ctx := &Context{basePath: "."}
|
||||
funcMaps := ctx.createFuncMap()
|
||||
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")
|
||||
require.Equal(t, "", actual2)
|
||||
require.ErrorIs(t, err2, nil)
|
||||
}
|
||||
|
||||
skipInsecureTemplateFunctions = currentVal
|
||||
}
|
||||
|
||||
func newFSExpecting(expectedFilename string, expected string) *filesystem.FileSystem {
|
||||
return filesystem.FromFileSystem(filesystem.FileSystem{
|
||||
ReadFile: func(filename string) ([]byte, error) {
|
||||
|
||||
Reference in New Issue
Block a user