lita-digitalocean 0.0.1 → 1.0.0

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: 5444464dba3faf90e5b413c215bda59c1a797fdf
4
- data.tar.gz: 9397be0387a7e3be5f012ee09dc3d0479e573003
3
+ metadata.gz: ceb867fa1a82a608494d9af9340cc2a9f2ccff2f
4
+ data.tar.gz: 79c78fd54b3ba4fb044e71c2d3687909c594af7f
5
5
  SHA512:
6
- metadata.gz: 3d8e15cb823eefde8069e2a908eefbeb365be41b3df69eedbb39d2af2ace2f79dac6242f2f2b62b7d1ea97fff09ee1af98763384f3048daca2d1dfd8e2b0e7e3
7
- data.tar.gz: 769db7c17a2f6e3f05b4e64d0cb515b7a6093a505f695739a97b140553a040ffbfcfa603b5de79165601ad231fd87ba13948903e136a755a9ae777dbb028dcd5
6
+ metadata.gz: 28c176473b7afe92034be4a40e66855264a7d6f2281b8760a1e8dd99eca7566c1997aa3daf58caf3b97a821ff74a802c8843d80166825c8e890fe6c47a9867fb
7
+ data.tar.gz: 6d9cda0c6800bee0cec9c2a015dbfd71eb7ec9b8c6d9d7c1573d2550f81a51c9bc9a0c99ef12c6fd542c082650c30fad628a41a0090436070e126a0ed48eafd0
data/README.md CHANGED
@@ -36,19 +36,187 @@ To use any of the DigitalOcean commands, the user sending the message must be in
36
36
 
37
37
  ### Domain commands
38
38
 
39
- Not yet implemented. Coming soon!
39
+ To create a new DNS record set:
40
+
41
+ ```
42
+ Lita: do domains create NAME IP
43
+ ```
44
+
45
+ To delete a DNS record set:
46
+
47
+ ```
48
+ Lita: do domains delete DOMAIN_NAME_OR_ID
49
+ ```
50
+
51
+ To list all DNS record sets:
52
+
53
+ ```
54
+ Lita: do domains list
55
+ ```
56
+
57
+ To show the details of a DNS record set:
58
+
59
+ ```
60
+ Lita: do domains show DOMAIN_NAME_OR_ID
61
+ ```
62
+
63
+ ### Domain record commands
64
+
65
+ To create a new DNS record:
66
+
67
+ ```
68
+ Lita: do domain records create DOMAIN_NAME_OR_ID TYPE DATA [--name NAME] [--priority PRIORITY] [--port PORT] [--weight WEIGHT]
69
+ ```
70
+
71
+ To delete a DNS record:
72
+
73
+ ```
74
+ Lita: do domain records delete DOMAIN_NAME_OR_ID DOMAIN_RECORD_ID
75
+ ```
76
+
77
+ To edit a DNS record:
78
+
79
+ ```
80
+ Lita: do domain records edit DOMAIN_NAME_OR_ID DOMAIN_RECORD_ID TYPE DATA [--name NAME] [--priority PRIORITY] [--port PORT] [--weight WEIGHT]
81
+ ```
82
+
83
+ To list all DNS records for a DNS record set:
84
+
85
+ ```
86
+ Lita: do domain records list DOMAIN_NAME_OR_ID
87
+ ```
88
+
89
+ To show the details of a DNS record:
90
+
91
+ ```
92
+ Lita: do domain records show DOMAIN_NAME_OR_ID DOMAIN_RECORD_ID
93
+ ```
40
94
 
41
95
  ### Droplet commands
42
96
 
43
- Not yet implemented. Coming soon!
97
+ To create a droplet:
98
+
99
+ ```
100
+ Lita: do droplets create HOSTNAME SIZE_ID_OR_SLUG IMAGE_ID_OR_SLUG REGION_ID_OR_SLUG [--ssh-key-ids SSH_KEY_IDS] [--private-networking] [--backups-enabled]
101
+ ```
102
+
103
+ To delete a droplet, optionally writing zeroes to the disk first:
104
+
105
+ ```
106
+ Lita: do droplets delete ID [--scrub]
107
+ ```
108
+
109
+ To list all droplets:
110
+
111
+ ```
112
+ Lita: do droplets list
113
+ ```
114
+
115
+ To reset the root password for a droplet:
116
+
117
+ ```
118
+ Lita: do droplets password reset ID
119
+ ```
120
+
121
+ To power cycle a droplet:
122
+
123
+ ```
124
+ Lita: do droplets power cycle ID
125
+ ```
126
+
127
+ To power off a droplet:
128
+
129
+ ```
130
+ Lita: do droplets power off ID
131
+ ```
132
+
133
+ To power on a droplet:
134
+
135
+ ```
136
+ Lita: do droplets power on ID
137
+ ```
138
+
139
+ To reboot a droplet:
140
+
141
+ ```
142
+ Lita: do droplets reboot ID
143
+ ```
144
+
145
+ To rebuild a droplet:
146
+
147
+ ```
148
+ Lita: do droplets rebuild ID IMAGE_ID
149
+ ```
150
+
151
+ To resize a droplet's disk:
152
+
153
+ ```
154
+ Lita: do droplets resize ID SIZE_ID_OR_SLUG
155
+ ```
156
+
157
+ To restore a droplet from an image:
158
+
159
+ ```
160
+ Lita: do droplets restore ID IMAGE_ID
161
+ ```
162
+
163
+ To show the details of a droplet:
164
+
165
+ ```
166
+ Lita: do droplets show ID
167
+ ```
168
+
169
+ To shut down a droplet:
170
+
171
+ ```
172
+ Lita: do droplets shutdown ID
173
+ ```
174
+
175
+ To take a snapshot of a droplet, optionally naming the snapshot:
176
+
177
+ ```
178
+ Lita: do droplets snapshot ID [NAME]
179
+ ```
44
180
 
45
181
  ### Image commands
46
182
 
47
- Not yet implemented. Coming soon!
183
+ To delete an image:
184
+
185
+ ```
186
+ Lita: do images delete ID_OR_SLUG
187
+ ```
188
+
189
+ To list all possible images:
190
+
191
+ ```
192
+ Lita: do images list
193
+ ```
194
+
195
+ To list only global images:
196
+
197
+ ```
198
+ Lita: do images list global
199
+ ```
200
+
201
+ To list only your own images:
202
+
203
+ ```
204
+ Lita: do images list my_images
205
+ ```
206
+
207
+ To show the details of an image:
208
+
209
+ ```
210
+ Lita: do images show ID_OR_SLUG
211
+ ```
48
212
 
49
213
  ### Region commands
50
214
 
51
- Not yet implemented. Coming soon!
215
+ To list all the possible regions:
216
+
217
+ ```
218
+ Lita: do regions list
219
+ ```
52
220
 
53
221
  ### SSH key commands
54
222
 
@@ -67,7 +235,7 @@ Lita: do ssh keys delete ID
67
235
  To edit the name and/or public key of an existing SSH key:
68
236
 
69
237
  ```
70
- Lita: do ssh keys edit ID [name=NAME] [public_key=PUBLIC_KEY]
238
+ Lita: do ssh keys edit ID [--name NAME] [--public-key PUBLIC_KEY]
71
239
  ```
72
240
 
73
241
  To list the names and IDs of all SSH keys:
@@ -84,7 +252,11 @@ Lita: do ssh keys show ID
84
252
 
85
253
  ### Size commands
86
254
 
87
- Not yet implemented. Coming soon!
255
+ To list all the possible image sizes:
256
+
257
+ ```
258
+ Lita: do sizes list
259
+ ```
88
260
 
89
261
  ## License
90
262
 
@@ -1,3 +1,13 @@
1
+ # This unfortunate monkey patch can be removed when a new i18n gem is released with the
2
+ # following patch in it: https://github.com/svenfuchs/i18n/pull/250
3
+ class Hash
4
+ def slice(*keep_keys)
5
+ h = self.class.new
6
+ keep_keys.each { |key| h[key] = fetch(key) }
7
+ h
8
+ end
9
+ end
10
+
1
11
  require "lita"
2
12
 
3
13
  Lita.load_locales Dir[File.expand_path(
@@ -5,3 +15,11 @@ Lita.load_locales Dir[File.expand_path(
5
15
  )]
6
16
 
7
17
  require "lita/handlers/digitalocean"
18
+ require "lita/handlers/digitalocean/base"
19
+ require "lita/handlers/digitalocean/domain"
20
+ require "lita/handlers/digitalocean/domain_record"
21
+ require "lita/handlers/digitalocean/droplet"
22
+ require "lita/handlers/digitalocean/image"
23
+ require "lita/handlers/digitalocean/region"
24
+ require "lita/handlers/digitalocean/ssh_key"
25
+ require "lita/handlers/digitalocean/size"
@@ -1,5 +1,3 @@
1
- require "digital_ocean"
2
-
3
1
  module Lita
4
2
  module Handlers
5
3
  class Digitalocean < Handler
@@ -7,151 +5,6 @@ module Lita
7
5
  config.client_id = nil
8
6
  config.api_key = nil
9
7
  end
10
-
11
- private
12
-
13
- def self.do_route(regexp, route_name, help)
14
- route(regexp, route_name, command: true, restrict_to: :digitalocean_admins, help: help)
15
- end
16
-
17
- public
18
-
19
- do_route /^do\s+ssh\s+keys?\s+add\s+.+$/i, :ssh_keys_add, {
20
- t("help.ssh_keys.add_key") => t("help.ssh_keys.add_value")
21
- }
22
-
23
- do_route /^do\s+ssh\s+keys?\s+delete\s+(\d+)$/i, :ssh_keys_delete, {
24
- t("help.ssh_keys.delete_key") => t("help.ssh_keys.delete_value")
25
- }
26
-
27
- do_route /^do\s+ssh\s+keys?\s+edit\s+(\d+)\s+.+$/i, :ssh_keys_edit, {
28
- t("help.ssh_keys.edit_key") => t("help.ssh_keys.edit_value")
29
- }
30
-
31
- do_route /^do\s+ssh\s+keys?\s+list$/i, :ssh_keys_list, {
32
- t("help.ssh_keys.list_key") => t("help.ssh_keys.list_value")
33
- }
34
-
35
- do_route /^do\s+ssh\s+keys?\s+show\s+(\d+)$/i, :ssh_keys_show, {
36
- t("help.ssh_keys.show_key") => t("help.ssh_keys.show_value"),
37
- }
38
-
39
- def ssh_keys_add(response)
40
- name, public_key = response.args[3..4]
41
-
42
- unless name && public_key
43
- return response.reply("#{t('format')}: #{t('help.ssh_keys.add_key')}")
44
- end
45
-
46
- do_response = do_call(response) do |client|
47
- client.ssh_keys.add(name: name, ssh_pub_key: public_key)
48
- end or return
49
-
50
- key = do_response.ssh_key
51
- response.reply(
52
- t("ssh_keys.add.created", message: "#{key.id} (#{key.name}): #{key.ssh_pub_key}")
53
- )
54
- end
55
-
56
- def ssh_keys_delete(response)
57
- key_id = response.matches[0][0]
58
-
59
- do_call(response) do |client|
60
- client.ssh_keys.delete(key_id)
61
- end or return
62
-
63
- response.reply(t("ssh_keys.delete.deleted", key_id: key_id))
64
- end
65
-
66
- def ssh_keys_edit(response)
67
- args = extract_named_args(response.args, :name, :public_key)
68
-
69
- if args[:public_key]
70
- args[:ssh_pub_key] = args.delete(:public_key)
71
- end
72
-
73
- do_response = do_call(response) do |client|
74
- client.ssh_keys.edit(response.matches[0][0], args)
75
- end or return
76
-
77
- key = do_response.ssh_key
78
- response.reply(
79
- t("ssh_keys.edit.updated", message: "#{key.id} (#{key.name}): #{key.ssh_pub_key}")
80
- )
81
- end
82
-
83
- def ssh_keys_list(response)
84
- do_response = do_call(response) do |client|
85
- client.ssh_keys.list
86
- end or return
87
-
88
- if do_response.ssh_keys.empty?
89
- response.reply(t("ssh_keys.list.empty"))
90
- else
91
- do_response.ssh_keys.each do |key|
92
- response.reply("#{key.id} (#{key.name})")
93
- end
94
- end
95
- end
96
-
97
- def ssh_keys_show(response)
98
- do_response = do_call(response) do |client|
99
- client.ssh_keys.show(response.matches[0][0])
100
- end or return
101
-
102
- key = do_response.ssh_key
103
- response.reply("#{key.id} (#{key.name}): #{key.ssh_pub_key}")
104
- end
105
-
106
- private
107
-
108
- def api_key
109
- config.api_key
110
- end
111
-
112
- def client
113
- @client ||= ::DigitalOcean::API.new(client_id: client_id, api_key: api_key)
114
- end
115
-
116
- def client_id
117
- config.client_id
118
- end
119
-
120
- def config
121
- Lita.config.handlers.digitalocean
122
- end
123
-
124
- def do_call(response)
125
- unless api_key && client_id
126
- response.reply(t("credentials_missing"))
127
- return
128
- end
129
-
130
- do_response = yield client
131
-
132
- if do_response.status != "OK"
133
- response.reply(t("error", message: do_response.message))
134
- return
135
- end
136
-
137
- do_response
138
- end
139
-
140
- def extract_named_args(args, *keys)
141
- args.inject({}) do |hash, arg|
142
- key, value = arg.split("=", 2)
143
-
144
- if value
145
- normalized_key = key.downcase.to_sym
146
-
147
- if keys.include?(normalized_key)
148
- hash[normalized_key] = value.gsub(/\A["']|["']\Z/, "")
149
- end
150
- end
151
-
152
- hash
153
- end
154
- end
155
8
  end
156
9
 
157
10
  Lita.register_handler(Digitalocean)
@@ -0,0 +1,62 @@
1
+ require "digital_ocean"
2
+ require "lita-keyword-arguments"
3
+ require "hashie"
4
+
5
+ module Lita
6
+ module Handlers
7
+ class Digitalocean < Handler
8
+ class Base < Handler
9
+ # Override key for locale namespace.
10
+ def self.name
11
+ "Digitalocean"
12
+ end
13
+
14
+ private
15
+
16
+ def self.do_route(regexp, route_name, help, kwargs = nil)
17
+ options = {
18
+ command: true,
19
+ help: help,
20
+ restrict_to: :digitalocean_admins
21
+ }
22
+
23
+ options[:kwargs] = kwargs if kwargs
24
+
25
+ route(regexp, route_name, options)
26
+ end
27
+
28
+ def api_key
29
+ config.api_key
30
+ end
31
+
32
+ def client
33
+ @client ||= ::DigitalOcean::API.new(client_id: client_id, api_key: api_key)
34
+ end
35
+
36
+ def client_id
37
+ config.client_id
38
+ end
39
+
40
+ def do_call(response)
41
+ unless api_key && client_id
42
+ response.reply(t("credentials_missing"))
43
+ return
44
+ end
45
+
46
+ do_response = yield client
47
+
48
+ if do_response[:status] != "OK"
49
+ response.reply(t("error", message: do_response[:message]))
50
+ return
51
+ end
52
+
53
+ do_response
54
+ end
55
+
56
+ def format_array(array)
57
+ %([#{array.join(",")}])
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end