pi 0.1.24 → 0.1.25

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.
@@ -85,8 +85,10 @@ module PI::Cli::Command
85
85
  display targets_table
86
86
  end
87
87
 
88
- def password(newpassword=nil)
88
+ def password(oldpassword=nil)
89
89
  client.check_login_status
90
+ newpassword = @options[:password]
91
+ oldpassword = ask "Old Password", :echo => '*' unless oldpassword
90
92
  unless newpassword
91
93
  loop{
92
94
  newpassword = ask "New Password", :echo => '*'
@@ -100,7 +102,11 @@ module PI::Cli::Command
100
102
  end
101
103
  }
102
104
  end
103
- client.password(newpassword)
105
+ manifest = {
106
+ :newPassword => newpassword,
107
+ :oldPassword => oldpassword
108
+ }
109
+ client.password(manifest)
104
110
  display "ok".green
105
111
  end
106
112
 
data/lib/cli/config.rb CHANGED
@@ -7,7 +7,8 @@ require 'json/pure'
7
7
  module PI::Cli
8
8
  class Config
9
9
 
10
- DEFAULT_TARGET = 'api.staging.samsungcloud.org'
10
+ # DEFAULT_TARGET = 'api.staging.samsungcloud.org'
11
+ DEFAULT_TARGET = 'staging.samsungcloud.org'
11
12
  DEFAULT_SUGGEST = 'samsungcloud.org'
12
13
 
13
14
  TARGET_FILE = '~/.pi_target'
data/lib/cli/runner.rb CHANGED
@@ -36,6 +36,14 @@ class PI::Cli::Runner
36
36
  opts.on('--project PROJ') { |proj| @options[:project] = proj }
37
37
  opts.on('--target TARG') { |targ| @options[:target] = targ }
38
38
  opts.on('--instance N') { |inst| @options[:instance] = inst }
39
+ opts.on('--type TYPE') { |type| @options[:type] = type }
40
+ opts.on('--value VALUE') { |value| @options[:value] = value }
41
+ opts.on('--service SERVICE') { |service| @options[:service] = service }
42
+ opts.on('--dns DNS') { |dns| @options[:dns] = dns }
43
+ opts.on('--zoneid ID') { |id| @options[:zoneid] = id }
44
+ # opts.on('--continent CONT') { |cont| @options[:continent] = cont }
45
+ # opts.on('--country COUNTRY') { |country| @options[:country] = country }
46
+ # opts.on('--recordid ID') { |id| @options[:recordid] = id }
39
47
  # generic tracing and debugging
40
48
  opts.on('-t [TKEY]') { |tkey| @options[:trace] = tkey || true }
41
49
  opts.on('--trace [TKEY]') { |tkey| @options[:trace] = tkey || true }
@@ -121,7 +129,7 @@ class PI::Cli::Runner
121
129
  set_cmd(:user, :targets)
122
130
 
123
131
  when 'password'
124
- usage ('pi password [newpassword]')
132
+ usage ('pi password [oldpassword] [--password PASS]')
125
133
  set_cmd(:user, :password, @args.size == 1 ? 1 : 0)
126
134
 
127
135
  when 'github'
@@ -234,7 +242,7 @@ class PI::Cli::Runner
234
242
  set_cmd(:apps, :scale_app, @args.size == 1 ? 1 : 0)
235
243
 
236
244
  when 'update-app'
237
- usage('pi update-app [appid] or pi update-app <appname> <--target TARGET>')
245
+ usage('pi update-app [appid] [--ver VERSION] or pi update-app <appname> <--target TARGET> [--ver VERSION]')
238
246
  set_cmd(:apps, :update_app, @args.size == 1 ? 1 : 0)
239
247
 
240
248
  when 'status'
@@ -246,11 +254,11 @@ class PI::Cli::Runner
246
254
  set_cmd(:apps, :app_env, @args.size == 1 ? 1 : 0)
247
255
 
248
256
  when 'create-env'
249
- usage('pi app-env [appid] or pi app-env <appname> <--target TARGET>')
257
+ usage('pi app-env [appid][--name,--value] or pi app-env <appname> <--target TARGET> [--name,--value]')
250
258
  set_cmd(:apps, :create_env, @args.size == 1 ? 1 : 0)
251
259
 
252
260
  when 'delete-env'
253
- usage('pi delete-env [appid] or pi delete-env <appname> <--target TARGET>')
261
+ usage('pi delete-env [appid] [--name NAME] or pi delete-env <appname> <--target TARGET> [--name NAME]')
254
262
  set_cmd(:apps, :delete_env, @args.size == 1 ? 1 : 0)
255
263
 
256
264
  when 'app-log'
@@ -266,13 +274,45 @@ class PI::Cli::Runner
266
274
  set_cmd(:services, :app_service, @args.size == 1 ? 1 : 0)
267
275
 
268
276
  when 'bind-service'
269
- usage('pi bind-service [appid] or pi bind-service <appname> <--target TARGET>')
277
+ usage('pi bind-service [appid] [--service SERVICE] or pi bind-service <appname> <--target TARGET> [--service SERVICE]')
270
278
  set_cmd(:services, :bind_service, @args.size == 1 ? 1 : 0)
271
279
 
272
280
  when 'unbind-service'
273
- usage('pi unbind-service [appid] or pi unbind-service <appname> <--target TARGET>')
281
+ usage('pi unbind-service [appid] [--service SERVICE] or pi unbind-service <appname> <--target TARGET> [--service SERVICE]')
274
282
  set_cmd(:services, :unbind_service, @args.size == 1 ? 1 : 0)
275
283
 
284
+ when 'services'
285
+ usage('pi services')
286
+ set_cmd(:services, :services)
287
+
288
+ when 'service'
289
+ usage('pi service [serviceid]')
290
+ set_cmd(:services, :service, @args.size == 1 ? 1 : 0)
291
+
292
+ when 'import-service'
293
+ usage('pi import-service [url]')
294
+ set_cmd(:services, :import_service, @args.size == 1 ? 1 : 0)
295
+
296
+ when 'export-service'
297
+ usage('pi export-service [serviceid]')
298
+ set_cmd(:services, :export_service, @args.size == 1 ? 1 : 0)
299
+
300
+ when 'check-service'
301
+ usage('pi check-service [serviceid]')
302
+ set_cmd(:services, :check_service, @args.size == 1 ? 1 : 0)
303
+
304
+ when 'register-service'
305
+ usage('pi register-service [serviceid] [--target TARGET] [--type TYPE]')
306
+ set_cmd(:services, :register_service, @args.size == 1 ? 1 : 0)
307
+
308
+ when 'deregister-service'
309
+ usage('pi deregister-service [serviceid] [--target TARGET]')
310
+ set_cmd(:services, :deregister_service, @args.size == 1 ? 1 : 0)
311
+
312
+ when 'delete-service'
313
+ usage('pi delete-service [serviceid]')
314
+ set_cmd(:services, :delete_service, @args.size == 1 ? 1 : 0)
315
+
276
316
  ###############################################################################
277
317
  # Dns
278
318
  ###############################################################################
@@ -282,12 +322,32 @@ class PI::Cli::Runner
282
322
  set_cmd(:dns, :app_dns, @args.size == 1 ? 1 : 0)
283
323
 
284
324
  when 'map-dns'
285
- usage('pi map-dns [appid] or pi map-dns <appname> <--target TARGET>')
325
+ usage('pi map-dns [appid] [--dns DNS] or pi map-dns <appname> <--target TARGET> [--dns DNS]')
286
326
  set_cmd(:dns, :map_dns, @args.size == 1 ? 1 : 0)
287
327
 
288
328
  when 'unmap-dns'
289
- usage('pi unmap-dns [appid] or pi unmap-dns <appname> <--target TARGET>')
329
+ usage('pi unmap-dns [appid] [--dns DNS] or pi unmap-dns <appname> <--target TARGET> [--dns DNS]')
290
330
  set_cmd(:dns, :unmap_dns, @args.size == 1 ? 1 : 0)
331
+
332
+ when 'dns'
333
+ usage('pi dns')
334
+ set_cmd(:dns, :dns)
335
+
336
+ when 'create-dns'
337
+ usage('pi create-dns [dnsname] [--zoneid ID] [--project PROJ] [--desc DESC]')
338
+ set_cmd(:dns, :create_dns, @args.size == 1 ? 1 : 0)
339
+
340
+ when 'delete-dns'
341
+ usage('pi delete-dns [dnsid]')
342
+ set_cmd(:dns, :delete_dns, @args.size == 1 ? 1 : 0)
343
+
344
+ when 'register-dns'
345
+ usage('pi register-dns [dnsid]')
346
+ set_cmd(:dns, :register_dns, @args.size == 1 ? 1 : 0)
347
+
348
+ when 'deregister-dns'
349
+ usage('pi deregister-dns [dnsid]')
350
+ set_cmd(:dns, :deregister_dns, @args.size == 1 ? 1 : 0)
291
351
 
292
352
  ###############################################################################
293
353
 
@@ -328,7 +388,7 @@ class PI::Cli::Runner
328
388
 
329
389
  # local shopts=$-
330
390
  # set -o noglob
331
- Kernel.system('set -o noglob')
391
+ # Kernel.system('set -o noglob')
332
392
  # Kernel.exec('sudo set -o noglob')
333
393
  # `set -o noglob`
334
394
  parse_command!
data/lib/cli/usage.rb CHANGED
@@ -30,6 +30,7 @@ Currently available pi commands are:
30
30
  info List system information
31
31
  user Display user information
32
32
  targets List available targets infomation
33
+ password [oldpassword] [--password PASS] Change the password for the current user
33
34
  github [name] [--email,--password] Bind to the github account
34
35
  runtimes Display the supported runtimes of the system
35
36
  frameworks Display the supported frameworks of the system
@@ -59,34 +60,47 @@ Currently available pi commands are:
59
60
  restart-app <appname> <--target TARGET> Restart the application
60
61
  scale-app [appid] [--instance N] Scale the application instances up or down
61
62
  scale-app <appname> <--target TARGET> [--instance N] Scale the application instances up or down
62
- update-app [appid] Update the application
63
- update-app <appname> <--target TARGET> Update the application
63
+ update-app [appid] [--ver VERSION] Update the application
64
+ update-app <appname> <--target TARGET>[--ver VERSION] Update the application
64
65
  status [appid] Display resource usage for the application
65
66
  status <appname> <--target TARGET> Display resource usage for the application
66
67
  app-env [appid] Display the environments for the application
67
68
  app-env <appname> <--target TARGET> Display the environments for the application
68
- create-env [appid] Create the environment for the application
69
- create-env <appname> <--target TARGET> Create the environment for the application
70
- delete-env [appid] Delete the environment for the application
71
- delete-env <appname> <--target TARGET> Delete the environment for the application
69
+ create-env [appid][--name,--value] Create the environment for the application
70
+ create-env <appname><--target TARGET>[--name,--value] Create the environment for the application
71
+ delete-env [appid] [--name NAME] Delete the environment for the application
72
+ delete-env <appname> <--target TARGET> [--name NAME] Delete the environment for the application
72
73
  app-log [appid] List the logs for the application
73
74
  app-log <appname> <--target TARGET> List the logs for the application
74
75
 
75
76
  Service
76
77
  app-service [appid] Display the binded services for the application
77
78
  app-service <appname> <--target TARGET> Display the binded services for the application
78
- bind-service [appid] Bind the services for the application
79
- bind-service <appname> <--target TARGET> Bind the services for the application
80
- unbind-service [appid] Unbind the service for the application
81
- unbind-service <appname> <--target TARGET> Unbind the service for the application
82
-
79
+ bind-service [appid][--service SERVICE] Bind the services for the application
80
+ bind-service <appname> <--target TARGET> [--service] Bind the services for the application
81
+ unbind-service [appid][--service SERVICE] Unbind the services for the application
82
+ unbind-service <appname> <--target TARGET>[--service] Unbind the services for the application
83
+ services List dedicated services
84
+ service [serviceid] List the connection info for the service
85
+ export-service [serviceid] Export dedicated service url
86
+ import-service [url] Import dedicated service
87
+ check-service [serviceid] Check availability for the service
88
+ delete-service [serviceid] Delete the service
89
+ register-service [serviceid] [--target,--type] Register to target
90
+ deregister-service [serviceid] [--target TARGET] Deregister to target
91
+
83
92
  DNS
84
93
  app-dns [appid] Display the mapped urls for the application
85
94
  app-dns <appname> <--target TARGET> Display the mapped urls for the application
86
- map-dns [appid] Map the urls for the application
87
- map-dns <appname> <--target TARGET> Map the urls for the application
88
- unmap-dns [appid] Unmap the url for the application
89
- unmap-dns <appname> <--target TARGET> Unmap the url for the application
95
+ map-dns [appid] [--dns DNS] Map the urls for the application
96
+ map-dns <appname> <--target TARGET> [--dns DNS] Map the urls for the application
97
+ unmap-dns [appid] [--dns DNS] Unmap the urls for the application
98
+ unmap-dns <appname> <--target TARGET> [--dns DNS] Unmap the urls for the application
99
+ dns List the dns
100
+ create-dns [dnsname] [--zoneid,--project,--desc] Create a new dns
101
+ register-dns [dnsid] Register to target
102
+ deregister-dns [dnsid] Deregister to target
103
+ delete-dns [dnsid] Delete the dns
90
104
  USAGE
91
105
 
92
106
  end
data/lib/cli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module PI
2
2
  module Cli
3
- VERSION = '0.1.24'
3
+ VERSION = '0.1.25'
4
4
  end
5
5
  end
data/lib/pi/client.rb CHANGED
@@ -26,10 +26,18 @@ class PI::Client
26
26
  class HTTPException < RuntimeError; end
27
27
 
28
28
 
29
- def initialize(target_urls=PI::DEFAULT_TARGET, auth_token=nil)
30
- target_urls = "http://#{target_urls}" unless /^https?/ =~ target_urls
31
- target_urls = target_urls.gsub(/\/+$/, '')
32
- @target = target_urls
29
+ def initialize(target_url=PI::DEFAULT_TARGET, auth_token=nil)
30
+ if target_url =~ /(https?:\/\/)?staging.samsungcloud.org/
31
+ if /^https?/ =~ target_url
32
+ target_url = target_url.split("//", 2)
33
+ target_url = target_url[1]
34
+ end
35
+ target_url = "http://api.#{target_url}"
36
+ else
37
+ target_url = "http://#{target_url}" unless /^https?/ =~ target_url
38
+ end
39
+ target_url = target_url.gsub(/\/+$/, '')
40
+ @target = target_url
33
41
  @auth_token = auth_token
34
42
  end
35
43
 
@@ -80,13 +88,12 @@ class PI::Client
80
88
  json_get("#{PI::USER_PATH}/targets")
81
89
  end
82
90
 
83
- def password(newpassword)
84
- # status, body, headers = json_post("#{PI::USER_PATH}/password/#{newpassword}",{:newpass => newpassword})
85
- json_get("#{PI::USER_PATH}/password/#{newpassword}")
91
+ def password(manifest={})
92
+ status, body, headers = json_post("#{PI::USER_PATH}/password", manifest)
86
93
  end
87
94
 
88
95
  def github(manifest={})
89
- json_post("#{PI::USER_PATH}/bind",manifest)
96
+ json_post("#{PI::USER_PATH}/github/bind",manifest)
90
97
  end
91
98
 
92
99
  def runtimes
@@ -254,6 +261,46 @@ class PI::Client
254
261
  http_delete("#{PI::APP_PATH}/#{appid}/service/unbind/#{servicename}",'application/json')
255
262
  end
256
263
 
264
+ def services
265
+ json_get("#{PI::SERVICE_PATH}/search")
266
+ end
267
+
268
+ def service(serviceid)
269
+ json_get("#{PI::SERVICE_PATH}/#{serviceid}")
270
+ end
271
+
272
+ def import_service(manifest={})
273
+ http_post("#{PI::SERVICE_PATH}/import",manifest)
274
+ end
275
+
276
+ def export_service(serviceid)
277
+ http_get("#{PI::SERVICE_PATH}/exporturl/#{serviceid}")
278
+ end
279
+
280
+ def check_service(serviceid)
281
+ http_get("#{PI::SERVICE_PATH}/check/#{serviceid}")
282
+ end
283
+
284
+ def delete_service(serviceid)
285
+ http_delete("#{PI::SERVICE_PATH}/#{serviceid}", 'application/json')
286
+ end
287
+
288
+ def usable_target(serviceid)
289
+ json_get("#{PI::SERVICE_PATH}/target/usable/#{serviceid}")
290
+ end
291
+
292
+ def service_target(serviceid)
293
+ json_get("#{PI::SERVICE_PATH}/servicetarget/#{serviceid}")
294
+ end
295
+
296
+ def register_service(serviceid, targetname, servicetype, manifest={})
297
+ json_post("#{PI::SERVICE_PATH}/register/#{targetname}/#{serviceid}?serviceType=#{servicetype}",manifest)
298
+ end
299
+
300
+ def deregister_service(servicetargetid)
301
+ http_delete("#{PI::SERVICE_PATH}/unregister/#{servicetargetid}",'application/json')
302
+ end
303
+
257
304
  #####################################################
258
305
  # dns
259
306
  #####################################################
@@ -274,6 +321,46 @@ class PI::Client
274
321
  http_delete("#{PI::APP_PATH}/#{appid}/url/unmap/#{url}", 'application/json')
275
322
  end
276
323
 
324
+ def dns
325
+ json_get("#{PI::DNS_PATH}/search")
326
+ end
327
+
328
+ def create_dns(manifest={})
329
+ json_post("#{PI::DNS_PATH}/", manifest)
330
+ end
331
+
332
+ def dns_zone_list
333
+ json_get("#{PI::DNS_PATH}/dnszone/list")
334
+ end
335
+
336
+ def verify_dns(dnsname, zoneid)
337
+ http_get("#{PI::DNS_PATH}/verify?dnsName=#{dnsname}&zoneId=#{zoneid}")
338
+ end
339
+
340
+ def delete_dns(dnsid)
341
+ http_delete("#{PI::DNS_PATH}/#{dnsid}",'application/json')
342
+ end
343
+
344
+ def usable_target(dnsid)
345
+ json_get("#{PI::DNS_PATH}/dnstarget/#{dnsid}")
346
+ end
347
+
348
+ def dns_continents
349
+ json_get("#{PI::DNS_PATH}/continents")
350
+ end
351
+
352
+ def dns_country(continents)
353
+ json_get("#{PI::DNS_PATH}/country/#{continents}")
354
+ end
355
+
356
+ def register_dns(dnsid, target, manifest={})
357
+ json_post("#{PI::DNS_PATH}/view/#{dnsid}/#{target}", manifest)
358
+ end
359
+
360
+ def deregister_dns(recordid)
361
+ http_delete("#{PI::DNS_PATH}/record/#{recordid}",'application/json')
362
+ end
363
+
277
364
  ######################################################
278
365
 
279
366
  private
data/lib/pi/const.rb CHANGED
@@ -3,7 +3,7 @@ module PI
3
3
  VERSION = 'Bougatsa 0.6.0'
4
4
 
5
5
  # Targets
6
- DEFAULT_TARGET = 'https://api.staging.samsungcloud.org'
6
+ DEFAULT_TARGET = 'https://staging.samsungcloud.org'
7
7
  DEFAULT_LOCAL_TARGET = 'http://www.samsungcloud.org'
8
8
 
9
9
  # General Paths
@@ -15,5 +15,7 @@ module PI
15
15
  APP_PATH = '/app'
16
16
  APPS_PATH = '/apps'
17
17
  ADMIN_PATH = '/admin'
18
+ SERVICE_PATH = '/service'
19
+ DNS_PATH = '/dns'
18
20
 
19
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 24
10
- version: 0.1.24
9
+ - 25
10
+ version: 0.1.25
11
11
  platform: ruby
12
12
  authors:
13
13
  - Samsung
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-04 00:00:00 Z
18
+ date: 2012-08-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json_pure