/
expr.go
36 lines (28 loc) · 984 Bytes
/
expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package expression
import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
service "github.com/argoproj/argo-cd/v2/util/notification/argocd"
"github.com/argoproj/argo-cd/v2/util/notification/expression/repo"
"github.com/argoproj/argo-cd/v2/util/notification/expression/strings"
"github.com/argoproj/argo-cd/v2/util/notification/expression/time"
)
var helpers = map[string]interface{}{}
func init() {
helpers = make(map[string]interface{})
register("time", time.NewExprs())
register("strings", strings.NewExprs())
}
func register(namespace string, entry map[string]interface{}) {
helpers[namespace] = entry
}
func Spawn(app *unstructured.Unstructured, argocdService service.Service, vars map[string]interface{}) map[string]interface{} {
clone := make(map[string]interface{})
for k := range vars {
clone[k] = vars[k]
}
for namespace, helper := range helpers {
clone[namespace] = helper
}
clone["repo"] = repo.NewExprs(argocdService, app)
return clone
}