about summary refs log tree commit diff
path: root/context/context.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-02-08T16·14+0100
committerVincent Ambo <tazjin@gmail.com>2017-02-08T16·34+0100
commit4e8223ef3496f390dd84a2a47fc8846afd6f7c76 (patch)
treefa64c30d2100c8b5eeece723565e9b7df3448348 /context/context.go
parentd6b16793c150202f78e5b862b372481f08a00a6f (diff)
feat context: Add support for resource set collections
A resource set collection is a resource set with an addition 'include' array
configured. It is a short-hand for importing multiple resource sets from the
same folder and for excluding/including them as a group.

See https://github.com/tazjin/kontemplate/issues/9 for more information.

Closes #9
Diffstat (limited to 'context/context.go')
-rw-r--r--context/context.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/context/context.go b/context/context.go
index 140f11fce7c6..94838f668d71 100644
--- a/context/context.go
+++ b/context/context.go
@@ -14,6 +14,10 @@ import (
 type ResourceSet struct {
 	Name   string                 `json:"name"`
 	Values map[string]interface{} `json:"values"`
+
+	// Fields for resource set collections
+	Include []ResourceSet `json:"include"`
+	Parent  *string
 }
 
 type Context struct {
@@ -63,3 +67,23 @@ func LoadContextFromFile(filename string) (*Context, error) {
 
 	return &c, nil
 }
+
+// Flattens resource set collections, i.e. resource sets that themselves have an additional 'include' field set.
+// Those will be regarded as a short-hand for including multiple resource sets from a subfolder.
+// See https://github.com/tazjin/kontemplate/issues/9 for more information.
+func flattenResourceSetCollections(rs *[]ResourceSet) *[]ResourceSet {
+	flattened := make([]ResourceSet, 0)
+
+	for _, r := range *rs {
+		if len(r.Include) == 0 {
+			flattened = append(flattened, r)
+		} else {
+			for _, subResourceSet := range r.Include {
+				subResourceSet.Parent = &r.Name
+				flattened = append(flattened, subResourceSet)
+			}
+		}
+	}
+
+	return &flattened
+}