ubalo 0.0.10 → 0.0.11

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 (3) hide show
  1. data/bin/ubalo +57 -34
  2. data/lib/ubalo.rb +15 -6
  3. metadata +8 -8
data/bin/ubalo CHANGED
@@ -55,9 +55,6 @@ program_desc 'Command-line access to ubalo.com.'
55
55
  desc "Change the connect url"
56
56
  flag 'connect-url'
57
57
 
58
- desc "Enable debug mode"
59
- switch :debug
60
-
61
58
  desc 'Display authentication information'
62
59
  command :whoami do |c|
63
60
  c.action do |global_options,options,args|
@@ -66,22 +63,22 @@ command :whoami do |c|
66
63
  end
67
64
 
68
65
  desc 'Display a list of available pods'
69
- command :list do |c|
66
+ command :pods do |c|
70
67
  c.action do |global_options,options,args|
71
68
  response = ubalo.pods
72
69
 
73
70
  puts "your pods:"
74
- your_pods = response['your_pods']
71
+ your_pods = response.fetch('your_pods')
75
72
  if your_pods.empty?
76
73
  puts " (none)"
77
74
  else
78
- response['your_pods'].each do |pod|
75
+ your_pods.each do |pod|
79
76
  puts Ubalo.format_pod(pod, false)
80
77
  end
81
78
  end
82
79
 
83
80
  puts "other pods:"
84
- other_pods = response['other_pods']
81
+ other_pods = response.fetch('other_pods')
85
82
  if other_pods.empty?
86
83
  puts " (none)"
87
84
  else
@@ -112,7 +109,7 @@ def process_download response, destination_path=nil
112
109
  files = response.fetch('files')
113
110
  destination_path ||= name
114
111
 
115
- if Dir.exist?(destination_path)
112
+ if File.exists?(destination_path)
116
113
  raise "directory #{destination_path.inspect} already exists"
117
114
  end
118
115
 
@@ -168,13 +165,13 @@ command :create do |c|
168
165
  end
169
166
  destination_path = pod_name
170
167
 
171
- if Dir.exist?(pod_name)
168
+ if File.exists?(pod_name)
172
169
  raise "directory #{destination_path} already exists, giving up."
173
170
  end
174
171
 
175
172
  templates = ubalo.available_templates
176
- if options.type
177
- pod_type = options.type
173
+ if options['type']
174
+ pod_type = options['type']
178
175
  unless templates.include? pod_type
179
176
  raise "Invalid pod type"
180
177
  end
@@ -186,7 +183,7 @@ command :create do |c|
186
183
  end
187
184
 
188
185
  $stderr.print "Creating a new #{pod_type} pod called #{pod_name}..."
189
- response = ubalo.create_pod(pod_name, templates[pod_type])
186
+ response = ubalo.create_pod(pod_name, templates.fetch(pod_type))
190
187
 
191
188
  fullname, destination_path = process_download(response)
192
189
 
@@ -203,7 +200,7 @@ command :run do |c|
203
200
 
204
201
  $stderr.print "Running #{pod_name}..."
205
202
  response = ubalo.submit_task(pod_name, args.join(" "))
206
- task_label = response['label']
203
+ task_label = response.fetch('label')
207
204
 
208
205
  result = ubalo.wait_task(task_label)
209
206
  ubalo.show_result(result)
@@ -268,7 +265,7 @@ command :stop do |c|
268
265
  task_label = args.first
269
266
  $stderr.print "Stopping task #{task_label}..."
270
267
  result = ubalo.stop_task(task_label)
271
- $stderr.puts " task now #{result['state']}."
268
+ $stderr.puts " task now #{result.fetch('state')}."
272
269
  end
273
270
  end
274
271
 
@@ -279,7 +276,7 @@ command :add_key do |c|
279
276
  public_key_file = args.shift
280
277
  public_key_file ||= File.expand_path('~/.ssh/id_rsa.pub')
281
278
 
282
- puts ubalo.upload_key(File.read(public_key_file))["message"]
279
+ puts ubalo.upload_key(File.read(public_key_file)).fetch('message')
283
280
  end
284
281
  end
285
282
 
@@ -293,7 +290,7 @@ end
293
290
  desc 'Push code to Ubalo'
294
291
  command :push do |c|
295
292
  c.action do |global_options,options,args|
296
- filenames = local_config['filenames']
293
+ filenames = local_config.fetch('filenames')
297
294
  contents = {}
298
295
  filenames.each do |filename|
299
296
  contents[filename] = File.read(filename)
@@ -303,8 +300,8 @@ command :push do |c|
303
300
  fail unless filenames.length == 1
304
301
 
305
302
  print "Uploading changes to #{filenames.first}... "
306
- result = ubalo.push(local_config['pod_url'], contents)
307
- puts result['message']
303
+ result = ubalo.push(local_config.fetch('pod_url'), contents)
304
+ puts result.fetch('message')
308
305
  end
309
306
  end
310
307
 
@@ -312,27 +309,26 @@ desc 'Pull code from Ubalo'
312
309
  command :pull do |c|
313
310
  c.action do |global_options,options,args|
314
311
  print "Pulling changes from Ubalo..."
315
- contents = ubalo.pull(local_config['pod_url'])
312
+ contents = ubalo.pull(local_config.fetch('pod_url'))
316
313
  puts " received."
317
314
 
318
- filenames = local_config['filenames']
315
+ filenames = local_config.fetch('filenames')
319
316
 
320
317
  filenames.each do |filename|
321
-
322
318
  if File.exists?(filename)
323
319
  existing_contents = File.read(filename)
324
320
  else
325
321
  existing_contents = nil
326
322
  end
327
323
 
328
- if contents[filename] == existing_contents
324
+ if contents.fetch(filename) == existing_contents
329
325
  puts "Checking #{filename}... no changes."
330
326
  else
331
327
  hl.choose do |menu|
332
328
  menu.prompt = "Changes made to #{filename}. Overwrite your copy? "
333
329
  menu.choice :yes do
334
330
  open(filename, 'w') do |f|
335
- f.puts contents[filename]
331
+ f.puts contents.fetch(filename)
336
332
  end
337
333
  puts "Changes saved to #{filename}."
338
334
  end
@@ -353,7 +349,8 @@ command :add_key do |c|
353
349
  public_key_file = args.shift
354
350
  public_key_file ||= File.expand_path('~/.ssh/id_rsa.pub')
355
351
 
356
- puts ubalo.upload_key(File.read(public_key_file))["message"]
352
+ response = ubalo.upload_key(File.read(public_key_file))
353
+ puts response.fetch('message')
357
354
  end
358
355
  end
359
356
 
@@ -373,6 +370,26 @@ command :edit do |c|
373
370
  end
374
371
  end
375
372
 
373
+ desc 'Copy files to or from a pod environ'
374
+ arg_name '<pod name>'
375
+ command :cp do |c|
376
+ c.desc 'copy recursively'
377
+ c.switch :r
378
+
379
+ c.action do |global_options,options,args|
380
+ opts = ""
381
+ opts << " -r" if options.r
382
+
383
+ environ = nil
384
+ scp_args = args.join(" ").gsub(/[\w-]+(?=:)/) do |pod_name|
385
+ ssh_path, environ = ubalo.ssh_path(pod_name)
386
+ "#{ssh_path}"
387
+ end
388
+
389
+ ubalo.scp(environ, opts, scp_args)
390
+ end
391
+ end
392
+
376
393
  desc 'Enter username and password for access'
377
394
  command :login do |c|
378
395
  c.action do |global_options,options,args|
@@ -381,8 +398,8 @@ command :login do |c|
381
398
  password = hl.ask(" password: "){|q| q.echo = false}
382
399
 
383
400
  response = ubalo.get_api_token(login, password)
384
- ubalo.token = response['api_token']
385
- username = response['username']
401
+ ubalo.token = response.fetch('api_token')
402
+ username = response.fetch('username')
386
403
 
387
404
  Ubalo.write_config(ubalo.base_url => {'token' => ubalo.token})
388
405
  puts "Success! Ready to use as #{username}."
@@ -406,7 +423,7 @@ command :publish do |c|
406
423
  $stderr.print "Publishing #{pod_name}..."
407
424
  response = ubalo.publish(pod_name)
408
425
  $stderr.puts " done."
409
- $stderr.puts "Your pod is now available at #{response['pod_url']}."
426
+ $stderr.puts "Your pod is now available at #{response.fetch('pod_url')}."
410
427
  end
411
428
  end
412
429
 
@@ -435,16 +452,17 @@ pre do |global,command,options,args|
435
452
  end
436
453
 
437
454
  unless token or (command && command.name == :login)
438
- raise "No credentials found. Please run 'ubalo login'."
455
+ $stderr.puts "No credentials found. Please run 'ubalo login'."
456
+ raise UbaloExit, 1
439
457
  end
440
458
 
441
459
  local_config_filename = ".ubalo/config"
442
460
  if File.exists?(local_config_filename)
443
- @local_config = YAML.load_file(local_config_filename)
461
+ full_path = File.expand_path(local_config_filename)
462
+ @local_config = YAML.load_file(full_path)
444
463
  end
445
464
 
446
465
  @ubalo ||= Ubalo.login(token, connect_url)
447
- @debug = global.debug
448
466
 
449
467
  true
450
468
  end
@@ -454,16 +472,21 @@ on_error do |exception|
454
472
  case exception
455
473
  when RestClient::BadRequest
456
474
  $stderr.puts exception.inspect.sub('400 Bad Request', 'Error')
457
- false
475
+ false # no additional raise required.
458
476
  when RestClient::ResourceNotFound
459
477
  $stderr.puts exception.inspect.sub('404 Resource Not Found', 'Error')
460
- false
478
+ false # no additional raise required.
479
+ when RestClient::Unauthorized
480
+ $stderr.puts "Invalid credentials. Please use ubalo login to reset them."
481
+ true # fall back to GLI's handling
482
+ when GLI::BadCommandLine
483
+ true # fall back to GLI's handling
461
484
  when UbaloExit
462
485
  # Normal exit, preserving the correct exit code.
463
486
  exit exception.message
464
487
  else
465
- raise if @debug
466
- true
488
+ $stderr.puts "Error! Unfortunately something went wrong. Please contact us: errors@ubalo.com."
489
+ raise # and go on to raise
467
490
  end
468
491
  end
469
492
 
@@ -164,6 +164,15 @@ class Ubalo
164
164
  end
165
165
  end
166
166
 
167
+ def scp(environ, opts, args)
168
+ scp_command = "scp -o SendEnv=UBALO_ENVIRON #{opts} #{args}"
169
+ Process.spawn({'UBALO_ENVIRON' => environ}, scp_command)
170
+ pid, status = Process.wait2
171
+ unless status.success?
172
+ abort "Error running cp"
173
+ end
174
+ end
175
+
167
176
  def stop_task(label)
168
177
  post(:stop_task, {:label => label})
169
178
  end
@@ -200,12 +209,12 @@ class Ubalo
200
209
  get(:available_templates)['templates']
201
210
  end
202
211
 
203
- def create_pod name, type
204
- post(:create_pod, template: type, pod_name: name)
212
+ def create_pod name, pod_type
213
+ post(:create_pod, :template => pod_type, :pod_name => name)
205
214
  end
206
215
 
207
216
  def push pod_url, contents
208
- url_post("#{pod_url}/api/push", contents: contents)
217
+ url_post("#{pod_url}/api/push", :contents => contents)
209
218
  end
210
219
 
211
220
  def pull pod_url
@@ -213,7 +222,7 @@ class Ubalo
213
222
  end
214
223
 
215
224
  def check_task label
216
- check_task_json({label: label})
225
+ check_task_json({:label => label})
217
226
  end
218
227
 
219
228
  def check_task_json hash
@@ -221,11 +230,11 @@ class Ubalo
221
230
  end
222
231
 
223
232
  def publish pod_name
224
- post(:publish, pod_name: pod_name)
233
+ post(:publish, :pod_name => pod_name)
225
234
  end
226
235
 
227
236
  def unpublish pod_name
228
- post(:unpublish, pod_name: pod_name)
237
+ post(:unpublish, :pod_name => pod_name)
229
238
  end
230
239
 
231
240
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubalo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-06 00:00:00.000000000Z
12
+ date: 2011-12-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &2152383460 !ruby/object:Gem::Requirement
16
+ requirement: &2164902800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152383460
24
+ version_requirements: *2164902800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &2152382720 !ruby/object:Gem::Requirement
27
+ requirement: &2164902220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152382720
35
+ version_requirements: *2164902220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rest-client
38
- requirement: &2152381580 !ruby/object:Gem::Requirement
38
+ requirement: &2164901580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.6.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152381580
46
+ version_requirements: *2164901580
47
47
  description: CLI and API client for Ubalo
48
48
  email: dev@ubalo.com
49
49
  executables: