knife-digital_ocean 2.1.0 → 2.2.0

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +6 -0
  5. data/Guardfile +1 -16
  6. data/README.md +112 -2
  7. data/knife-digital_ocean.gemspec +3 -0
  8. data/lib/chef/knife/digital_ocean_account_info.rb +45 -0
  9. data/lib/chef/knife/digital_ocean_domain_create.rb +55 -0
  10. data/lib/chef/knife/digital_ocean_domain_destroy.rb +43 -0
  11. data/lib/chef/knife/digital_ocean_domain_list.rb +44 -0
  12. data/lib/chef/knife/digital_ocean_domain_record_create.rb +78 -0
  13. data/lib/chef/knife/digital_ocean_domain_record_destroy.rb +54 -0
  14. data/lib/chef/knife/digital_ocean_domain_record_edit.rb +88 -0
  15. data/lib/chef/knife/digital_ocean_domain_record_list.rb +56 -0
  16. data/lib/chef/knife/digital_ocean_droplet_destroy.rb +29 -3
  17. data/lib/chef/knife/digital_ocean_sshkey_create.rb +54 -0
  18. data/lib/chef/knife/digital_ocean_sshkey_destroy.rb +43 -0
  19. data/lib/knife-digital_ocean/version.rb +1 -1
  20. data/spec/fixtures/vcr_cassettes/accountinfo.yml +65 -0
  21. data/spec/fixtures/vcr_cassettes/domainlist.yml +69 -0
  22. data/spec/fixtures/vcr_cassettes/public_images.yml +164 -0
  23. data/spec/lib/chef/knife/digital_ocean_account_info_spec.rb +37 -0
  24. data/spec/lib/chef/knife/digital_ocean_domain_create_spec.rb +5 -0
  25. data/spec/lib/chef/knife/digital_ocean_domain_destroy_spec.rb +5 -0
  26. data/spec/lib/chef/knife/digital_ocean_domain_list_spec.rb +38 -0
  27. data/spec/lib/chef/knife/digital_ocean_domain_record_create_spec.rb +5 -0
  28. data/spec/lib/chef/knife/digital_ocean_domain_record_destroy_spec.rb +5 -0
  29. data/spec/lib/chef/knife/digital_ocean_domain_record_edit_spec.rb +5 -0
  30. data/spec/lib/chef/knife/digital_ocean_domain_record_list_spec.rb +5 -0
  31. data/spec/lib/chef/knife/digital_ocean_image_list_spec.rb +14 -1
  32. data/spec/lib/chef/knife/digital_ocean_sshkey_create_spec.rb +5 -0
  33. data/spec/lib/chef/knife/digital_ocean_sshkey_destroy_spec.rb +5 -0
  34. data/spec/spec_helper.rb +26 -4
  35. metadata +83 -3
@@ -0,0 +1,54 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+
14
+ require 'chef/knife/digital_ocean_base'
15
+
16
+ class Chef
17
+ class Knife
18
+ class DigitalOceanDomainRecordDestroy < Knife
19
+ include Knife::DigitalOceanBase
20
+
21
+ banner 'knife digital_ocean domain record destroy (options)'
22
+
23
+ option :domain,
24
+ :short => '-D NAME',
25
+ :long => '--domain-id NAME',
26
+ :description => 'The domain name'
27
+
28
+ option :record,
29
+ :short => '-R ID',
30
+ :long => '--record-id ID',
31
+ :description => 'The record id'
32
+
33
+ def run
34
+ $stdout.sync = true
35
+
36
+ validate!
37
+
38
+ unless locate_config_value(:domain)
39
+ ui.error("Domain cannot be empty. => -D <domain-name>")
40
+ exit 1
41
+ end
42
+
43
+ unless locate_config_value(:record)
44
+ ui.error("Record cannot be empty. => -R <record-id>")
45
+ exit 1
46
+ end
47
+
48
+ result = client.domain_records.delete for_domain: locate_config_value(:domain), id: locate_config_value(:record)
49
+ ui.error JSON.parse(result)['message'] rescue 'OK'
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,88 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+
14
+ require 'chef/knife/digital_ocean_base'
15
+
16
+ class Chef
17
+ class Knife
18
+ class DigitalOceanDomainRecordEdit < Knife
19
+ include Knife::DigitalOceanBase
20
+
21
+ banner 'knife digital_ocean domain record edit (options)'
22
+
23
+ option :domain,
24
+ :short => '-D NAME',
25
+ :long => '--domain-id NAME',
26
+ :description => 'The domain name'
27
+
28
+ option :record,
29
+ :short => '-R ID',
30
+ :long => '--record-id ID',
31
+ :description => 'The record id'
32
+
33
+ option :type,
34
+ :short => '-T RECORD TYPE',
35
+ :long => '--type RECORD TYPE',
36
+ :description => 'The type of record'
37
+
38
+ option :name,
39
+ :short => '-N RECORD NAME',
40
+ :long => '--name RECORD NAME',
41
+ :description => 'The record name'
42
+
43
+ option :data,
44
+ :short => '-a DATA',
45
+ :long => '--data DATA',
46
+ :description => 'The record data'
47
+
48
+ def run
49
+ $stdout.sync = true
50
+
51
+ validate!
52
+
53
+ unless locate_config_value(:domain)
54
+ ui.error("Domain cannot be empty. => -D <domain-name>")
55
+ exit 1
56
+ end
57
+
58
+ unless locate_config_value(:record)
59
+ ui.error("Record cannot be empty. => -R <record-id>")
60
+ exit 1
61
+ end
62
+
63
+ unless locate_config_value(:type)
64
+ ui.error("Record type cannot be empty. => -T <record-type>")
65
+ exit 1
66
+ end
67
+
68
+ unless locate_config_value(:name)
69
+ ui.error("Record name cannot be empty. => -N <record-name>")
70
+ exit 1
71
+ end
72
+
73
+ unless locate_config_value(:data)
74
+ ui.error("Record data cannot be empty. => -d <data>")
75
+ exit 1
76
+ end
77
+
78
+ domain_record = DropletKit::DomainRecord.new(
79
+ type: locate_config_value(:type),
80
+ name: locate_config_value(:name),
81
+ data: locate_config_value(:data)
82
+ )
83
+ result = client.domain_records.update domain_record, for_domain: locate_config_value(:domain), id: locate_config_value(:record)
84
+ ui.error JSON.parse(result)['message'] rescue 'OK'
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,56 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+
14
+ class Chef
15
+ class Knife
16
+ class DigitalOceanDomainRecordList < Knife
17
+ include Knife::DigitalOceanBase
18
+
19
+ banner 'knife digital_ocean domain record list (options)'
20
+
21
+ option :name,
22
+ :short => '-D NAME',
23
+ :long => '--domain-name NAME',
24
+ :description => 'The domain name'
25
+
26
+ def run
27
+ $stdout.sync = true
28
+
29
+ validate!
30
+
31
+ unless locate_config_value(:name)
32
+ ui.error("Domain Name cannot be empty. => -D <domain-name>")
33
+ exit 1
34
+ end
35
+
36
+ domains_list = [
37
+ ui.color('ID', :bold),
38
+ ui.color('Type', :bold),
39
+ ui.color('Name', :bold),
40
+ ui.color('Data', :bold)
41
+ ]
42
+
43
+ records = client.domain_records.all for_domain: locate_config_value(:name)
44
+ records.each do |domain|
45
+ domains_list << domain.id.to_s
46
+ domains_list << domain.type.to_s
47
+ domains_list << domain.name.to_s
48
+ domains_list << domain.data.to_s
49
+ end
50
+
51
+
52
+ puts ui.list(domains_list, :uneven_columns_across, 4)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -24,18 +24,44 @@ class Chef
24
24
  long: '--server ID',
25
25
  description: 'The server id'
26
26
 
27
+ option :all,
28
+ short: '-a',
29
+ long: '--all',
30
+ description: '!WARNING! UNRECOVERABLE Destroy all droplets.'
31
+
32
+
27
33
  def run
28
34
  $stdout.sync = true
29
35
 
30
36
  validate!
31
37
 
32
- unless locate_config_value(:server)
38
+ droplets_ids = []
39
+
40
+ unless locate_config_value(:server) || locate_config_value(:all)
33
41
  ui.error('Server cannot be empty. ALL DATA WILL BE LOST! => -S <server-id>')
34
42
  exit 1
35
43
  end
36
44
 
37
- result = client.droplets.delete(id: locate_config_value(:server))
38
- puts JSON.parse(result)['message'] rescue 'OK'
45
+ if locate_config_value(:all) && !client.droplets
46
+ ui.error('You don`t have droplets')
47
+ exit 1
48
+ end
49
+
50
+ if locate_config_value(:server)
51
+ droplets_ids = [locate_config_value(:server)]
52
+ end
53
+
54
+ if locate_config_value(:all)
55
+ droplets_ids = client.droplets.all.map do |droplet|
56
+ droplet.id
57
+ end
58
+ end
59
+
60
+ droplets_ids.each do |id|
61
+ puts "Delete droplet with id: #{id}"
62
+ result = client.droplets.delete(id: id)
63
+ puts JSON.parse(result)['message'] rescue 'OK'
64
+ end
39
65
  end
40
66
  end
41
67
  end
@@ -0,0 +1,54 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+
14
+ require 'chef/knife/digital_ocean_base'
15
+
16
+ class Chef
17
+ class Knife
18
+ class DigitalOceanSshkeyCreate < Knife
19
+ include Knife::DigitalOceanBase
20
+
21
+ banner 'knife digital_ocean sshkey create (options)'
22
+
23
+ option :name,
24
+ :short => '-n NAME',
25
+ :long => '--sshkey-name NAME',
26
+ :description => 'The ssh key name'
27
+
28
+ option :public_key,
29
+ :short => '-i PUBLIC KEY',
30
+ :long => '--public-key PUBLIC KEY',
31
+ :description => 'File that contains your public ssh key'
32
+
33
+ def run
34
+ $stdout.sync = true
35
+
36
+ validate!
37
+
38
+ unless locate_config_value(:name)
39
+ ui.error("SSH Key name cannot be empty. => -N <sshkey-name>")
40
+ exit 1
41
+ end
42
+
43
+ unless locate_config_value(:public_key)
44
+ ui.error("SSH key file needs to be specified. => -I <public_key>")
45
+ exit 1
46
+ end
47
+
48
+ ssh_key = DropletKit::SSHKey.new name: locate_config_value(:name), public_key: File.read(File.expand_path(locate_config_value(:public_key)))
49
+ result = client.ssh_keys.create(ssh_key)
50
+ ui.error JSON.parse(result)['message'] rescue 'OK'
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+
14
+ require 'chef/knife/digital_ocean_base'
15
+
16
+ class Chef
17
+ class Knife
18
+ class DigitalOceanSshkeyDestroy < Knife
19
+ include Knife::DigitalOceanBase
20
+
21
+ banner 'knife digital_ocean sshkey destroy (options)'
22
+
23
+ option :id,
24
+ :short => '-i ID',
25
+ :long => '--sshkey-id ID',
26
+ :description => 'The ssh key id'
27
+
28
+ def run
29
+ $stdout.sync = true
30
+
31
+ validate!
32
+
33
+ unless locate_config_value(:id)
34
+ ui.error("SSH key id cannot be empty. => -i <id>")
35
+ exit 1
36
+ end
37
+
38
+ result = client.ssh_keys.delete id: locate_config_value(:id)
39
+ ui.error JSON.parse(result)['message'] rescue 'OK'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module DigitalOcean
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.digitalocean.com/v2/account
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Authorization:
13
+ - Bearer FAKE_ACCESS_TOKEN
14
+ User-Agent:
15
+ - Faraday v0.9.0
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Tue, 11 Nov 2014 03:48:34 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - __cfduid=d4ff495c6a4297ba6a268c69722a7928c1415677714886; expires=Mon, 23-Dec-2019
37
+ 23:50:00 GMT; path=/; domain=.digitalocean.com; HttpOnly
38
+ Status:
39
+ - 200 OK
40
+ X-Frame-Options:
41
+ - SAMEORIGIN
42
+ X-Xss-Protection:
43
+ - 1; mode=block
44
+ X-Content-Type-Options:
45
+ - nosniff
46
+ Ratelimit-Limit:
47
+ - '1200'
48
+ Ratelimit-Remaining:
49
+ - '1180'
50
+ Ratelimit-Reset:
51
+ - '1415677540'
52
+ Cache-Control:
53
+ - max-age=0, private, must-revalidate
54
+ X-Request-Id:
55
+ - 8e7ba67a-eeca-432d-9a5f-951d3956a67c
56
+ X-Runtime:
57
+ - '0.022150'
58
+ Cf-Ray:
59
+ - 187783d60a990ecd-EWR
60
+ body:
61
+ encoding: UTF-8
62
+ string: '{"account":{"droplet_limit":20,"email":"greg@gregf.org","uuid":"49e2e737d3a7407a042bb7e88f4da8629166f2b9","email_verified":true}}'
63
+ http_version:
64
+ recorded_at: Tue, 11 Nov 2014 03:48:34 GMT
65
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.digitalocean.com/v2/domains
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Authorization:
13
+ - Bearer FAKE_ACCESS_TOKEN
14
+ User-Agent:
15
+ - Faraday v0.9.0
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Tue, 11 Nov 2014 02:03:24 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - __cfduid=da09923cc0418e749f91c7994a5bd60711415671404660; expires=Mon, 23-Dec-2019
37
+ 23:50:00 GMT; path=/; domain=.digitalocean.com; HttpOnly
38
+ Status:
39
+ - 200 OK
40
+ X-Frame-Options:
41
+ - SAMEORIGIN
42
+ X-Xss-Protection:
43
+ - 1; mode=block
44
+ X-Content-Type-Options:
45
+ - nosniff
46
+ Ratelimit-Limit:
47
+ - '1200'
48
+ Ratelimit-Remaining:
49
+ - '1199'
50
+ Ratelimit-Reset:
51
+ - '1415675004'
52
+ Cache-Control:
53
+ - max-age=0, private, must-revalidate
54
+ X-Request-Id:
55
+ - 50c94a8d-a8aa-4a97-9443-65b5d36ef5ba
56
+ X-Runtime:
57
+ - '0.097458'
58
+ Cf-Ray:
59
+ - 1876e9c7159c0ec7-EWR
60
+ body:
61
+ encoding: UTF-8
62
+ string: '{"domains":[{"name":"gregf.org","ttl":1800,"zone_file":"$ORIGIN gregf.org.\n$TTL
63
+ 1800\ngregf.org. IN SOA ns1.digitalocean.com. hostmaster.gregf.org. 1415640503
64
+ 10800 3600 604800 1800\ngregf.org. 1800 IN NS ns1.digitalocean.com.\ngregf.org.
65
+ 1800 IN NS ns2.digitalocean.com.\ngregf.org. 1800 IN NS ns3.digitalocean.com.\ngregf.org.
66
+ 1800 IN A 162.243.243.162\n"}],"links":{},"meta":{"total":1}}'
67
+ http_version:
68
+ recorded_at: Tue, 11 Nov 2014 02:03:24 GMT
69
+ recorded_with: VCR 2.9.3