about summary refs log tree commit diff
path: root/templater
diff options
context:
space:
mode:
Diffstat (limited to 'templater')
-rw-r--r--templater/fromfile.go24
-rw-r--r--templater/templater.go13
2 files changed, 10 insertions, 27 deletions
diff --git a/templater/fromfile.go b/templater/fromfile.go
deleted file mode 100644
index f4f1e79cbfba..000000000000
--- a/templater/fromfile.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2017  Niklas Wik <niklas.wik@nokia.com>
-//
-// This file is part of Kontemplate.
-//
-// Kontemplate is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-package templater
-
-import (
-	"io/ioutil"
-)
-
-//GetFromFile returns file content as string
-func GetFromFile(file string) (string, error) {
-
-	data, err := ioutil.ReadFile(file)
-	if err != nil {
-		return "", err
-	}
-	return string(data), nil
-}
diff --git a/templater/templater.go b/templater/templater.go
index 5bdb2f2e3bb1..fd514a5ac06f 100644
--- a/templater/templater.go
+++ b/templater/templater.go
@@ -119,7 +119,7 @@ func processFiles(c *context.Context, rs *context.ResourceSet, rp string, files
 }
 
 func templateFile(c *context.Context, rs *context.ResourceSet, filename string) (string, error) {
-	tpl, err := template.New(path.Base(filename)).Funcs(templateFuncs()).Option(failOnMissingKeys).ParseFiles(filename)
+	tpl, err := template.New(path.Base(filename)).Funcs(templateFuncs(rs)).Option(failOnMissingKeys).ParseFiles(filename)
 
 	if err != nil {
 		return "", meep.New(
@@ -185,7 +185,7 @@ func matchesResourceSet(s *[]string, rs *context.ResourceSet) bool {
 	return false
 }
 
-func templateFuncs() template.FuncMap {
+func templateFuncs(rs *context.ResourceSet) template.FuncMap {
 	m := sprig.TxtFuncMap()
 	m["json"] = func(data interface{}) string {
 		b, _ := json.Marshal(data)
@@ -193,7 +193,14 @@ func templateFuncs() template.FuncMap {
 	}
 	m["passLookup"] = GetFromPass
 	m["lookupIPAddr"] = GetIPsFromDNS
-	m["fileContent"] = GetFromFile
+	m["insertFile"] = func(file string) (string, error) {
+		data, err := ioutil.ReadFile(path.Join(rs.Path, file))
+		if err != nil {
+			return "", err
+		}
+
+		return string(data), nil
+	}
 
 	return m
 }