Skip to content

Commit

Permalink
Adding utility functions for more templating options.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferahl committed Apr 27, 2022
1 parent 0da853d commit bbe94ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/pkg/template/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package template
import (
"fmt"
"strconv"
"strings"

corev1alpha1 "github.com/kristofferahl/aeto/apis/core/v1alpha1"
)
Expand All @@ -15,6 +16,7 @@ type Data struct {
Labels map[string]string
Annotations map[string]string
Parameters []*corev1alpha1.Parameter
Utils UtilityFunctions
}

type Namespaces struct {
Expand Down Expand Up @@ -49,3 +51,29 @@ func (d Data) Bool(name string) (bool, error) {
}
return strconv.ParseBool(v)
}

type UtilityFunctions struct {
String
Slice
}

type String struct{}

func (d String) Replace(s, old, new string, n int) string {
return strings.Replace(s, old, new, n)
}

func (d String) ReplaceAll(s string, old string, new string) string {
return strings.ReplaceAll(s, old, new)
}

type Slice struct{}

func (d Slice) ContainsString(haystack []string, needle string) bool {
for _, s := range haystack {
if s == needle {
return true
}
}
return false
}
1 change: 1 addition & 0 deletions internal/pkg/tenant/resource_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (r *ResourceGenerator) newTemplateData(blueprint corev1alpha1.Blueprint, pa
Labels: r.state.Labels,
Annotations: r.state.Annotations,
Parameters: parameters,
Utils: template.UtilityFunctions{},
}
}

Expand Down

0 comments on commit bbe94ec

Please sign in to comment.