-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use mustache to wire up params, creds, outputs #264
Conversation
62bfe10
to
d7e4ddf
Compare
@carolynvs @vdice take a look. The only thing I'm kind of bummed about in this is that the mustache templates need to be quoted, otherwise the go marshalling isn't happy. Maybe we need to change how the marshalling works and only marshall the steps after they've been fully resolved? This seems like a big enough change to review on it's own though, tackle that in another refactor. |
I'm not sure I see how to resolve before we've parsed the file, but you are closer than I am to it for sure. Yeah let's go with this for now and iterate. |
I was thinking more that we wouldn't fully try and rehydrate a struct with the yaml marsheller, but I don't know if that's possible. just thinking out loud |
source: bundle.parameters.database-name | ||
mysqlUser: | ||
source: bundle.parameters.mysql-user | ||
mysqlDatabase: "{{ bundle.parameters.database-name}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
muy bien!
docs/content/authoring-bundles.md
Outdated
source: bundle.parameters.database-name | ||
mysqlUser: | ||
source: bundle.parameters.mysql-user | ||
mysqlDatabase: {{ bundle.parameters.database-name }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these have quotes?
docs/content/mixin-architecture.md
Outdated
source: bundle.parameters.database-name | ||
mysqlUser: | ||
source: bundle.parameters.mysql-user | ||
mysqlDatabase: {{ bundle.parameters.database-name }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these have quotes?
@@ -95,23 +95,18 @@ install: | |||
key: mysql-password | |||
- helm: | |||
description: "Install Wordpress" | |||
name: | |||
source: bundle.parameters.wordpress-name | |||
name: {{ bundle.parameters.wordpress-name }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like all the markdown files are missing quotes around the moustash template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I forgot to update them! Thanks for pointing that out.
docs/content/wiring.md
Outdated
@@ -29,7 +29,7 @@ You can also provide any other attributes, as specified by the CNAB [parameters] | |||
|
|||
## Wiring Parameters | |||
|
|||
Once a parameter has been declared in the `porter.yaml`, Porter provides a simple mechanism for specifying how the parameter value should be wired into the mixin. To reference a parameter in the bundle, you use a notation of the form `source: bundle.parameters.PARAM_NAME`. This can be used anywhere within step definition. For example, to use the `database_name` parameter defined above in the `set` block of the helm mixin: | |||
Once a parameter has been declared in the `porter.yaml`, Porter provides a simple mechanism for specifying how the parameter value should be wired into the mixin. To reference a parameter in the bundle, you use a notation of the form `{{ bundle.parameters.PARAM_NAME }}`. This can be used anywhere within step definition. For example, to use the `database_name` parameter defined above in the `set` block of the helm mixin: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should mention the surrounding quotes
data := make(map[string]interface{}) | ||
m.sensitiveValues = []string{} | ||
bundle := make(map[string]interface{}) | ||
data["bundle"] = bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a question about mustache. Looks like we are building up a map that has keys for parameters, outputs, etc inside of it, then that's what the template is operating upon.
If we had a struct called "TemplateMagicPants" (or whatever) and it had fields for parameters, outputs, credentials, and everything else we needed, would that work too as input data to mustache? Or would that result in different syntax in the template?
This is just a question for me to understand mustache, not asking you to change anything. 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to have a struct called TemplateMagicPants that had those, that lived in a map with the key bundle. Or another struct. It's walking what ever the template syntax is. I was trying to keep it mostly the same, and I think the comment from our Amazon friends used similar syntax.
I did find myself wondering what the point of the "bundle" is. everything is rooted off that....soooooo maybe just {{ parameters.x }} or {{ outputs.y }} or {{ credentials.z }} or {{ dependencies.x.y.z }}
I was thinking along these lines for the general refactor of "the manifest" from the running state of things, but here I didn't want to change the syntax of the template since we hadn't chatted about that. Happy to go either way, but I think my opinion is the "bundle" key is not really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not remove the bundle.
prefix for now. I believe that it is important for both giving people a starting point in their heads for what to type, and also for the autocomplete to have something to go off of.
return nil, err | ||
} | ||
if param.Sensitive { | ||
m.sensitiveValues = append(m.sensitiveValues, val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't on you, but the sensitive values stuff is in desperate need of a refactor so that it's not tied to the manifest like this. I can't wait for your work to split out the runtime from the manifest as I believe that's something we identified as being helpful in order to do the masking in a less obtrusive way going forward. 🤞
pkg/config/manifest.go
Outdated
creds := make(map[string]interface{}) | ||
bundle["credentials"] = creds | ||
for _, cred := range m.Credentials { | ||
//pe := strings.ToUpper(cred.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we nuke this comment?
pkg/config/manifest.go
Outdated
return nil, errors.New(fmt.Sprintf("no value found for source specification: %s", key)) | ||
payload, err := yaml.Marshal(step) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to resolve step") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure wrapping all these various errors with the same error message is going to be helpful? Having a bit more context about what was going on may be useful when dealing with errors like "unable to resolve step: unexpected EOF", you know?
pkg/config/manifest.go
Outdated
} | ||
return replacement, nil | ||
return yaml.Unmarshal([]byte(rendered), step) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this last error isn't being wrapped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such quotes, much wow 🐶
Merge at will |
This PR changes how we wire params, credentials and outputs between steps. Instead of the previous "source:" bundle.x.y.z, now we use Mustache templates.
Closes #161