droplet_kit 2.3.0 → 2.4.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: 2ecbe9de2e2f4c7fc8678c9c3e997208d79b3b8f
4
- data.tar.gz: 6a9e211e1303f9c226d3d039789308c047340bcd
3
+ metadata.gz: 84d6ad636a505caf049b0c9bcf8c38ff0aedda28
4
+ data.tar.gz: a447e68783fce91d0eeaa1ecbefaf1ce1752ed57
5
5
  SHA512:
6
- metadata.gz: 3a762b334cf6b65390ad5551ebae8286499f82aa49e996e16772609046904261e2c52c1dbe2b9926f244cd88f694053cba74e1805ec007ceb83d250bd4e3c460
7
- data.tar.gz: d43a3564498375614861eb2416de54e3182879130efd71a7321ae04205f01e7e9e92a73088cb4a9d044149ee8ba0bd49b57c2e08292c6a0c751c673d18d16128
6
+ metadata.gz: d592ec69dd61e597c02a7ab9e737b42b58fa62189024ee745f27fa77d22e8fb99de448d7c09eae4d98325d813b7e5d2671ff669ef8b1b4721fb00b65f746afed
7
+ data.tar.gz: 7ab6c9ae7ea96cabdc6b03be3abae4e4f559039bba48f4062dbce3f9763c153f9953b5dd77ce36a96783314622585c0fa3cae38e8514de2c8764609f1a2b46b6
@@ -7,9 +7,10 @@ before_install:
7
7
  rvm:
8
8
  - "2.0.0"
9
9
  - "2.1.10"
10
- - "2.2.7"
11
- - "2.3.4"
12
- - "2.4.1"
10
+ - "2.2.10"
11
+ - "2.3.7"
12
+ - "2.4.4"
13
+ - "2.5.1"
13
14
 
14
15
  matrix:
15
16
  exclude:
@@ -1,3 +1,6 @@
1
+ ### Version 2.4.0
2
+ * Added CDN resource.
3
+
1
4
  ### Version 2.3.0
2
5
  * Added support for Let's Encrypt certificates.
3
6
 
@@ -11,7 +14,7 @@
11
14
  * Added Firewall resource.
12
15
  * Added support for updating TTLs for DomainRecord resource.
13
16
  * Added support of all Rails 5 releases.
14
- * Added depreciation for Tag resource rename.
17
+ * Added deprecation for Tag resource rename.
15
18
 
16
19
  ### Version 2.1.0
17
20
  * Added monitoring to the Droplet resource.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # DropletKit
2
+ [![Build Status](https://travis-ci.org/digitalocean/droplet_kit.svg?branch=master)](https://travis-ci.org/digitalocean/droplet_kit)
3
+ [![Gem Version](https://badge.fury.io/rb/droplet_kit.svg)](https://badge.fury.io/rb/droplet_kit)
2
4
 
3
5
  DropletKit is the official [DigitalOcean V2 API](https://developers.digitalocean.com/v2/) client. It supports everything the API can do with a simple interface written in Ruby.
4
6
 
5
- [![Build Status](https://travis-ci.org/digitalocean/droplet_kit.svg?branch=master)](https://travis-ci.org/digitalocean/droplet_kit)
6
-
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
@@ -25,6 +25,7 @@ You'll need to generate an access token in Digital Ocean's control panel at http
25
25
  With your access token, retrieve a client instance with it.
26
26
 
27
27
  ```ruby
28
+ require 'droplet_kit'
28
29
  client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
29
30
  ```
30
31
 
@@ -64,6 +65,26 @@ droplet = client.droplets.find(id: 123)
64
65
 
65
66
  # All Resources and actions.
66
67
 
68
+ ## CDN resource
69
+
70
+ ```ruby
71
+ client = DropletKit::Client.new(access_token: 'TOKEN')
72
+ client.cdns #=> DropletKit::CertificateResource
73
+ cdn = DropletKit::CDN.new(
74
+ origin: 'myspace.nyc3.digitaloceanspaces.com',
75
+ ttl: 1800
76
+ )
77
+ ```
78
+
79
+ Actions supported:
80
+
81
+ * `client.cdns.find(id: 'id')`
82
+ * `client.cdns.all()`
83
+ * `client.cdns.create(cdn)`
84
+ * `client.cdns.update_ttl(id: 'id', ttl: 3600)`
85
+ * `client.cdns.flush_cache(id: 'id', files: ['*', 'path/to/css/*'])`
86
+ * `client.cdns.delete(id: 'id')`
87
+
67
88
  ## Certificate resource
68
89
 
69
90
  ```ruby
@@ -38,6 +38,7 @@ module DropletKit
38
38
  autoload :FirewallInboundRule, 'droplet_kit/models/firewall_inbound_rule'
39
39
  autoload :FirewallOutboundRule, 'droplet_kit/models/firewall_outbound_rule'
40
40
  autoload :FirewallPendingChange, 'droplet_kit/models/firewall_pending_change'
41
+ autoload :CDN, 'droplet_kit/models/cdn'
41
42
 
42
43
  # Resources
43
44
  autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
@@ -61,6 +62,7 @@ module DropletKit
61
62
  autoload :LoadBalancerResource, 'droplet_kit/resources/load_balancer_resource'
62
63
  autoload :CertificateResource, 'droplet_kit/resources/certificate_resource'
63
64
  autoload :FirewallResource, 'droplet_kit/resources/firewall_resource'
65
+ autoload :CDNResource, 'droplet_kit/resources/cdn_resource'
64
66
 
65
67
  # JSON Maps
66
68
  autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
@@ -94,6 +96,7 @@ module DropletKit
94
96
  autoload :FirewallInboundRuleMapping, 'droplet_kit/mappings/firewall_inbound_rule_mapping'
95
97
  autoload :FirewallOutboundRuleMapping, 'droplet_kit/mappings/firewall_outbound_rule_mapping'
96
98
  autoload :FirewallPendingChangeMapping, 'droplet_kit/mappings/firewall_pending_change_mapping'
99
+ autoload :CDNMapping, 'droplet_kit/mappings/cdn_mapping'
97
100
 
98
101
  # Utils
99
102
  autoload :PaginatedResource, 'droplet_kit/paginated_resource'
@@ -19,6 +19,7 @@ module DropletKit
19
19
  def self.resources
20
20
  {
21
21
  actions: ActionResource,
22
+ cdns: CDNResource,
22
23
  certificates: CertificateResource,
23
24
  droplets: DropletResource,
24
25
  domains: DomainResource,
@@ -0,0 +1,31 @@
1
+ module DropletKit
2
+ class CDNMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping CDN
7
+ root_key singular: 'endpoint', plural: 'endpoints', scopes: [:read]
8
+
9
+ scoped :read do
10
+ property :id
11
+ property :ttl
12
+ property :origin
13
+ property :endpoint
14
+ property :created_at
15
+ end
16
+
17
+ scoped :create do
18
+ property :origin
19
+ property :ttl
20
+ end
21
+
22
+ scoped :update do
23
+ property :ttl
24
+ end
25
+
26
+ scoped :delete_cache do
27
+ property :files
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module DropletKit
2
+ class CDN < BaseModel
3
+ attribute :id
4
+ attribute :ttl
5
+ attribute :origin
6
+ attribute :endpoint
7
+ attribute :created_at
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ module DropletKit
2
+ class CDNResource < ResourceKit::Resource
3
+ include ErrorHandlingResourcable
4
+
5
+ resources do
6
+ action :find, 'GET /v2/cdn/endpoints/:id' do
7
+ handler(200) { |response| CDNMapping.extract_single(response.body, :read) }
8
+ end
9
+
10
+ action :all, 'GET /v2/cdn/endpoints' do
11
+ query_keys :per_page, :page
12
+ handler(200) { |response| CDNMapping.extract_collection(response.body, :read) }
13
+ end
14
+
15
+ action :create, 'POST /v2/cdn/endpoints' do
16
+ body { |cdn| CDNMapping.representation_for(:create, cdn) }
17
+ handler(201) { |response| CDNMapping.extract_single(response.body, :read) }
18
+ handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
19
+ end
20
+
21
+ action :update_ttl, 'PUT /v2/cdn/endpoints/:id' do
22
+ body { |hash| { ttl: hash[:ttl] }.to_json }
23
+ handler(200) { |response| CDNMapping.extract_single(response.body, :read) }
24
+ handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
25
+ end
26
+
27
+ action :flush_cache, 'DELETE /v2/cdn/endpoints/:id/cache' do
28
+ body { |hash| { files: hash[:files] }.to_json }
29
+ handler(204) { |_| true }
30
+ handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
31
+ end
32
+
33
+ action :delete, 'DELETE /v2/cdn/endpoints/:id' do
34
+ handler(204) { |_| true }
35
+ end
36
+ end
37
+
38
+ def all(*args)
39
+ PaginatedResource.new(action(:all), self, *args)
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -0,0 +1,16 @@
1
+ {
2
+ "endpoints": [
3
+ {
4
+ "id": "7724db7c-e098-11e5-b522-000f53304e51",
5
+ "origin": "my-space-cdn.nyc3.digitaloceanspaces.com",
6
+ "endpoint": "my-space-cdn.nyc3.cdn.digitaloceanspaces.com",
7
+ "ttl": 3600,
8
+ "created_at": "2016-03-02T17:00:49Z"
9
+ }
10
+ ],
11
+ "links": {
12
+ },
13
+ "meta": {
14
+ "total": 1
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
+ "origin": "my-space-cdn.nyc3.digitaloceanspaces.com",
5
+ "endpoint": "my-space-cdn.nyc3.cdn.digitaloceanspaces.com",
6
+ "ttl": 3600,
7
+ "created_at": "2016-03-02T17:00:49Z"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
+ "origin": "my-space-cdn.nyc3.digitaloceanspaces.com",
5
+ "endpoint": "my-space-cdn.nyc3.cdn.digitaloceanspaces.com",
6
+ "ttl": 3600,
7
+ "created_at": "2016-03-02T17:00:49Z"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "endpoint": {
3
+ "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
+ "origin": "my-space-cdn.nyc3.digitaloceanspaces.com",
5
+ "endpoint": "my-space-cdn.nyc3.cdn.digitaloceanspaces.com",
6
+ "ttl": 60,
7
+ "created_at": "2016-03-02T17:00:49Z"
8
+ }
9
+ }
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DropletKit::CDNResource do
4
+ subject(:resource) { described_class.new(connection: connection) }
5
+ include_context 'resources'
6
+
7
+ let(:id) { '7724db7c-e098-11e5-b522-000f53304e51' }
8
+ let(:origin) { 'my-space-cdn.nyc3.digitaloceanspaces.com' }
9
+ let(:endpoint) { 'my-space-cdn.nyc3.cdn.digitaloceanspaces.com' }
10
+ let(:ttl) { 3600 }
11
+ let(:created_at) { '2016-03-02T17:00:49Z' }
12
+
13
+ let(:path) { '/v2/cdn/endpoints' }
14
+ let(:path_with_id) { "#{path}/#{id}" }
15
+
16
+ RSpec::Matchers.define :match_cdn_fixture do
17
+ match do |cdn|
18
+ expect(cdn).to be_kind_of(DropletKit::CDN)
19
+
20
+ expect(cdn.id).to eq(id)
21
+ expect(cdn.origin).to eq(origin)
22
+ expect(cdn.endpoint).to eq(endpoint)
23
+ expect(cdn.ttl).to eq(ttl)
24
+ expect(cdn.created_at).to eq(created_at)
25
+ end
26
+ end
27
+
28
+ describe '#all' do
29
+ it 'returns all of the cdns' do
30
+ stub_do_api(path, :get).to_return(body: api_fixture('cdns/all'))
31
+ cdns = resource.all
32
+
33
+ expect(cdns).to all(be_kind_of(DropletKit::CDN))
34
+ expect(cdns.first).to match_cdn_fixture
35
+ end
36
+
37
+ it_behaves_like 'a paginated index' do
38
+ let(:fixture_path) { 'cdns/all' }
39
+ let(:api_path) { '/v2/cdn/endpoints' }
40
+ end
41
+ end
42
+
43
+ describe '#find' do
44
+ it 'returns a singular cdn' do
45
+ stub_do_api(path_with_id, :get).to_return(body: api_fixture('cdns/find'))
46
+ cdn = resource.find(id: id)
47
+
48
+ expect(cdn).to match_cdn_fixture
49
+ end
50
+ end
51
+
52
+ describe '#create' do
53
+ it 'returns the created cdn' do
54
+ cdn = DropletKit::CDN.new(
55
+ origin: origin,
56
+ ttl: ttl
57
+ )
58
+
59
+ as_string = DropletKit::CDNMapping.representation_for(:create, cdn)
60
+ stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('cdns/create'), status: 201)
61
+ created_cdn = resource.create(cdn)
62
+
63
+ expect(created_cdn).to match_cdn_fixture
64
+ end
65
+
66
+ it_behaves_like 'an action that handles invalid parameters' do
67
+ let(:action) { 'create' }
68
+ let(:arguments) { DropletKit::CDN.new }
69
+ end
70
+ end
71
+
72
+ describe '#update_ttl' do
73
+ let(:exception) { DropletKit::FailedUpdate }
74
+
75
+ it 'returns the updated cdn' do
76
+ as_string = { ttl: 60 }.to_json
77
+ stub_do_api(path_with_id, :put).with(body: as_string).to_return(body: api_fixture('cdns/update_ttl'))
78
+ updated_cdn = resource.update_ttl(id: id, ttl: 60)
79
+
80
+ expect(updated_cdn).to be_kind_of(DropletKit::CDN)
81
+
82
+ expect(updated_cdn.id).to eq(id)
83
+ expect(updated_cdn.ttl).to eq(60)
84
+ end
85
+
86
+ it "fails if ttl is invalid" do
87
+ as_string = { ttl: 0 }.to_json
88
+ response_body = { id: :unprocessable_entity, message: 'invalid ttl' }
89
+ stub_do_api(path_with_id, :put).with(body: as_string).to_return(body: response_body.to_json, status: 422)
90
+
91
+ expect { resource.update_ttl(id: id, ttl: 0) }.to raise_exception(exception).with_message(response_body[:message])
92
+ end
93
+ end
94
+
95
+ describe '#flush_cache' do
96
+ let(:cache_path) { "/v2/cdn/endpoints/#{id}/cache" }
97
+ let(:exception) { DropletKit::FailedUpdate }
98
+
99
+ it 'sends a delete request to cdn cache' do
100
+ as_string = { files: ["*"] }.to_json
101
+ request = stub_do_api(cache_path, :delete).with(body: as_string)
102
+ resource.flush_cache(id: id, files: ["*"])
103
+
104
+ expect(request).to have_been_made
105
+ end
106
+
107
+ it "fails if files are not passed in" do
108
+ as_string = { files: [] }.to_json
109
+ response_body = { id: :unprocessable_entity, message: 'invalid request body' }
110
+ stub_do_api(cache_path, :delete).with(body: as_string).to_return(body: response_body.to_json, status: 422)
111
+
112
+ expect { resource.flush_cache(id: id, files: []) }.to raise_exception(exception).with_message(response_body[:message])
113
+ end
114
+ end
115
+
116
+ describe '#delete' do
117
+ it 'sends a delete request for the cdn' do
118
+ request = stub_do_api(path_with_id, :delete)
119
+ resource.delete(id: id)
120
+
121
+ expect(request).to have_been_made
122
+ end
123
+ end
124
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'pry'
3
2
 
4
3
  RSpec.describe DropletKit::CertificateResource do
5
4
  include_context 'resources'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droplet_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Ross
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -205,6 +205,7 @@ files:
205
205
  - lib/droplet_kit/error_handling_resourcable.rb
206
206
  - lib/droplet_kit/mappings/account_mapping.rb
207
207
  - lib/droplet_kit/mappings/action_mapping.rb
208
+ - lib/droplet_kit/mappings/cdn_mapping.rb
208
209
  - lib/droplet_kit/mappings/certificate_mapping.rb
209
210
  - lib/droplet_kit/mappings/domain_mapping.rb
210
211
  - lib/droplet_kit/mappings/domain_record_mapping.rb
@@ -236,6 +237,7 @@ files:
236
237
  - lib/droplet_kit/models/account.rb
237
238
  - lib/droplet_kit/models/action.rb
238
239
  - lib/droplet_kit/models/base_model.rb
240
+ - lib/droplet_kit/models/cdn.rb
239
241
  - lib/droplet_kit/models/certificate.rb
240
242
  - lib/droplet_kit/models/domain.rb
241
243
  - lib/droplet_kit/models/domain_record.rb
@@ -268,6 +270,7 @@ files:
268
270
  - lib/droplet_kit/paginated_resource.rb
269
271
  - lib/droplet_kit/resources/account_resource.rb
270
272
  - lib/droplet_kit/resources/action_resource.rb
273
+ - lib/droplet_kit/resources/cdn_resource.rb
271
274
  - lib/droplet_kit/resources/certificate_resource.rb
272
275
  - lib/droplet_kit/resources/domain_record_resource.rb
273
276
  - lib/droplet_kit/resources/domain_resource.rb
@@ -292,6 +295,10 @@ files:
292
295
  - spec/fixtures/account/info.json
293
296
  - spec/fixtures/actions/all.json
294
297
  - spec/fixtures/actions/find.json
298
+ - spec/fixtures/cdns/all.json
299
+ - spec/fixtures/cdns/create.json
300
+ - spec/fixtures/cdns/find.json
301
+ - spec/fixtures/cdns/update_ttl.json
295
302
  - spec/fixtures/certificates/all.json
296
303
  - spec/fixtures/certificates/find.json
297
304
  - spec/fixtures/certificates/lets_encrypt.json
@@ -379,6 +386,7 @@ files:
379
386
  - spec/lib/droplet_kit/paginated_resource_spec.rb
380
387
  - spec/lib/droplet_kit/resources/account_resource_spec.rb
381
388
  - spec/lib/droplet_kit/resources/action_resource_spec.rb
389
+ - spec/lib/droplet_kit/resources/cdn_resource_spec.rb
382
390
  - spec/lib/droplet_kit/resources/certificate_resource_spec.rb
383
391
  - spec/lib/droplet_kit/resources/domain_record_resource_spec.rb
384
392
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb
@@ -425,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
433
  version: '0'
426
434
  requirements: []
427
435
  rubyforge_project:
428
- rubygems_version: 2.6.8
436
+ rubygems_version: 2.6.11
429
437
  signing_key:
430
438
  specification_version: 4
431
439
  summary: Droplet Kit is the official Ruby library for DigitalOcean's API
@@ -433,6 +441,10 @@ test_files:
433
441
  - spec/fixtures/account/info.json
434
442
  - spec/fixtures/actions/all.json
435
443
  - spec/fixtures/actions/find.json
444
+ - spec/fixtures/cdns/all.json
445
+ - spec/fixtures/cdns/create.json
446
+ - spec/fixtures/cdns/find.json
447
+ - spec/fixtures/cdns/update_ttl.json
436
448
  - spec/fixtures/certificates/all.json
437
449
  - spec/fixtures/certificates/find.json
438
450
  - spec/fixtures/certificates/lets_encrypt.json
@@ -520,6 +532,7 @@ test_files:
520
532
  - spec/lib/droplet_kit/paginated_resource_spec.rb
521
533
  - spec/lib/droplet_kit/resources/account_resource_spec.rb
522
534
  - spec/lib/droplet_kit/resources/action_resource_spec.rb
535
+ - spec/lib/droplet_kit/resources/cdn_resource_spec.rb
523
536
  - spec/lib/droplet_kit/resources/certificate_resource_spec.rb
524
537
  - spec/lib/droplet_kit/resources/domain_record_resource_spec.rb
525
538
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb