pearl 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dca946b28b42b66b4d14e151a63e531eed171186
4
- data.tar.gz: df773866825fe4c6cc331f65debd8365207b86d0
3
+ metadata.gz: af0e92ef3c79f8beabfb06a3cee20ee63301f5d1
4
+ data.tar.gz: 57e00452487c5877a3e4176cdbfd7388205b080d
5
5
  SHA512:
6
- metadata.gz: cd0f02927c45e95d4fafd8703113e5743d3fe681c559361fe3d3bb2d8c6ed24353caff0626fa025414bd9990af8c3f6685a4c6099a2db59eb73f742bfa03cab5
7
- data.tar.gz: 964a75eaef276a34de3f1913722abb3a36a7d563589c84db3e32033d1b8ea8ff2b1d4e08c82a7d8d43cf70e543dec43933604928af7c6c6cb75338b690080777
6
+ metadata.gz: f532cd6d58851a9f6d813d0a05db4ec4d0559feb4142d5bbd0c4e27f843d28cb37367e2af9a988796a6d0e67a48ef6241fc44cc375bb4d5657c3d9117f47d821
7
+ data.tar.gz: f2682056b712791515923daf7df86fa9c54909efdbc02d4da0cfbc6c6481ee5ee131fe5b6e5ecccba1c1138ed11cc931a981e2ab9d1b81b74ad301204bbd7e55
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/README.md CHANGED
@@ -27,11 +27,11 @@ To view a droplet
27
27
 
28
28
  To create a droplet
29
29
 
30
- $ pearl droplet add <name> --size <size id> --image <image id> --region <region id>
30
+ $ pearl droplet add <name> --size <size id> --image <image id> --region <region id> --ssh_key_ids <ssh key ids>
31
31
 
32
32
  or
33
33
 
34
- $ pearl droplet add <name> -s <size id> -i <image id> -r <region id>
34
+ $ pearl droplet add <name> -s <size id> -i <image id> -r <region id> -k <ssh key ids>
35
35
 
36
36
  Reboot a droplet
37
37
 
@@ -51,11 +51,11 @@ Power Off droplet
51
51
 
52
52
  Power On droplet
53
53
 
54
- $ pearl droplet power_on -d <droplet id>
54
+ $ pearl droplet power on -d <droplet id>
55
55
 
56
56
  Reset root password
57
57
 
58
- $ pearl droplet password_reset -d <droplet id>
58
+ $ pearl droplet password reset -d <droplet id>
59
59
 
60
60
  Resize droplet
61
61
 
@@ -119,10 +119,23 @@ To destroy an image
119
119
 
120
120
  $ pearl image destroy -i <image id>
121
121
 
122
+ ### SSH Keys
123
+
124
+ Display all ssh keys
125
+
126
+ $ pearl ssh_keys
127
+
128
+ To view a ssh key
129
+
130
+ $ pearl ssh_key -k <ssh_key_id>
131
+
132
+ To delete a ssh key
133
+
134
+ $ paerl ssh_key destroy -k <ssh_key_id>
135
+
122
136
  ## TODO
123
137
 
124
138
  * ~~Format output instead of just printing the json response.~~
125
- * Add SSH resource.
126
139
 
127
140
  ## Contributing
128
141
 
data/lib/pearl/cli.rb CHANGED
@@ -10,6 +10,8 @@ module Pearl
10
10
  image = nil
11
11
  region = nil
12
12
  size = nil
13
+ ssh_key_ids = nil
14
+ ssh_key_pub = nil
13
15
 
14
16
  opts = OptionParser.new do |opts|
15
17
  opts.banner = "Usage: pearl [resource] [options]"
@@ -31,10 +33,14 @@ module Pearl
31
33
  region = r
32
34
  end
33
35
 
34
- opts.on('-s', '--size [SIZE ID]', 'Set the size forthe droplet') do |s|
36
+ opts.on('-s', '--size [SIZE ID]', 'Set the size for the droplet') do |s|
35
37
  size = s
36
38
  end
37
39
 
40
+ opts.on('-k', '--ssh_key_ids [KEY ID]', 'SSH Keys to add to the droplet') do |k|
41
+ ssh_key_ids = k
42
+ end
43
+
38
44
  opts.on('-v', '--version', 'Display version') do
39
45
  puts Pearl::VERSION
40
46
  exit
@@ -77,7 +83,13 @@ module Pearl
77
83
  name = command.split(' ', 3)[2]
78
84
  raise 'Error: Invalid droplet name.' if name.nil? || name.length <= 0
79
85
 
80
- options = { name: name, image_id: image_id, region_id: region_id, size_id: size_id }
86
+ options = {
87
+ name: name,
88
+ image_id: image_id,
89
+ region_id: region_id,
90
+ size_id: size_id,
91
+ ssh_key_ids: ssh_key_ids
92
+ }
81
93
 
82
94
  Pearl.create_droplet(options)
83
95
  exit
@@ -195,9 +207,29 @@ module Pearl
195
207
  when /\Aregions\z/i
196
208
  Pearl.regions
197
209
  exit
210
+
211
+ # SSH Keys
212
+ when /\Assh_keys\z/i
213
+ Pearl.ssh_keys
214
+ exit
215
+ when /\Assh_key\z/i
216
+ ssh_key_ids = ssh_key_ids.to_i
217
+ raise 'Error: Invalid SSH Key ID.' if ssh_key_ids == 0 || !ssh_key_ids.is_a?(Fixnum)
218
+ Pearl.ssh_key(ssh_key_ids)
219
+ exit
220
+
221
+ when /\Assh_key (destroy|delete)\z/i
222
+ ssh_key_ids = ssh_key_ids.to_i
223
+ raise 'Error: Invalid SSH Key ID.' if ssh_key_ids == 0 || !ssh_key_ids.is_a?(Fixnum)
224
+ Pearl.delete_ssh_key(ssh_key_ids)
225
+ exit
226
+
227
+ # Sizes
198
228
  when /\Asizes\z/i
199
229
  Pearl.sizes
200
230
  exit
231
+
232
+ # Any other command
201
233
  else
202
234
  puts "Error: '#{command}' is an invalid command."
203
235
  exit
@@ -212,4 +244,4 @@ module Pearl
212
244
  end
213
245
  end
214
246
  end
215
- end
247
+ end
@@ -16,7 +16,8 @@ module Pearl
16
16
  params = { name: options[:name],
17
17
  size_id: options[:size_id],
18
18
  image_id: options[:image_id],
19
- region_id: options[:region_id]
19
+ region_id: options[:region_id],
20
+ ssh_key_ids: options[:ssh_key_ids]
20
21
  }
21
22
  response = request("droplets/new", params).body
22
23
  pretty_table("Droplet", response)
@@ -93,4 +94,4 @@ module Pearl
93
94
  end
94
95
  end
95
96
  end
96
- end
97
+ end
@@ -20,8 +20,8 @@ module Pearl
20
20
  end
21
21
 
22
22
  def destroy_image(id)
23
- response = request("images/#{id}").body
24
- pretty_table("Image", response)
23
+ response = request("images/#{id}/destroy").body
24
+ pretty_event("Destroying image #{id}", response)
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,22 @@
1
+ module Pearl
2
+ class Client
3
+
4
+ module SshKeys
5
+
6
+ def ssh_keys
7
+ response = request("ssh_keys").body
8
+ pretty_table("SSH Keys", response)
9
+ end
10
+
11
+ def ssh_key(id)
12
+ response = request("ssh_keys/#{id}").body
13
+ pretty_table('SSH Key', response)
14
+ end
15
+
16
+ def delete_ssh_key(id)
17
+ response = request("ssh_keys/#{id}/destroy").body
18
+ pretty_basic("Deleting ssh key #{id}", response)
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/pearl/client.rb CHANGED
@@ -11,6 +11,7 @@ module Pearl
11
11
  include Images
12
12
  include Regions
13
13
  include Sizes
14
+ include SshKeys
14
15
 
15
16
  include PrettyTable
16
17
 
@@ -37,4 +38,4 @@ module Pearl
37
38
  @client_id != nil && @api_key != nil
38
39
  end
39
40
  end
40
- end
41
+ end
@@ -54,5 +54,16 @@ module Pearl
54
54
  table = Terminal::Table.new title: heading, headings: ['Status', 'Event ID'], rows: rows
55
55
  puts table
56
56
  end
57
+
58
+ def pretty_basic(heading = '', data)
59
+ # Convert JSON response into a hash for easier parsing
60
+ tmp = MultiJson.load(data, symbolize_keys: true)
61
+
62
+ rows = []
63
+ rows << [tmp[:status]]
64
+
65
+ table = Terminal::Table.new title: heading, rows: rows
66
+ puts table
67
+ end
57
68
  end
58
69
  end
data/lib/pearl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pearl
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/pearl.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_dependency "multi_json", "~> 1.6.1"
26
- spec.add_dependency "terminal-table"
26
+ spec.add_dependency "terminal-table", "~> 1.4.5"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pearl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manish Valechha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-07 00:00:00.000000000 Z
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: terminal-table
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.4.5
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.4.5
69
69
  description: Command line interface for DigitalOcean's API
70
70
  email:
71
71
  - manishval@hotmail.com
@@ -87,6 +87,7 @@ files:
87
87
  - lib/pearl/client/images.rb
88
88
  - lib/pearl/client/regions.rb
89
89
  - lib/pearl/client/sizes.rb
90
+ - lib/pearl/client/sshkeys.rb
90
91
  - lib/pearl/error.rb
91
92
  - lib/pearl/http.rb
92
93
  - lib/pearl/pretty_table.rb
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  requirements: []
122
123
  rubyforge_project:
123
- rubygems_version: 2.0.0
124
+ rubygems_version: 2.0.3
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Command line interface for DigitalOcean's API