From 815ffc7cac745be28dc02a92524747f806dc8393 Mon Sep 17 00:00:00 2001
From: Jessica Yuen <im.jessicayuen@gmail.com>
Date: Fri, 27 Oct 2017 17:56:07 -0700
Subject: [PATCH] Jsonnet Snippet Parser should translate params based on
 updated spec

This commit will cause the jsonnet snippet parser to parse input of the
form `import 'param://foo` to `params.foo` as opposed to the previous
`${foo}`.

${foo} does not provide an easily accessible way to the params that are
exposed through the params.libsonnet file. Since parameters are being
exposed using a local 'params' variable, it makes sense for the jsonnet
snippet to parse `import param://foo as `params.foo` instead.
---
 prototype/snippet/jsonnet/snippet.go      | 7 +++----
 prototype/snippet/jsonnet/snippet_test.go | 6 +++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/prototype/snippet/jsonnet/snippet.go b/prototype/snippet/jsonnet/snippet.go
index 8e672d1b..ad00f736 100644
--- a/prototype/snippet/jsonnet/snippet.go
+++ b/prototype/snippet/jsonnet/snippet.go
@@ -28,8 +28,7 @@ import (
 
 const (
 	paramPrefix            = "param://"
-	paramReplacementPrefix = "${"
-	paramReplacementSuffix = "}"
+	paramReplacementPrefix = "params."
 )
 
 // Parse rewrites the imports in a Jsonnet file before returning the parsed
@@ -301,7 +300,7 @@ func visitLocalBind(node ast.LocalBind, imports *[]ast.Import) error {
 // ---------------------------------------------------------------------------
 
 // replace converts all parameters in the passed Jsonnet of form
-// `import 'param://port'` into `${port}`.
+// `import 'param://port'` into `params.port`.
 func replace(jsonnet string, imports []ast.Import) string {
 	lines := strings.Split(jsonnet, "\n")
 
@@ -315,7 +314,7 @@ func replace(jsonnet string, imports []ast.Import) string {
 	})
 
 	for _, im := range imports {
-		param := paramReplacementPrefix + strings.TrimPrefix(im.File.Value, paramPrefix) + paramReplacementSuffix
+		param := paramReplacementPrefix + strings.TrimPrefix(im.File.Value, paramPrefix)
 
 		lineStart := im.Loc().Begin.Line
 		lineEnd := im.Loc().End.Line
diff --git a/prototype/snippet/jsonnet/snippet_test.go b/prototype/snippet/jsonnet/snippet_test.go
index 6cb1f071..4fd213d4 100644
--- a/prototype/snippet/jsonnet/snippet_test.go
+++ b/prototype/snippet/jsonnet/snippet_test.go
@@ -49,9 +49,9 @@ func TestParse(t *testing.T) {
 			
 			local service = k.core.v1.service;
 			local servicePort = k.core.v1.service.mixin.spec.portsType;
-			local port = servicePort.new((${port}), (${portName}));
+			local port = servicePort.new((params.port), (params.portName));
 			
-			local name = ${name};
+			local name = params.name;
 			k.core.v1.service.new('%s-service' % [name], {app: name}, port)`,
 		},
 		// Test where an import param is split over multiple lines.
@@ -66,7 +66,7 @@ func TestParse(t *testing.T) {
 
 			`
 			local f = (
-				${f}
+				params.f
 
 
 			);
-- 
GitLab