leeroy_app 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +40 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +103 -0
  7. data/LICENSE +21 -0
  8. data/README.md +40 -0
  9. data/Rakefile +5 -0
  10. data/bin/leeroy +18 -0
  11. data/hierarchy.md +39 -0
  12. data/leeroy.gemspec +42 -0
  13. data/lib/leeroy/app.rb +132 -0
  14. data/lib/leeroy/env.rb +116 -0
  15. data/lib/leeroy/helpers/aws.rb +403 -0
  16. data/lib/leeroy/helpers/dumpable.rb +72 -0
  17. data/lib/leeroy/helpers/env.rb +42 -0
  18. data/lib/leeroy/helpers/logging.rb +36 -0
  19. data/lib/leeroy/helpers/polling.rb +67 -0
  20. data/lib/leeroy/helpers/state.rb +59 -0
  21. data/lib/leeroy/helpers.rb +9 -0
  22. data/lib/leeroy/state.rb +70 -0
  23. data/lib/leeroy/task/base.rb +61 -0
  24. data/lib/leeroy/task/image.rb +126 -0
  25. data/lib/leeroy/task/instantiate.rb +200 -0
  26. data/lib/leeroy/task/sleep.rb +29 -0
  27. data/lib/leeroy/task/stub.rb +40 -0
  28. data/lib/leeroy/task/terminate.rb +49 -0
  29. data/lib/leeroy/task.rb +17 -0
  30. data/lib/leeroy/types/dash.rb +17 -0
  31. data/lib/leeroy/types/image.rb +53 -0
  32. data/lib/leeroy/types/instance.rb +67 -0
  33. data/lib/leeroy/types/mash.rb +17 -0
  34. data/lib/leeroy/types/packedstring.rb +25 -0
  35. data/lib/leeroy/types/phase.rb +20 -0
  36. data/lib/leeroy/types/semaphore.rb +30 -0
  37. data/lib/leeroy/types/statedata.rb +44 -0
  38. data/lib/leeroy/types/statemetadata.rb +29 -0
  39. data/lib/leeroy/types/userdata.rb +13 -0
  40. data/lib/leeroy/version.rb +3 -0
  41. data/lib/leeroy.rb +7 -0
  42. data/spec/spec_helper.rb +105 -0
  43. data/spec/support/aruba.rb +1 -0
  44. data/spec/use_aruba_with_rspec_spec.rb +11 -0
  45. metadata +333 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a33c630bfff44d8f1fbaff8694c65891aef0f8c5
4
+ data.tar.gz: ad0999e31aec974b08fb8f1e10c268b62a653004
5
+ SHA512:
6
+ metadata.gz: faf7735d2cdcd8f9cf9cb0e834210f465802fb614845bdca5c8ccd7bb1f3bd8da3d81cda343c036bfe2cf1488d32196c7b28ee6eb5d2c7dab40fc96aa2eedf0e
7
+ data.tar.gz: a5c965a55dc5be2683f0f27e98405e7c200ef6f0566ef000b62e760d8150e3e58b57c2e4b74193fd697abfb35949e3c1dfc853adb932fc423ed4109a0065dddf
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ ## Application configuration
29
+ .env
30
+ .env*
31
+ *.log
32
+
33
+ # for a library or gem, you might want to ignore these files since the code is
34
+ # intended to run in multiple environments; otherwise, check them in:
35
+ # Gemfile.lock
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p645
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in leeroy.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ leeroy_app (0.1.0)
5
+ awesome_print (~> 1.6)
6
+ aws-sdk (~> 2)
7
+ chronic (~> 0.10)
8
+ dotenv (~> 2.1)
9
+ gli (~> 2.13)
10
+ hashie (~> 3.4)
11
+ multi_json (~> 1.11)
12
+ rugged (~> 0.23)
13
+ smart_polling (~> 1.0)
14
+ yell (~> 2.0)
15
+ yell-adapters-syslog (~> 2.0)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ aruba (0.11.1)
21
+ childprocess (~> 0.5.6)
22
+ contracts (~> 0.9)
23
+ cucumber (>= 1.3.19)
24
+ event-bus (~> 0.2)
25
+ ffi (~> 1.9.10)
26
+ rspec-expectations (>= 2.99)
27
+ thor (~> 0.19)
28
+ awesome_print (1.6.1)
29
+ aws-sdk (2.2.20)
30
+ aws-sdk-resources (= 2.2.20)
31
+ aws-sdk-core (2.2.20)
32
+ jmespath (~> 1.0)
33
+ aws-sdk-resources (2.2.20)
34
+ aws-sdk-core (= 2.2.20)
35
+ builder (3.2.2)
36
+ childprocess (0.5.9)
37
+ ffi (~> 1.0, >= 1.0.11)
38
+ chronic (0.10.2)
39
+ coderay (1.1.0)
40
+ contracts (0.12.0)
41
+ cucumber (2.1.0)
42
+ builder (>= 2.1.2)
43
+ cucumber-core (~> 1.3.0)
44
+ diff-lcs (>= 1.1.3)
45
+ gherkin3 (~> 3.1.0)
46
+ multi_json (>= 1.7.5, < 2.0)
47
+ multi_test (>= 0.1.2)
48
+ cucumber-core (1.3.1)
49
+ gherkin3 (~> 3.1.0)
50
+ diff-lcs (1.2.5)
51
+ dotenv (2.1.0)
52
+ event-bus (0.2.3)
53
+ ffi (1.9.10)
54
+ gherkin3 (3.1.2)
55
+ gli (2.13.4)
56
+ hashie (3.4.3)
57
+ jmespath (1.1.3)
58
+ method_source (0.8.2)
59
+ multi_json (1.11.2)
60
+ multi_test (0.1.2)
61
+ pry (0.10.3)
62
+ coderay (~> 1.1.0)
63
+ method_source (~> 0.8.1)
64
+ slop (~> 3.4)
65
+ pry-awesome_print (9.6.10)
66
+ awesome_print (>= 1.1.0, < 999)
67
+ pry (>= 0.9.0, < 999)
68
+ rake (10.4.2)
69
+ rspec (3.4.0)
70
+ rspec-core (~> 3.4.0)
71
+ rspec-expectations (~> 3.4.0)
72
+ rspec-mocks (~> 3.4.0)
73
+ rspec-core (3.4.1)
74
+ rspec-support (~> 3.4.0)
75
+ rspec-expectations (3.4.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.4.0)
78
+ rspec-mocks (3.4.1)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.4.0)
81
+ rspec-support (3.4.1)
82
+ rugged (0.23.3)
83
+ slop (3.6.0)
84
+ smart_polling (1.0.0)
85
+ thor (0.19.1)
86
+ yell (2.0.5)
87
+ yell-adapters-syslog (2.0.2)
88
+ yell (~> 2.0)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ aruba (~> 0.11.1)
95
+ bundler (~> 1.6)
96
+ leeroy_app!
97
+ pry (~> 0.10)
98
+ pry-awesome_print (~> 9.6)
99
+ rake (~> 10.0)
100
+ rspec (~> 3.3)
101
+
102
+ BUNDLED WITH
103
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 FitnessKeeper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # leeroy
2
+ o rly? ya rly!
3
+
4
+ ## Installation/Configuration
5
+
6
+ ### Development
7
+
8
+ $ bundle install
9
+ $ ./bin/leeroy env -d > .env
10
+ $ $EDITOR .env
11
+
12
+ ### Production
13
+
14
+ $ gem install leeroy_app
15
+ $ leeroy env -p -d >> ~/.profile
16
+ $ $EDITOR ~/.profile
17
+
18
+ ## Usage
19
+
20
+ ### General
21
+
22
+ leeroy is a "git-like" application; it takes GNU-style command-line options, global options come before the subcommand, command-specific options come after the subcommand.
23
+
24
+ $ leeroy --help
25
+
26
+ ### Jenkins workflow
27
+
28
+ Create a new gold master image:
29
+
30
+ $ leeroy instantiate --phase gold_master | leeroy image | leeroy terminate
31
+
32
+ Create a new application image:
33
+
34
+ $ leeroy instantiate --phase application | leeroy image | leeroy terminate
35
+
36
+ ### Provisioning workflow
37
+
38
+ FIXME not implemented yet
39
+
40
+ $ leeroy bootstrap | leeroy provision
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "dotenv/tasks"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
data/bin/leeroy ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ if ENV['ENVIRONMENT'] == 'development'
7
+ require 'bundler/setup'
8
+ require 'pry'
9
+ end
10
+
11
+ lib = File.expand_path('../lib', __FILE__)
12
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
13
+
14
+ require 'leeroy/app'
15
+
16
+ include Leeroy::App
17
+
18
+ # vim: set et fenc= ft=ruby ff=unix sts=2 sw=2 ts=2 :
data/hierarchy.md ADDED
@@ -0,0 +1,39 @@
1
+ ## General principles
2
+
3
+ * Objects interact with the world outside the program (_e.g._ I/O)
4
+ * Objects contain state
5
+ * Modules provide traits/behaviors/information common to multiple objects (_e.g._ logging)
6
+ * The Leeroy::App namespace defines the CLI (commands, runtime configuration)
7
+ * The Leeroy::Data namespace defines the persistence layer
8
+ * The Leeroy::Task namespace defines the application's capabilities
9
+ * The Leeroy::Helpers namespace contains only helper modules, no class definitions
10
+
11
+ ## Hierarchy
12
+
13
+ classes are marked with `*`
14
+
15
+ ```
16
+ Leeroy
17
+
18
+ Leeroy::App
19
+ Leeroy::App::Command
20
+ Leeroy::App::Command::Config
21
+ Leeroy::App::Command::Env
22
+ Leeroy::App::Command::State
23
+ Leeroy::App::Command::Task
24
+ Leeroy::App::Command::Version
25
+
26
+ Leeroy::Helpers
27
+ Leeroy::Helpers::AWS
28
+ Leeroy::Helpers::Env
29
+ Leeroy::Helpers::Polling
30
+ Leeroy::Helpers::State
31
+
32
+ Leeroy::Task
33
+ Leeroy::Task::Base *
34
+ Leeroy::Task::RunInstance *
35
+ Leeroy::Task::ImageInstance *
36
+ Leeroy::Task::TerminateInstance *
37
+
38
+ Leeroy::Version
39
+ ```
data/leeroy.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'leeroy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "leeroy_app"
8
+ spec.version = Leeroy::VERSION
9
+ spec.authors = ["Steve Huff"]
10
+ spec.email = ["steve.huff@runkeeper.com"]
11
+ spec.summary = %q{Automate tasks with Jenkins}
12
+ spec.description = %q{Leeroy is a framework and CLI app that captures common features required at various points in a CI pipeline. It is designed to be invoked interactively or from Jenkins scripts.}
13
+ spec.homepage = "https://github.com/FitnessKeeper/leeroy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ # external dependencies for building gems
22
+ spec.requirements << 'LibGit2 dependencies for rugged: https://github.com/libgit2/libgit2#optional-dependencies, also CMake and pkg-config'
23
+
24
+ spec.add_development_dependency "aruba", "~> 0.11.1"
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.3"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+ spec.add_development_dependency "pry-awesome_print", "~> 9.6"
30
+
31
+ spec.add_runtime_dependency "awesome_print", "~> 1.6"
32
+ spec.add_runtime_dependency "aws-sdk", "~> 2"
33
+ spec.add_runtime_dependency "chronic", "~> 0.10"
34
+ spec.add_runtime_dependency "dotenv", "~> 2.1"
35
+ spec.add_runtime_dependency "gli", "~> 2.13"
36
+ spec.add_runtime_dependency "hashie", "~> 3.4"
37
+ spec.add_runtime_dependency "multi_json", "~> 1.11"
38
+ spec.add_runtime_dependency "rugged", "~> 0.23"
39
+ spec.add_runtime_dependency "smart_polling", "~> 1.0"
40
+ spec.add_runtime_dependency "yell", "~> 2.0"
41
+ spec.add_runtime_dependency "yell-adapters-syslog", "~> 2.0"
42
+ end
data/lib/leeroy/app.rb ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gli'
4
+
5
+ require 'leeroy'
6
+ require 'leeroy/task/image'
7
+ require 'leeroy/task/instantiate'
8
+ require 'leeroy/task/terminate'
9
+ require 'leeroy/task/sleep'
10
+ require 'leeroy/task/stub'
11
+
12
+ include GLI::App
13
+
14
+ module Leeroy
15
+ module App
16
+
17
+ # constants
18
+ VALID_PHASE = ['gold_master','application']
19
+
20
+ program_desc 'Automate tasks with Jenkins'
21
+
22
+ # global options
23
+ desc "Perform the requested task (pass '--no-op' for testing)."
24
+ switch [:op], :default_value => true
25
+
26
+ desc 'Displays the version of leeroy and exits.'
27
+ command :version do |c|
28
+ c.action do |global_options,options,args|
29
+ printf("leeroy %s\n", Leeroy::VERSION)
30
+ end
31
+ end
32
+
33
+ desc "Displays leeroy's environment settings."
34
+ command :env do |c|
35
+ c.desc "Use default environment settings instead of reading from shell environment."
36
+ c.switch :default, :d
37
+
38
+ c.desc "Format environment settings for use in .profile."
39
+ c.switch :profile, :p
40
+
41
+ c.action do |global_options,options,args|
42
+ puts Leeroy::Env.new(options).to_s
43
+ end
44
+ end
45
+
46
+ desc "Instantiates an EC2 instance for imaging."
47
+ command :instantiate do |c|
48
+
49
+ valid_phase = VALID_PHASE
50
+ c.desc "Phase of deploy process for which to deploy (must be one of #{valid_phase.sort})."
51
+ c.flag [:p, :phase], :must_match => valid_phase
52
+
53
+ c.action do |global_options,options,args|
54
+ # validate input
55
+ unless options[:phase].nil? or valid_phase.include?(options[:phase])
56
+ help_now! "Valid arguments for '--phase' are: #{valid_phase.sort.join(',')}."
57
+ end
58
+
59
+ task = Leeroy::Task::Instantiate.new(global_options: global_options, options: options, args: args)
60
+ task.perform
61
+ end
62
+ end
63
+
64
+ desc "Terminates an EC2 instance."
65
+ command :terminate do |c|
66
+
67
+ c.desc "Instance ID (or IDs as comma-delimited strings) to terminate (reads from state if none provided)."
68
+ c.flag [:i, :instance], :type => Array
69
+
70
+ c.action do |global_options,options,args|
71
+ task = Leeroy::Task::Terminate.new(global_options: global_options, options: options, args: args)
72
+ task.perform
73
+ end
74
+ end
75
+
76
+ desc "Creates an image from a running EC2 instance."
77
+ command :image do |c|
78
+
79
+ valid_phase = VALID_PHASE
80
+ c.desc "Phase of deploy process for which to deploy (must be one of #{valid_phase.sort})."
81
+ c.flag [:p, :phase]
82
+
83
+ c.desc "Instance ID from which to image (optional, will be extracted from state if not provided)."
84
+ c.flag [:i, :instance]
85
+
86
+ c.desc "Image index (optional, will be calculated if not provided)."
87
+ c.flag [:n, :index]
88
+
89
+ c.action do |global_options,options,args|
90
+ # validate input
91
+ unless options[:phase].nil? or valid_phase.include?(options[:phase])
92
+ help_now! "Valid arguments for '--phase' are: #{valid_phase.sort.join(',')}."
93
+ end
94
+
95
+ # index must be nil or must look like a positive integer
96
+ begin
97
+ unless options[:index].nil? or options[:index].to_i > 0
98
+ help_now! "The argument for '--index' must be a positive integer."
99
+ end
100
+
101
+ rescue NoMethodError => e
102
+ help_now! "The argument for '--index' must be a positive integer."
103
+ end
104
+
105
+ task = Leeroy::Task::Image.new(global_options: global_options, options: options, args: args)
106
+ task.perform
107
+ end
108
+ end
109
+
110
+ desc "Sleeps for some number of seconds."
111
+ command :sleep do |c|
112
+ c.desc "Number of seconds to sleep."
113
+ c.flag [:i, :interval], :default_value => 2
114
+
115
+ c.action do |global_options,options,args|
116
+ Leeroy::Task::Sleep.new(global_options: global_options, options: options, args: args).perform
117
+ end
118
+ end
119
+
120
+ desc "Runs the stub task."
121
+ command :stub do |c|
122
+ c.desc "Amount by which to increment the stub value"
123
+ c.flag [:i, :increment], :default_value => 1
124
+ c.action do |global_options,options,args|
125
+ task = Leeroy::Task::Stub.new(global_options: global_options, options: options, args: args)
126
+ task.perform
127
+ end
128
+ end
129
+
130
+ exit run(ARGV)
131
+ end
132
+ end
data/lib/leeroy/env.rb ADDED
@@ -0,0 +1,116 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ require 'leeroy/types/mash'
5
+ require 'leeroy/helpers/dumpable'
6
+ require 'leeroy/helpers/env'
7
+ require 'leeroy/helpers/logging'
8
+
9
+ module Leeroy
10
+ class Env < Leeroy::Types::Mash
11
+ include Leeroy::Helpers::Dumpable
12
+ include Leeroy::Helpers::Env
13
+ include Leeroy::Helpers::Logging
14
+
15
+ # constants
16
+ S3_PREFIXES = {
17
+ :secrets => 'secrets',
18
+ :jenkins => 'jenkins',
19
+ :builds => 'builds',
20
+ :logs => 'logs',
21
+ :semaphores => 'semaphores',
22
+ :tests => 'tests',
23
+ }
24
+
25
+ ENV_DEFAULTS = {
26
+ 'LEEROY_APP_NAME' => '<identifying string, e.g. "tomcat7">',
27
+ 'LEEROY_AWS_LINUX_AMI' => '<AMI ID to be used as base for gold master>',
28
+ 'LEEROY_BUILD_INSTANCE_TYPE' => '<EC2 instance type to be used for imaging>',
29
+ 'LEEROY_BUILD_PROFILE_NAME' => '<IAM instance profile name to be applied to imaging instances>',
30
+ 'LEEROY_BUILD_SECURITY_GROUP' => '<VPC security group name to be applied to imaging instances>',
31
+ 'LEEROY_BUILD_SSH_KEYPAIR' => '<SSH keypair name for access to imaging instances>',
32
+ 'LEEROY_BUILD_SUBNET' => '<VPC subnet name to be applied to imaging instances>',
33
+ 'LEEROY_BUILD_TARGET' => '<identifying string for application build, e.g. "webapi" or "stage20">',
34
+ 'LEEROY_BUILD_VPC' => '<VPC name in which imaging instances are created>',
35
+ 'LEEROY_GOLD_MASTER_IMAGE_PREFIX' => '<identifying string used to generate AMI names>',
36
+ 'LEEROY_GOLD_MASTER_NAME' => '<identifying string used to tag gold master instances during imaging>',
37
+ 'LEEROY_POLL_INTERVAL' => '<number of seconds to wait between polling for long-running AWS operations>',
38
+ 'LEEROY_POLL_TIMEOUT' => '<number of seconds to wait between giving up on long-running AWS operations>',
39
+ 'LEEROY_PROVISIONING_TEMPLATE_PREFIX' => '<path on local filesystem to directory containing provisioning templates>',
40
+ 'LEEROY_S3_BUCKET' => '<name of bucket used as datastore>',
41
+ 'LEEROY_PROVISIONING_TEMPLATE_PREFIX' => '<path on local filesystem to directory containing user-data templates>',
42
+ }
43
+
44
+ ENV_EXTRAS = {
45
+ 'ENVIRONMENT' => '<development or production>',
46
+ 'GLI_DEBUG' => '<true or false>',
47
+ 'AWS_REGION' => '<your AWS region>',
48
+ }
49
+
50
+ # attr_reader :default, :profile
51
+ attr_reader :profile, :defaults
52
+
53
+ def initialize(options = {}, env = ENV)
54
+ begin
55
+ logger.debug "initializing #{self.class}"
56
+ logger.debug "options: #{options.inspect}"
57
+
58
+ @defaults = options[:default]
59
+ @profile = options[:profile]
60
+
61
+ if self.defaults
62
+ unfiltered = ENV_DEFAULTS
63
+ extras = ENV_EXTRAS
64
+ else
65
+ unfiltered = env
66
+ extras = {}
67
+ end
68
+
69
+ filtered = _filterEnv(unfiltered).merge(extras)
70
+ logger.debug "filtered: #{filtered.inspect}"
71
+
72
+ self.dump_properties = filtered.keys.sort.collect { |x| x.to_sym }
73
+ super(filtered)
74
+
75
+ rescue StandardError => e
76
+ raise e
77
+ end
78
+ end
79
+
80
+ def to_s
81
+ _prettyPrint
82
+ end
83
+
84
+ private
85
+
86
+ def _prettyPrint
87
+ if self.profile
88
+ formatstr = 'export %s=%s'
89
+ header = '# environment variables for leeroy configuration'
90
+ else
91
+ formatstr = '%s=%s'
92
+ header = nil
93
+ end
94
+
95
+ if self.defaults
96
+ formatstr = '# '.concat(formatstr)
97
+ end
98
+
99
+ properties = self.dump_properties.collect {|x| x.to_s}.sort.collect {|x| sprintf(formatstr, x, self.fetch(x))}
100
+
101
+ properties.unshift(header) unless header.nil?
102
+
103
+ properties.join("\n")
104
+ end
105
+
106
+ def _filterEnv(env, prefix = 'LEEROY_')
107
+ begin
108
+ logger.debug("filtering env by prefix '#{prefix}'")
109
+ env.select { |k,v| k.start_with?(prefix) }
110
+
111
+ rescue StandardError => e
112
+ raise e
113
+ end
114
+ end
115
+ end
116
+ end