Skip to content

Commit

Permalink
implemented requested changes: some minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: sanskruti-shahu <sanskruti.shahu@harness.io>
  • Loading branch information
sanskruti-shahu committed Feb 23, 2024
1 parent 61c0469 commit 9295c43
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/lang/funcs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func MakeTemplateFileFunc(baseDir string, funcsCb func() map[string]function.Fun

// This is safe even if args[1] contains unknowns because the HCL
// template renderer itself knows how to short-circuit those.
val, err := RenderTemplate(expr, args[1], funcsCb)
val, err := renderTemplate(expr, args[1], funcsCb)
return val.Type(), err
},
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
Expand All @@ -129,7 +129,7 @@ func MakeTemplateFileFunc(baseDir string, funcsCb func() map[string]function.Fun
if err != nil {
return cty.DynamicVal, err
}
result, err := RenderTemplate(expr, args[1], funcsCb)
result, err := renderTemplate(expr, args[1], funcsCb)
return result.WithMarks(pathMarks), err
},
})
Expand Down
4 changes: 2 additions & 2 deletions internal/lang/funcs/render_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/zclconf/go-cty/cty/function"
)

func RenderTemplate(expr hcl.Expression, varsVal cty.Value, funcsCb func() map[string]function.Function) (cty.Value, error) {
func renderTemplate(expr hcl.Expression, varsVal cty.Value, funcsCb func() map[string]function.Function) (cty.Value, error) {
if varsTy := varsVal.Type(); !(varsTy.IsMapType() || varsTy.IsObjectType()) {
return cty.DynamicVal, function.NewArgErrorf(1, "invalid vars value: must be a map") // or an object, but we don't strongly distinguish these most of the time
}
Expand Down Expand Up @@ -46,7 +46,7 @@ func RenderTemplate(expr hcl.Expression, varsVal cty.Value, funcsCb func() map[s
for _, traversal := range expr.Variables() {
root := traversal.RootName()
referencedPos := fmt.Sprintf("%q", root)
if currFilename != TemplateStringFilename {
if currFilename != templateStringFilename {
referencedPos = fmt.Sprintf("%q, referenced at %s", root, traversal[0].SourceRange())
}
if _, ok := ctx.Variables[root]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/lang/funcs/render_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestRenderTemplate(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {

got, err := RenderTemplate(test.Expr, test.Vars, func() map[string]function.Function {
got, err := renderTemplate(test.Expr, test.Vars, func() map[string]function.Function {
return map[string]function.Function{}
})

Expand Down
8 changes: 4 additions & 4 deletions internal/lang/funcs/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func StrContains(str, substr cty.Value) (cty.Value, error) {
// This constant provides a placeholder value for filename indicating
// that no file is needed for templatestring.
const (
TemplateStringFilename = "NoFileNeeded"
templateStringFilename = "NoFileNeeded"
)

// MakeTemplateStringFunc constructs a function that takes a string and
Expand All @@ -192,7 +192,7 @@ func MakeTemplateStringFunc(content string, funcsCb func() map[string]function.F
}
loadTmpl := func(content string, marks cty.ValueMarks) (hcl.Expression, error) {

expr, diags := hclsyntax.ParseTemplate([]byte(content), TemplateStringFilename, hcl.Pos{Line: 1, Column: 1})
expr, diags := hclsyntax.ParseTemplate([]byte(content), templateStringFilename, hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
return nil, diags
}
Expand All @@ -218,7 +218,7 @@ func MakeTemplateStringFunc(content string, funcsCb func() map[string]function.F

// This is safe even if args[1] contains unknowns because the HCL
// template renderer itself knows how to short-circuit those.
val, err := RenderTemplate(expr, args[1], funcsCb)
val, err := renderTemplate(expr, args[1], funcsCb)
return val.Type(), err
},
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
Expand All @@ -227,7 +227,7 @@ func MakeTemplateStringFunc(content string, funcsCb func() map[string]function.F
if err != nil {
return cty.DynamicVal, err
}
result, err := RenderTemplate(expr, args[1], funcsCb)
result, err := renderTemplate(expr, args[1], funcsCb)
return result.WithMarks(dataMarks), err
},
})
Expand Down

0 comments on commit 9295c43

Please sign in to comment.