-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add the possibility to template playbooks #103
Conversation
Thanks for your pull request. Is this your first contribution to a Snowplow open source project? Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://github.com/snowplow/snowplow/wiki/CLA to learn more and sign. Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks. |
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.
done a first pass, I think this is good use case 👍
sql_runner/consul_provider.go
Outdated
@@ -15,12 +15,14 @@ package main | |||
type ConsulPlaybookProvider struct { | |||
consulAddress string | |||
consulKey string | |||
variables CLIVariables |
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.
the indent seems off
sql_runner/consul_provider.go
Outdated
consulKey: consulKey, | ||
consulAddress: options.consul, | ||
consulKey: options.playbook, | ||
variables: options.variables, |
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.
same, don't hesitate to run gofmt
sql_runner/consul_provider.go
Outdated
} | ||
|
||
func NewConsulPlaybookProvider(consulAddress, consulKey string) *ConsulPlaybookProvider { | ||
func NewConsulPlaybookProvider(options Options) *ConsulPlaybookProvider { |
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.
are we sure we want to pass the whole options bundle and not just the address, key and variables?
sql_runner/yaml_provider.go
Outdated
} | ||
|
||
func NewYAMLFilePlaybookProvider(playbookPath string) *YAMLFilePlaybookProvider { | ||
func NewYAMLFilePlaybookProvider(options Options) *YAMLFilePlaybookProvider { |
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.
same remark as above
sql_runner/yaml_utils.go
Outdated
@@ -26,13 +27,18 @@ var ( | |||
|
|||
// Parses a playbook.yml to return the targets | |||
// to execute against and the steps to execute | |||
func parsePlaybookYaml(playbookBytes []byte) (Playbook, error) { | |||
func parsePlaybookYaml(playbookBytes []byte, variables CLIVariables) (Playbook, error) { |
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.
might be worth it to restrict ourselves to just a map[string]string
sql_runner/yaml_utils.go
Outdated
return "", err | ||
} | ||
|
||
return string(filled.String()), err |
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.
why the wrapping of a string in another string?
sql_runner/yaml_utils.go
Outdated
@@ -51,3 +57,17 @@ func cleanYaml(rawYaml []byte) []byte { | |||
} | |||
return buffer.Bytes() | |||
} | |||
|
|||
func fillPlaybookTemplate(playbookStr string, variables CLIVariables) (string, error) { |
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.
same I think we can drop CLIVariables
in favour of map[string]string
sql_runner/options.go
Outdated
for value := range split { | ||
kv := strings.SplitN(split[value], "=", 2) | ||
|
||
(*i)[kv[0]] = kv[1] |
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 check the length of kv and send an error accordingly to avoid index out of range?
I signed it! |
Confirmed! @dannymc129 has signed the Individual Contributor License Agreement. Thanks so much |
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.
Looks great! 👍 , scheduling for the next version
Merging, sorry for the delay 👍 |
@BenFradet I think this should have been split into two commits - one to add the new templating functionality, and the other to fix the limitation around the single variable provision. |
Nw, we can still split the commit when merging to master. I'll log the other issue. |
Thanks @BenFradet ! |
I was recently recommended by @lritter to consider using this tool for some adhoc queries we need to run regularly and I ended up really liking it. Simple, clean, functional, we're already snowplow users and a perfect match.
But I wasn't happy with the idea of all of my hosts and password being hosted along with the playbooks, so to fix this I changed it so that the
-var
flag will pass into a playbook similar to the way it does for sql templates, then we can get our passwords out of local config without worrying the tool.I also found out that based on:
https://github.com/snowplow/sql-runner/blob/master/sql_runner/options.go#L28-L36
there's a limit of only a single key=value pair in the
-var
flag, I extended this so that it will load any number of vars via comma separation (key=value,key2=value2
)Pretty new to go, please do pick it apart.