startapp 0.1.6

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 (156) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +95 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/rhc_bash +1672 -0
  7. data/bin/app +37 -0
  8. data/conf/express.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +191 -0
  11. data/features/deployments_feature.rb +129 -0
  12. data/features/domains_feature.rb +58 -0
  13. data/features/keys_feature.rb +37 -0
  14. data/features/members_feature.rb +166 -0
  15. data/lib/rhc/auth/basic.rb +64 -0
  16. data/lib/rhc/auth/token.rb +102 -0
  17. data/lib/rhc/auth/token_store.rb +53 -0
  18. data/lib/rhc/auth.rb +5 -0
  19. data/lib/rhc/autocomplete.rb +66 -0
  20. data/lib/rhc/autocomplete_templates/bash.erb +39 -0
  21. data/lib/rhc/cartridge_helpers.rb +118 -0
  22. data/lib/rhc/cli.rb +40 -0
  23. data/lib/rhc/command_runner.rb +185 -0
  24. data/lib/rhc/commands/account.rb +25 -0
  25. data/lib/rhc/commands/alias.rb +124 -0
  26. data/lib/rhc/commands/app.rb +726 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +115 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +329 -0
  31. data/lib/rhc/commands/clone.rb +66 -0
  32. data/lib/rhc/commands/configure.rb +20 -0
  33. data/lib/rhc/commands/create.rb +100 -0
  34. data/lib/rhc/commands/delete.rb +19 -0
  35. data/lib/rhc/commands/deploy.rb +32 -0
  36. data/lib/rhc/commands/deployment.rb +82 -0
  37. data/lib/rhc/commands/domain.rb +172 -0
  38. data/lib/rhc/commands/env.rb +142 -0
  39. data/lib/rhc/commands/force_stop.rb +17 -0
  40. data/lib/rhc/commands/git_clone.rb +34 -0
  41. data/lib/rhc/commands/logout.rb +51 -0
  42. data/lib/rhc/commands/logs.rb +21 -0
  43. data/lib/rhc/commands/member.rb +148 -0
  44. data/lib/rhc/commands/port_forward.rb +197 -0
  45. data/lib/rhc/commands/reload.rb +17 -0
  46. data/lib/rhc/commands/restart.rb +17 -0
  47. data/lib/rhc/commands/scp.rb +54 -0
  48. data/lib/rhc/commands/server.rb +40 -0
  49. data/lib/rhc/commands/setup.rb +60 -0
  50. data/lib/rhc/commands/show.rb +43 -0
  51. data/lib/rhc/commands/snapshot.rb +137 -0
  52. data/lib/rhc/commands/ssh.rb +51 -0
  53. data/lib/rhc/commands/sshkey.rb +97 -0
  54. data/lib/rhc/commands/start.rb +17 -0
  55. data/lib/rhc/commands/stop.rb +17 -0
  56. data/lib/rhc/commands/tail.rb +47 -0
  57. data/lib/rhc/commands/threaddump.rb +14 -0
  58. data/lib/rhc/commands/tidy.rb +17 -0
  59. data/lib/rhc/commands.rb +396 -0
  60. data/lib/rhc/config.rb +321 -0
  61. data/lib/rhc/context_helper.rb +121 -0
  62. data/lib/rhc/core_ext.rb +202 -0
  63. data/lib/rhc/coverage_helper.rb +33 -0
  64. data/lib/rhc/deployment_helpers.rb +111 -0
  65. data/lib/rhc/exceptions.rb +256 -0
  66. data/lib/rhc/git_helpers.rb +106 -0
  67. data/lib/rhc/help_formatter.rb +55 -0
  68. data/lib/rhc/helpers.rb +481 -0
  69. data/lib/rhc/highline_extensions.rb +479 -0
  70. data/lib/rhc/json.rb +51 -0
  71. data/lib/rhc/output_helpers.rb +260 -0
  72. data/lib/rhc/rest/activation.rb +11 -0
  73. data/lib/rhc/rest/alias.rb +42 -0
  74. data/lib/rhc/rest/api.rb +87 -0
  75. data/lib/rhc/rest/application.rb +348 -0
  76. data/lib/rhc/rest/attributes.rb +36 -0
  77. data/lib/rhc/rest/authorization.rb +8 -0
  78. data/lib/rhc/rest/base.rb +79 -0
  79. data/lib/rhc/rest/cartridge.rb +162 -0
  80. data/lib/rhc/rest/client.rb +650 -0
  81. data/lib/rhc/rest/deployment.rb +18 -0
  82. data/lib/rhc/rest/domain.rb +98 -0
  83. data/lib/rhc/rest/environment_variable.rb +15 -0
  84. data/lib/rhc/rest/gear_group.rb +16 -0
  85. data/lib/rhc/rest/httpclient.rb +145 -0
  86. data/lib/rhc/rest/key.rb +44 -0
  87. data/lib/rhc/rest/membership.rb +105 -0
  88. data/lib/rhc/rest/mock.rb +1042 -0
  89. data/lib/rhc/rest/user.rb +32 -0
  90. data/lib/rhc/rest.rb +148 -0
  91. data/lib/rhc/scp_helpers.rb +27 -0
  92. data/lib/rhc/ssh_helpers.rb +380 -0
  93. data/lib/rhc/tar_gz.rb +51 -0
  94. data/lib/rhc/usage_templates/command_help.erb +51 -0
  95. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  96. data/lib/rhc/usage_templates/help.erb +61 -0
  97. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  98. data/lib/rhc/usage_templates/options_help.erb +12 -0
  99. data/lib/rhc/vendor/okjson.rb +600 -0
  100. data/lib/rhc/vendor/parseconfig.rb +178 -0
  101. data/lib/rhc/vendor/sshkey.rb +253 -0
  102. data/lib/rhc/vendor/zliby.rb +628 -0
  103. data/lib/rhc/version.rb +5 -0
  104. data/lib/rhc/wizard.rb +637 -0
  105. data/lib/rhc.rb +34 -0
  106. data/spec/coverage_helper.rb +82 -0
  107. data/spec/direct_execution_helper.rb +339 -0
  108. data/spec/keys/example.pem +23 -0
  109. data/spec/keys/example_private.pem +27 -0
  110. data/spec/keys/server.pem +19 -0
  111. data/spec/rest_spec_helper.rb +31 -0
  112. data/spec/rhc/assets/cert.crt +22 -0
  113. data/spec/rhc/assets/cert_key_rsa +27 -0
  114. data/spec/rhc/assets/empty.txt +0 -0
  115. data/spec/rhc/assets/env_vars.txt +7 -0
  116. data/spec/rhc/assets/env_vars_2.txt +1 -0
  117. data/spec/rhc/assets/foo.txt +1 -0
  118. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  119. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  120. data/spec/rhc/auth_spec.rb +442 -0
  121. data/spec/rhc/cli_spec.rb +186 -0
  122. data/spec/rhc/command_spec.rb +435 -0
  123. data/spec/rhc/commands/account_spec.rb +42 -0
  124. data/spec/rhc/commands/alias_spec.rb +333 -0
  125. data/spec/rhc/commands/app_spec.rb +777 -0
  126. data/spec/rhc/commands/apps_spec.rb +39 -0
  127. data/spec/rhc/commands/authorization_spec.rb +157 -0
  128. data/spec/rhc/commands/cartridge_spec.rb +665 -0
  129. data/spec/rhc/commands/clone_spec.rb +41 -0
  130. data/spec/rhc/commands/deployment_spec.rb +327 -0
  131. data/spec/rhc/commands/domain_spec.rb +401 -0
  132. data/spec/rhc/commands/env_spec.rb +493 -0
  133. data/spec/rhc/commands/git_clone_spec.rb +102 -0
  134. data/spec/rhc/commands/logout_spec.rb +86 -0
  135. data/spec/rhc/commands/member_spec.rb +247 -0
  136. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  137. data/spec/rhc/commands/scp_spec.rb +77 -0
  138. data/spec/rhc/commands/server_spec.rb +69 -0
  139. data/spec/rhc/commands/setup_spec.rb +118 -0
  140. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  141. data/spec/rhc/commands/ssh_spec.rb +163 -0
  142. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  143. data/spec/rhc/commands/tail_spec.rb +81 -0
  144. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  145. data/spec/rhc/config_spec.rb +407 -0
  146. data/spec/rhc/helpers_spec.rb +531 -0
  147. data/spec/rhc/highline_extensions_spec.rb +314 -0
  148. data/spec/rhc/json_spec.rb +30 -0
  149. data/spec/rhc/rest_application_spec.rb +258 -0
  150. data/spec/rhc/rest_client_spec.rb +752 -0
  151. data/spec/rhc/rest_spec.rb +740 -0
  152. data/spec/rhc/targz_spec.rb +55 -0
  153. data/spec/rhc/wizard_spec.rb +756 -0
  154. data/spec/spec_helper.rb +575 -0
  155. data/spec/wizard_spec_helper.rb +330 -0
  156. metadata +469 -0
@@ -0,0 +1,330 @@
1
+
2
+ module WizardStepsHelper
3
+ def should_greet_user
4
+ next_stage.should_not be_nil
5
+
6
+ last_output do |s|
7
+ s.count("\n").should >= 3
8
+ s.should match(/StartApp Client Tools \(app\) Setup Wizard/)
9
+ end
10
+ end
11
+
12
+ def should_challenge_for(username, password)
13
+ input_line username.to_s if username
14
+ input_line password.to_s if password
15
+ next_stage.should_not be_nil
16
+
17
+ last_output do |s|
18
+ s.send(username ? :should : :should_not, match("Login to "))
19
+ s.send(password ? :should : :should_not, match(/Password: [\*]{8}$/))
20
+ end
21
+ end
22
+
23
+ def should_write_config
24
+ test_config_file(false)
25
+ end
26
+ def should_overwrite_config
27
+ test_config_file(true)
28
+ end
29
+ def test_config_file(present)
30
+ File.exists?(current_config_path).should be present
31
+
32
+ next_stage.should_not be_nil
33
+
34
+ last_output.should match("Saving configuration to #{current_config_path}")
35
+
36
+ File.readable?(current_config_path).should be true
37
+ RHC::Vendor::ParseConfig.new(current_config_path).tap do |cp|
38
+ cp["default_rhlogin"].should == username
39
+ cp["libra_server"].should == mock_uri
40
+ cp["use_authorization_tokens"].should == 'false'
41
+ end
42
+ end
43
+
44
+ def should_create_an_ssh_keypair
45
+ setup_mock_ssh
46
+ keys_should_not_exist
47
+
48
+ next_stage.should_not be_nil
49
+
50
+ keys_should_exist
51
+ last_output.should match('No SSH keys were found. We will generate a pair of keys')
52
+ end
53
+
54
+ def should_not_create_an_ssh_keypair
55
+ next_stage.should_not be_nil
56
+
57
+ last_output.should == ''
58
+ end
59
+
60
+ def should_upload_default_key
61
+ input_line 'yes'
62
+
63
+ next_stage.should_not be_nil
64
+
65
+ last_output do |s|
66
+ s.should match('Since you do not have any keys associated')
67
+ #s.should match(/Fingerprint\: (?:[a-f0-9]{2}\:){15}/)
68
+ s.should match("Uploading key 'default' ... ")
69
+ end
70
+ end
71
+
72
+ def should_skip_uploading_key
73
+ input_line 'no'
74
+
75
+ next_stage.should_not be_nil
76
+
77
+ last_output.should match('You can upload your public SSH key at a later time using ')
78
+ end
79
+
80
+ def should_find_matching_server_key
81
+ next_stage.should_not be_nil
82
+
83
+ last_output.should == ""
84
+ end
85
+
86
+ def should_find_git
87
+ setup_mock_has_git(true)
88
+
89
+ next_stage.should_not be_nil
90
+
91
+ last_output.should match(/Checking for git .*found/)
92
+ end
93
+
94
+ def should_display_windows_info
95
+ next_stage.should_not be_nil
96
+
97
+ last_output do |s|
98
+ s.should match('Git for Windows')
99
+ s.should match('In order to fully interact with StartApp you will need to install and configure a git client')
100
+ end
101
+ end
102
+
103
+ def should_not_find_git
104
+ setup_mock_has_git(false)
105
+
106
+ next_stage.should_not be_nil
107
+
108
+ last_output do |s|
109
+ s.should match(/Checking for git .*needs to be installed/)
110
+ s.should match("Automated installation of client tools is not supported for your platform")
111
+ end
112
+ end
113
+
114
+ def should_not_find_problems
115
+ FakeFS::File.expect_mode(RHC::Config.ssh_priv_key_file_path, '600')
116
+
117
+ next_stage.should_not be_nil
118
+ last_output do |s|
119
+ s.should match(/Checking common problems \.+.+?done/)
120
+ end
121
+ end
122
+
123
+ def should_check_remote_server
124
+ FakeFS::File.expect_mode(RHC::Config.ssh_priv_key_file_path, '600')
125
+
126
+ ssh = Object.new
127
+ ssh.should_receive(:close)
128
+ Net::SSH.should_receive(:start).once.and_return(ssh)
129
+ subject.should_receive(:ssh_key_uploaded?).and_return(true)
130
+
131
+ next_stage.should_not be_nil
132
+ last_output do |s|
133
+ s.should match(/Checking common problems \.+.+? done/)
134
+ end
135
+ end
136
+
137
+ def should_find_ssh_keys
138
+ next_stage.should_not be_nil
139
+
140
+ last_output do |s|
141
+ s.should_not match(/Remote server does not have the corresponding SSH key/)
142
+ end
143
+ end
144
+
145
+ def should_not_find_ssh_keys
146
+ next_stage.should_not be_nil
147
+
148
+ last_output do |s|
149
+ s.should match(/Remote server does not have the corresponding SSH key/)
150
+ end
151
+ end
152
+
153
+ def should_create_a_namespace
154
+ input_line "thisnamespaceistoobigandhastoomanycharacterstobevalid"
155
+ input_line "invalidnamespace"
156
+ input_line "testnamespace"
157
+
158
+ next_stage.should_not be_nil
159
+
160
+ last_output do |s|
161
+ s.should match(/Checking for a domain .*none/)
162
+ s.should match(/(?:Too long.*?){2}/m)
163
+ end
164
+ subject.send(:options).__hash__[:namespace].should == 'testnamespace'
165
+ end
166
+
167
+ def should_skip_creating_namespace
168
+ input_line ""
169
+
170
+ next_stage.should_not be_nil
171
+
172
+ last_output do |s|
173
+ s.should match(/Checking for a domain .*none/)
174
+ s.should match("You will not be able to create an application without completing this step.")
175
+ s.should match("You may create a domain later through 'app create-domain'")
176
+ end
177
+ subject.send(:options).__hash__[:namespace].should be_nil
178
+ end
179
+
180
+ def should_find_a_namespace(namespace)
181
+ next_stage.should_not be_nil
182
+
183
+ last_output.should match(/Checking for a domain .*#{namespace}/)
184
+ subject.send(:options).__hash__[:namespace].should be_nil
185
+ end
186
+
187
+ def should_list_types_of_apps_to_create
188
+ next_stage.should_not be_nil
189
+
190
+ last_output do |s|
191
+ s.should match('app create-app <app name> mock_standalone_cart-1')
192
+ s.should match('app create-app <app name> mock_standalone_cart-2')
193
+ end
194
+ end
195
+
196
+ def should_find_apps(*args)
197
+ next_stage.should_not be_nil
198
+
199
+ last_output do |s|
200
+ s.should match("found #{args.length}")
201
+ args.each do |(name, domain_name)|
202
+ s.should match("#{name} http://#{name}-#{domain_name}.rhcloud.com")
203
+ end
204
+ s.should match("You are using ")
205
+ s.should match("The following gear sizes are available to you")
206
+ end
207
+ end
208
+
209
+ def should_be_done
210
+ next_stage.should be_true
211
+
212
+ last_output.should match("Your client tools are now configured.")
213
+ end
214
+ end
215
+
216
+
217
+ module WizardHelper
218
+ def next_stage
219
+ @stages ||= subject.stages
220
+ @stage ||= -1
221
+ @current_stage = @stages[@stage+=1]
222
+ subject.send(@current_stage)
223
+ end
224
+
225
+ def current_config_path
226
+ subject.send(:config).config_path
227
+ end
228
+
229
+ def setup_mock_has_git(bool)
230
+ subject.stub(:"has_git?") { bool }
231
+ end
232
+
233
+ def current_ssh_dir
234
+ subject.send(:config).ssh_dir
235
+ end
236
+ def setup_mock_ssh(add_ssh_key=false)
237
+ FileUtils.mkdir_p current_ssh_dir
238
+ if add_ssh_key
239
+ setup_mock_ssh_keys
240
+ end
241
+ end
242
+
243
+ def keys_should_exist
244
+ File.exists?(File.join(current_ssh_dir, "id_rsa")).should be true
245
+ File.exists?(File.join(current_ssh_dir, "id_rsa.pub")).should be true
246
+ end
247
+ def keys_should_not_exist
248
+ File.exists?(File.join(current_ssh_dir, "id_rsa")).should be false
249
+ File.exists?(File.join(current_ssh_dir, "id_rsa.pub")).should be false
250
+ end
251
+
252
+ def priv_key
253
+ <<EOF
254
+ -----BEGIN RSA PRIVATE KEY-----
255
+ MIICWwIBAAKBgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+Xb
256
+ saS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77
257
+ fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3SfwIDAQAB
258
+ AoGAbMC+xZp5TsPEokOywWeH6cdWgZF5wpF7Dw7Nx34F2AFkfYWYAgVKaSxizHHv
259
+ i1VdFmOBGw7Gaq+BiXXyGwEvdpmgDoZDwvJrShZef5LwYnJ/NCqjZ8Xbb9z4VxCL
260
+ pkqMFFpEeNQcIDLZRF8Z1prRQnOL+Z498P6d3G/UWkR5NXkCQQDsGlpJzJwAPpwr
261
+ YZ98LgKT0n2WHeCrMQ9ZyJQl3Dz40qasQmIotB+mdIh87EFex7vvyiuzRC5rfcoX
262
+ CBHEkQpVAkEA2UFNBKgI1v5+16K0/CXPakQ25AlGODDv2VXlHwRPOayUG/Tn2joj
263
+ fj0T4/pu9AGhz0oVXFlz7iO8PEwFU+plgwJAKD2tmdp31ErXj0VKS34EDnHX2dgp
264
+ zMPF3AWlynYpJjexFLcTx+A7bMF76d7SnXbpf0sz+4/pYYTFBvvnG1ulKQJACJsR
265
+ lfGiCAIkvB3x1VsaEDeLhRTo9yjZF17TqJrfGIXBiCn3VSmgZku9EfbFllzKMA/b
266
+ MMFKWlCIEEtimqRaSQJAPVA1E7AiEvfUv0kRT73tDf4p/BRJ7p2YwjxrGpDBQhG1
267
+ YI+4NOhWtAG3Uips++8RhvmLjv8y+TNKU31J1EJmYA==
268
+ -----END RSA PRIVATE KEY-----
269
+ EOF
270
+ end
271
+
272
+ def pub_key
273
+ <<EOF
274
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIXpBBs7g93z/5JqW5IJNJR8bG6DWhpL2vR2ROEfzGqDHLZ+XbsaS/Ogc3nZNSav3juHWdiBFIc0unPpLdwmXtcL3tjN52CJqPgU/W0q061fL/tk77fFqW2upluo0ZRZQdPc3vTI3tWWZcpyE2LPHHUOI3KN+lRqxgw0Y6z/3Sfw== OpenShift-Key
275
+ EOF
276
+ end
277
+
278
+ def rsa_key_content_public
279
+ 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDJ54a/MlApilkfv7VCQS3lyUL5tHkJbuKNHOk6BtREsdrATZOpB3En3bRlgDMeGR0tAuRanvBai8TQG2kZluwdqAuTER0hiuZrAimrUHWbkQGZlwGWHBzNw/98gliZJYkZchAJjyzdQULbzq9xhcXzfYhUbZH1SGq6sThmR63tiYZHlbqQ+a56vpyFQsVEzvq5uqkvcJpSX74gDo0xqAAxSdNYZTBpLgFMB9Xzk/1UNlZ9C1SNDxEwFQZgzNriVyrGsJWaXfZdJRBa0PwScPEpJ4VlDFEgdtynjE1LabUAdMBoBXlr8QZgNHCuc3hUq/IVm3NShx+J3hVO3mP8HcLJ'
280
+ end
281
+ def rsa_key_fingerprint_public
282
+ '18:2a:99:6c:9b:65:6f:a5:13:57:c9:41:c7:b4:24:36'
283
+ end
284
+
285
+ class Sshkey < OpenStruct
286
+ def type
287
+ @table[:type]
288
+ end
289
+ def type=(type)
290
+ @table[:type] = type
291
+ end
292
+ end
293
+
294
+ def mock_key_objects
295
+ [
296
+ Sshkey.new(:name => 'default', :type => 'ssh-rsa', :fingerprint => "0f:97:4b:82:87:bb:c6:dc:40:a3:c1:bc:bb:55:1e:fa"),
297
+ Sshkey.new(:name => 'cb490595', :type => 'ssh-rsa', :fingerprint => "cb:49:05:95:b4:42:1c:95:74:f7:2d:41:0d:f0:37:3b"),
298
+ Sshkey.new(:name => '96d90241', :type => 'ssh-rsa', :fingerprint => "96:d9:02:41:e1:cb:0d:ce:e5:3b:fc:da:13:65:3e:32"),
299
+ Sshkey.new(:name => '73ce2cc1', :type => 'ssh-rsa', :fingerprint => "73:ce:2c:c1:01:ea:79:cc:f6:be:86:45:67:96:7f:e3")
300
+ ]
301
+ end
302
+
303
+ def setup_mock_ssh_keys(dir=current_ssh_dir)
304
+ private_key_file = File.join(dir, "id_rsa")
305
+ public_key_file = File.join(dir, "id_rsa.pub")
306
+ File.open(private_key_file, 'w') { |f| f.write priv_key }
307
+
308
+ File.open(public_key_file, 'w') { |f| f.write pub_key }
309
+ end
310
+
311
+ def setup_different_config
312
+ path = File.join(File.join(home_dir, '.startapp'), 'express.conf')
313
+ FileUtils.mkdir_p File.dirname(path)
314
+ File.open(path, "w") do |file|
315
+ file.puts <<EOF
316
+ # Default user login
317
+ default_rhlogin='a_different_user'
318
+
319
+ # Server API
320
+ libra_server = 'a_different_server.com'
321
+ EOF
322
+ end
323
+ path
324
+ end
325
+ end
326
+
327
+ RSpec.configure do |config|
328
+ config.include(WizardHelper)
329
+ config.include(WizardStepsHelper)
330
+ end