cloudstrap 0.29.1.pre

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.
@@ -0,0 +1,160 @@
1
+ require 'contracts'
2
+ require 'pastel'
3
+ require 'yaml'
4
+
5
+ module StackatoLKG
6
+ class Config
7
+ include ::Contracts::Core
8
+ include ::Contracts::Builtin
9
+
10
+ Contract None => String
11
+ def region
12
+ @region ||= ENV.fetch('BOOTSTRAP_REGION') do
13
+ config.fetch('region') do
14
+ 'us-west-2'
15
+ end
16
+ end
17
+ end
18
+
19
+ Contract None => String
20
+ def cache_path
21
+ @cache_path ||= ENV.fetch('BOOTSTRAP_CACHE_PATH') do
22
+ config.fetch('cache_path') { [workdir, '.cache'].join('/') }
23
+ end
24
+ end
25
+
26
+ Contract None => String
27
+ def vpc_cidr_block
28
+ @vpc_cidr_block ||= ENV.fetch('BOOTSTRAP_VPC_CIDR_BLOCK') do
29
+ config.fetch('vpc_cidr_block') { '10.0.0.0/16' }
30
+ end
31
+ end
32
+
33
+ Contract None => String
34
+ def public_cidr_block
35
+ @public_cidr_block ||= ENV.fetch('BOOTSTRAP_PUBLIC_CIDR_BLOCK') do
36
+ config.fetch('public_cidr_block') do
37
+ vpc_cidr_block.gsub(/([[:digit:]]{1,3}\.?){2,2}\/[[:digit:]]{1,2}$/, '0.0/24')
38
+ end
39
+ end
40
+ end
41
+
42
+ Contract None => String
43
+ def private_cidr_block
44
+ @private_cidr_block ||= ENV.fetch('BOOTSTRAP_PRIVATE_CIDR_BLOCK') do
45
+ config.fetch('private_cidr_block') do
46
+ vpc_cidr_block.gsub(/([[:digit:]]{1,3}\.?){2,2}\/[[:digit:]]{1,2}$/, '1.0/24')
47
+ end
48
+ end
49
+ end
50
+
51
+ Contract None => String
52
+ def ami_owner
53
+ @ami_owner ||= ENV.fetch('BOOTSTRAP_AMI_OWNER') do
54
+ config.fetch('ami_owner') do
55
+ '099720109477'
56
+ end
57
+ end
58
+ end
59
+
60
+ Contract None => String
61
+ def ubuntu_release
62
+ @distribution ||= ENV.fetch('BOOTSTRAP_UBUNTU_RELEASE') do
63
+ config.fetch('ubuntu_release') do
64
+ '14.04'
65
+ end
66
+ end
67
+ end
68
+
69
+ Contract None => String
70
+ def instance_type
71
+ @instance_type ||= ENV.fetch('BOOTSTRAP_INSTANCE_TYPE') do
72
+ config.fetch('instance_type') do
73
+ 't2.micro'
74
+ end
75
+ end
76
+ end
77
+
78
+ Contract None => String
79
+ def ssh_dir
80
+ @ssh_dir ||= File.expand_path(ENV.fetch('BOOTSTRAP_SSH_DIR') do
81
+ [workdir, '.ssh'].join('/')
82
+ end)
83
+ end
84
+
85
+ Contract None => String
86
+ def ssh_username
87
+ @ssh_username ||= ENV.fetch('BOOTSTRAP_SSH_USERNAME') do
88
+ config.fetch('ssh_username') do
89
+ 'ubuntu'
90
+ end
91
+ end
92
+ end
93
+
94
+ Contract None => String
95
+ def hdp_dir
96
+ @hdp_dir ||= File.expand_path(ENV.fetch('BOOTSTRAP_HDP_DIR') { dir })
97
+ end
98
+
99
+ Contract None => String
100
+ def hdp_origin
101
+ @hdp_origin ||= ENV.fetch('BOOTSTRAP_HDP_BOOTSTRAP_ORIGIN') do
102
+ config.fetch('hdp_bootstrap_origin')
103
+ end
104
+ end
105
+
106
+ Contract None => String
107
+ def hdp_version
108
+ @hdp_archive ||= ENV.fetch('BOOTSTRAP_HDP_BOOTSTRAP_VERSION') do
109
+ config.fetch('hdp_bootstrap_version')
110
+ end
111
+ end
112
+
113
+ Contract None => String
114
+ def hdp_package_url
115
+ @hdp_package_url ||= ENV.fetch('BOOTSTRAP_HDP_BOOTSTRAP_PACKAGE_URL') do
116
+ config.fetch('hdp_bootstrap_package_url') do
117
+ "#{hdp_origin}/hcp-bootstrap_#{hdp_version.gsub('+', '%2B')}_amd64.deb"
118
+ end
119
+ end
120
+ end
121
+
122
+ Contract None => String
123
+ def bootstrap_properties_seed_url
124
+ ENV.fetch('BOOTSTRAP_PROPERTIES_SEED_URL') do
125
+ config.fetch('bootstrap_properties_seed_url')
126
+ end
127
+ end
128
+
129
+ private
130
+
131
+ Contract None => String
132
+ def workdir
133
+ @workdir ||= ENV.fetch('BOOTSTRAP_WORKDIR') { Dir.pwd }
134
+ end
135
+
136
+ Contract None => String
137
+ def dir
138
+ @dir ||= ENV.fetch('BOOTSTRAP_CONFIG_DIR') { workdir }
139
+ end
140
+
141
+ Contract None => String
142
+ def file
143
+ @file ||= ENV.fetch('BOOTSTRAP_CONFIG_FILE') { 'config.yaml' }
144
+ end
145
+
146
+ Contract None => String
147
+ def path
148
+ @path ||= File.expand_path [dir, file].join('/')
149
+ end
150
+
151
+ Contract None => Hash
152
+ def config
153
+ @settings ||= if File.exist?(path)
154
+ YAML.load_file(path)
155
+ else
156
+ {}
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,76 @@
1
+ require 'contracts'
2
+ require 'java-properties'
3
+
4
+ require_relative '../config'
5
+ require_relative '../seed_properties'
6
+
7
+ module StackatoLKG
8
+ module HDP
9
+ class BootstrapProperties
10
+ include ::Contracts::Core
11
+ include ::Contracts::Builtin
12
+
13
+ Contract None => Hash
14
+ def properties
15
+ @properties ||= load!
16
+ end
17
+
18
+ Contract RespondTo[:to_sym], String => BootstrapProperties
19
+ def update!(property, value)
20
+ update(property, value).tap do
21
+ save!
22
+ end
23
+ end
24
+
25
+ Contract RespondTo[:to_sym], String => BootstrapProperties
26
+ def update(property, value)
27
+ raise KeyError unless properties.has_key? property.to_sym
28
+
29
+ properties.store property.to_sym, value
30
+
31
+ self
32
+ end
33
+
34
+ Contract None => Bool
35
+ def save!
36
+ JavaProperties.write(properties, file) ? true : false
37
+ end
38
+
39
+ Contract None => String
40
+ def file
41
+ @file ||= [config.hdp_dir, 'bootstrap.properties'].join('/')
42
+ end
43
+
44
+ private
45
+
46
+ Contract None => ::Cloudstrap::SeedProperties
47
+ def seed
48
+ @seed ||= ::Cloudstrap::SeedProperties.new
49
+ end
50
+
51
+ Contract None => Bool
52
+ def exist?
53
+ File.exist?(file)
54
+ end
55
+
56
+ Contract None => Hash
57
+ def load
58
+ if exist?
59
+ JavaProperties.load file
60
+ else
61
+ JavaProperties.parse seed.contents
62
+ end
63
+ end
64
+
65
+ Contract None => Hash
66
+ def load!
67
+ @properties = load
68
+ end
69
+
70
+ Contract None => ::StackatoLKG::Config
71
+ def config
72
+ @config ||= ::StackatoLKG::Config.new
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ require 'contracts'
2
+ require 'faraday'
3
+ require_relative 'config'
4
+
5
+ module Cloudstrap
6
+ class SeedProperties
7
+ include ::Contracts::Core
8
+ include ::Contracts::Builtin
9
+
10
+ Contract None => String
11
+ def source
12
+ config.bootstrap_properties_seed_url
13
+ end
14
+
15
+ Contract None => ::Faraday::Response
16
+ def connection
17
+ @connection ||= ::Faraday.get source
18
+ end
19
+
20
+ Contract None => Maybe[String]
21
+ def contents
22
+ @contents ||= connection.body if connection.success?
23
+ end
24
+
25
+ Contract None => ::StackatoLKG::Config
26
+ def config
27
+ @config ||= ::StackatoLKG::Config.new
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'ssh/client'
2
+ require_relative 'ssh/key'
@@ -0,0 +1,36 @@
1
+ require 'contracts'
2
+ require 'sshkit'
3
+
4
+ module StackatoLKG
5
+ module SSH
6
+ class Client
7
+ include ::Contracts::Core
8
+ include ::Contracts::Builtin
9
+
10
+ Contract String => Client
11
+ def initialize(private_key) # TODO: Eliminate side-effects
12
+ ::SSHKit::Backend::Netssh.configure do |ssh|
13
+ ssh.ssh_options = {
14
+ config: false,
15
+ auth_methods: ['publickey'],
16
+ keys: private_key
17
+ }
18
+ end
19
+
20
+ self
21
+ end
22
+
23
+ Contract String, Proc => Any
24
+ def to(host, &block)
25
+ ::SSHKit::Coordinator.new("#{config.ssh_username}@#{host}").each(&block)
26
+ end
27
+
28
+ private
29
+
30
+ Contract None => ::StackatoLKG::Config
31
+ def config
32
+ @config ||= ::StackatoLKG::Config.new
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,82 @@
1
+ require 'contracts'
2
+ require 'sshkey'
3
+ require_relative '../config'
4
+
5
+ module StackatoLKG
6
+ module SSH
7
+ class Key
8
+ include ::Contracts::Core
9
+ include ::Contracts::Builtin
10
+
11
+ Contract String, KeywordArgs[ephemeral: Optional[Bool]] => Key
12
+ def initialize(name, **with_options)
13
+ @name = name
14
+ if loadable? then load else generate(with_options) end
15
+ self
16
+ end
17
+
18
+ Contract None => String
19
+ def to_s
20
+ @key.ssh_public_key
21
+ end
22
+
23
+ Contract None => ::SSHKey
24
+ def load
25
+ @key ||= load!
26
+ end
27
+
28
+ Contract None => ::SSHKey
29
+ def load!
30
+ @key = ::SSHKey.new(File.read private_file).tap do |key|
31
+ raise ::EncodingError unless valid?(key.ssh_public_key)
32
+ end
33
+ end
34
+
35
+ Contract ::SSHKey => ::SSHKey
36
+ def save(key)
37
+ FileUtils.mkdir_p dir
38
+ File.write public_file, key.ssh_public_key
39
+ File.write private_file, key.private_key
40
+ File.chmod 0400, private_file
41
+ load!
42
+ end
43
+
44
+ Contract KeywordArgs[ephemeral: Optional[Bool]] => ::SSHKey
45
+ def generate(ephemeral: false)
46
+ ::SSHKey.generate(type: 'RSA', comment: @name).tap do |key|
47
+ save key unless ephemeral
48
+ end
49
+ end
50
+
51
+ Contract None => Bool
52
+ def loadable?
53
+ File.readable? private_file
54
+ end
55
+
56
+ Contract None => String
57
+ def public_file
58
+ @public_file ||= [private_file, 'pub'].join('.')
59
+ end
60
+
61
+ Contract None => String
62
+ def private_file
63
+ @private_file ||= [dir, File.basename(@name)].join('/')
64
+ end
65
+
66
+ private
67
+
68
+ Contract String => Bool
69
+ def valid?(public_key)
70
+ ::SSHKey.valid_ssh_public_key? public_key
71
+ end
72
+
73
+ Contract None => String
74
+ def dir
75
+ @dir ||= [
76
+ ::StackatoLKG::Config.new.ssh_dir,
77
+ File.dirname(@name)
78
+ ].join('/')
79
+ end
80
+ end
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudstrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.29.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Chris Olstrom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.5.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: contracts
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.14'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.14.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.14'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.14.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: retries
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 0.0.5
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.5
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.5
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.5
73
+ - !ruby/object:Gem::Dependency
74
+ name: moneta
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.8'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.8.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: sshkey
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.8'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.8.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.8'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.8.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: sshkit
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.11'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.11.0
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.11'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 1.11.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: java-properties
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.1'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.1.1
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.1'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.1.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: pastel
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.6'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 0.6.0
163
+ type: :runtime
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '0.6'
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 0.6.0
173
+ - !ruby/object:Gem::Dependency
174
+ name: faraday
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '0.9'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 0.9.0
183
+ type: :runtime
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '0.9'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 0.9.0
193
+ description:
194
+ email: chris@olstrom.com
195
+ executables:
196
+ - cloudstrap
197
+ extensions: []
198
+ extra_rdoc_files: []
199
+ files:
200
+ - ".gitignore"
201
+ - LICENSE.txt
202
+ - README.org
203
+ - bin/cloudstrap
204
+ - cloudstrap.gemspec
205
+ - lib/cloudstrap.rb
206
+ - lib/cloudstrap/amazon.rb
207
+ - lib/cloudstrap/amazon/ec2.rb
208
+ - lib/cloudstrap/amazon/iam.rb
209
+ - lib/cloudstrap/amazon/service.rb
210
+ - lib/cloudstrap/amazon/support/rate_limit_handler.rb
211
+ - lib/cloudstrap/bootstrap_agent.rb
212
+ - lib/cloudstrap/config.rb
213
+ - lib/cloudstrap/hdp/bootstrap_properties.rb
214
+ - lib/cloudstrap/seed_properties.rb
215
+ - lib/cloudstrap/ssh.rb
216
+ - lib/cloudstrap/ssh/client.rb
217
+ - lib/cloudstrap/ssh/key.rb
218
+ homepage: https://github.com/colstrom/cloudstrap
219
+ licenses:
220
+ - MIT
221
+ metadata: {}
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">"
234
+ - !ruby/object:Gem::Version
235
+ version: 1.3.1
236
+ requirements: []
237
+ rubyforge_project:
238
+ rubygems_version: 2.5.1
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Strapping Boots to Clouds
242
+ test_files: []