Skip to content
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

Merged
merged 6 commits into from
Jan 10, 2018

Conversation

dannymc129
Copy link
Contributor

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.

@snowplowcla
Copy link

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.

Copy link

@BenFradet BenFradet left a 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 👍

@@ -15,12 +15,14 @@ package main
type ConsulPlaybookProvider struct {
consulAddress string
consulKey string
variables CLIVariables

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indent seems off

consulKey: consulKey,
consulAddress: options.consul,
consulKey: options.playbook,
variables: options.variables,

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

}

func NewConsulPlaybookProvider(consulAddress, consulKey string) *ConsulPlaybookProvider {
func NewConsulPlaybookProvider(options Options) *ConsulPlaybookProvider {

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?

}

func NewYAMLFilePlaybookProvider(playbookPath string) *YAMLFilePlaybookProvider {
func NewYAMLFilePlaybookProvider(options Options) *YAMLFilePlaybookProvider {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark as above

@@ -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) {

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

return "", err
}

return string(filled.String()), err

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?

@@ -51,3 +57,17 @@ func cleanYaml(rawYaml []byte) []byte {
}
return buffer.Bytes()
}

func fillPlaybookTemplate(playbookStr string, variables CLIVariables) (string, error) {

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

@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage increased (+0.7%) to 33.247% when pulling bd704b2 on dannymc129:master into 0ae72da on snowplow:master.

@snowplow snowplow deleted a comment from coveralls Jul 12, 2017
@snowplow snowplow deleted a comment from coveralls Jul 12, 2017
for value := range split {
kv := strings.SplitN(split[value], "=", 2)

(*i)[kv[0]] = kv[1]

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?

@dannymc129
Copy link
Contributor Author

I signed it!

@coveralls
Copy link

coveralls commented Aug 4, 2017

Coverage Status

Coverage increased (+0.6%) to 33.161% when pulling e00c717 on dannymc129:master into 0ae72da on snowplow:master.

@snowplowcla
Copy link

Confirmed! @dannymc129 has signed the Individual Contributor License Agreement. Thanks so much

Copy link

@BenFradet BenFradet left a 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

@BenFradet BenFradet added this to the Version 0.6.0 milestone Aug 10, 2017
@BenFradet BenFradet changed the base branch from master to develop January 10, 2018 16:44
@BenFradet BenFradet changed the title Add Templating Options for Playbooks Add the possibility to template playbooks Jan 10, 2018
@BenFradet
Copy link

Merging, sorry for the delay 👍

@BenFradet BenFradet merged commit 23d1c08 into snowplow:develop Jan 10, 2018
@alexanderdean
Copy link
Member

@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.

@BenFradet
Copy link

Nw, we can still split the commit when merging to master.

I'll log the other issue.

@alexanderdean
Copy link
Member

Thanks @BenFradet !

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants