engine.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package template provides utilities for working with different template engine versions.
  14. package template
  15. import (
  16. "fmt"
  17. corev1 "k8s.io/api/core/v1"
  18. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. v2 "github.com/external-secrets/external-secrets/pkg/template/v2"
  20. )
  21. // ExecFunc is the function signature type for executing a template engine.
  22. type ExecFunc func(tpl, data map[string][]byte, scope esapi.TemplateScope, target esapi.TemplateTarget, secret *corev1.Secret) error
  23. // EngineForVersion returns the appropriate template engine for the given version.
  24. func EngineForVersion(version esapi.TemplateEngineVersion) (ExecFunc, error) {
  25. // We want to leave this for new versions
  26. switch version { //nolint:gocritic
  27. case esapi.TemplateEngineV2:
  28. return v2.Execute, nil
  29. }
  30. return nil, fmt.Errorf("unsupported template engine version: %s", version)
  31. }