bootscript 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'bootscript'
2
+
3
+ describe Bootscript do
4
+ describe :DEFAULT_VARS do
5
+ it "provides some sane default template variables" do
6
+ [ :platform, :startup_command,
7
+ :create_ramdisk, :ramdisk_size, :ramdisk_mount,
8
+ :add_script_tags
9
+ ].each do |required_var|
10
+ Bootscript::DEFAULT_VARS.should include(required_var)
11
+ Bootscript::DEFAULT_VARS[required_var].should_not be nil
12
+ end
13
+ end
14
+ end
15
+
16
+ describe :generate do
17
+ before :each do
18
+ @template_vars = {key1: :value1, key2: :value2}
19
+ @data_map = {'/use/local/bin/hello.sh' => "echo Hello!\n"}
20
+ @script = Bootscript::Script.new
21
+ end
22
+ it "accepts a Hash of template vars and a data map" do
23
+ Bootscript.generate(@template_vars, @data_map)
24
+ end
25
+ it "creates a Script with the same data map" do
26
+ Bootscript::Script.stub(:new).and_return @script
27
+ @script.should_receive(:data_map=).with @data_map
28
+ Bootscript.generate(@template_vars, @data_map)
29
+ end
30
+ it "calls generate() on the script, passing the same template vars" do
31
+ Bootscript::Script.stub(:new).and_return @script
32
+ @script.should_receive(:generate).with(@template_vars, nil)
33
+ Bootscript.generate(@template_vars, @data_map)
34
+ end
35
+ end
36
+
37
+ # determines whether Windows is the boot target for a given set of ERB vars
38
+ describe :windows? do
39
+ [:windows, :WinDoWs, 'windows', 'WINDOWS'].each do |value|
40
+ context "its Hash argument has :platform => #{value} (#{value.class})" do
41
+ it "returns true" do
42
+ Bootscript.windows?(platform: value).should be true
43
+ end
44
+ end
45
+ end
46
+ [:unix, :OS_X, 'other', 'randomstring0940358'].each do |value|
47
+ context "its Hash argument has :platform => #{value} (#{value.class})" do
48
+ it "returns false" do
49
+ Bootscript.windows?(platform: value).should be false
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ describe :default_logger do
56
+ context "with no arguments" do
57
+ it "returns a Ruby Logger with LOG_LEVEL set to FATAL" do
58
+ logger = Bootscript.default_logger
59
+ logger.level.should be Logger::FATAL
60
+ end
61
+ end
62
+ context "with a specific log level" do
63
+ [Logger::DEBUG, Logger::INFO, Logger::WARN].each do |log_level|
64
+ it "returns a standard Ruby Logger with level #{log_level}" do
65
+ logger = Bootscript.default_logger(STDOUT, log_level)
66
+ logger.level.should be log_level
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require "#{File.dirname __FILE__}/unpacker"
4
+ require 'rspec'
5
+ RSpec.configure do |c|
6
+ c.mock_with :rspec
7
+ end
8
+ require 'bootscript'
@@ -0,0 +1,40 @@
1
+ module Bootscript
2
+ require 'open3'
3
+
4
+ # a utility class for testing BootScripts
5
+ # only suitable for BootScripts that fit in memory!
6
+ class Unpacker
7
+
8
+ attr_reader :config, :text, :command
9
+
10
+ @text # the actual text of the rendered BootScript
11
+
12
+ def initialize(script_text)
13
+ @text = script_text
14
+ @config = Hash.new
15
+ parse
16
+ end
17
+
18
+ def parse
19
+ # try to grab Bash config statements from the text of the script
20
+ @text.each_line do |line|
21
+ break if line =~ /\A__ARCHIVE_FOLLOWS__/
22
+ if matches = line.match(%r{(\w+)=(.*)})
23
+ key, value = matches[1], matches[2]
24
+ value.gsub!(/\A['"]+|['"]+\Z/, "") # strip quotes
25
+ @config[key] = value
26
+ end
27
+ end
28
+ end
29
+
30
+ # extracts the contents of the BootScript's archive into dir
31
+ def unpack_to(dir)
32
+ Open3.popen3('uudecode -o /dev/stdout | tar xz', chdir: dir) do
33
+ |stdin, stdout, stderr, thread|
34
+ stdin.write @text
35
+ stderr.read # (why is this is needed for successfull unpacking?)
36
+ end
37
+ end
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootscript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Benton Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erubis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyzip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ZenTest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Constructs a self-extracting archive, wrapped in a script, for securely
140
+ initializing cloud systems
141
+ email:
142
+ - benton@bentonroberts.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - .gitignore
148
+ - .rspec
149
+ - ERB_VARS.md
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bootscript.gemspec
155
+ - lib/bootscript.rb
156
+ - lib/bootscript/chef.rb
157
+ - lib/bootscript/script.rb
158
+ - lib/bootscript/uu_writer.rb
159
+ - lib/bootscript/version.rb
160
+ - lib/templates/bootscript.ps1.erb
161
+ - lib/templates/bootscript.sh.erb
162
+ - lib/templates/chef/attributes.json.erb
163
+ - lib/templates/chef/chef-install.ps1.erb
164
+ - lib/templates/chef/chef-install.sh.erb
165
+ - lib/templates/chef/chef_client.conf.erb
166
+ - lib/templates/chef/json_attributes.rb.erb
167
+ - lib/templates/chef/ramdisk_secrets.rb.erb
168
+ - lib/templates/windows_footer.bat.erb
169
+ - lib/templates/windows_header.bat.erb
170
+ - spec/bootscript/chef_spec.rb
171
+ - spec/bootscript/script_spec.rb
172
+ - spec/bootscript/uu_writer_spec.rb
173
+ - spec/bootscript_spec.rb
174
+ - spec/spec_helper.rb
175
+ - spec/unpacker.rb
176
+ homepage: http://github.com/benton/bootscript
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.2.1
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Constructs a self-extracting archive, wrapped in a script, for securely initializing
200
+ cloud systems
201
+ test_files:
202
+ - spec/bootscript/chef_spec.rb
203
+ - spec/bootscript/script_spec.rb
204
+ - spec/bootscript/uu_writer_spec.rb
205
+ - spec/bootscript_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/unpacker.rb
208
+ has_rdoc: