-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from viola/add-lb-and-cert-resource
Add Certificate and LoadBalancer resources.
- Loading branch information
Showing
23 changed files
with
820 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ tmp | |
*.o | ||
*.a | ||
mkmf.log | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module DropletKit | ||
class CertificateMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping Certificate | ||
root_key singular: 'certificate', plural: 'certificates', scopes: [:read] | ||
|
||
scoped :read do | ||
property :id | ||
property :name | ||
property :not_after | ||
property :sha1_fingerprint | ||
property :created_at | ||
end | ||
|
||
scoped :create do | ||
property :name | ||
property :private_key | ||
property :leaf_certificate | ||
property :certificate_chain | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module DropletKit | ||
class ForwardingRuleMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
root_key plural: 'forwarding_rules', scopes: [:create, :update] | ||
mapping ForwardingRule | ||
|
||
scoped :read, :create, :update do | ||
property :entry_protocol | ||
property :entry_port | ||
property :target_protocol | ||
property :target_port | ||
property :certificate_id | ||
property :tls_passthrough | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module DropletKit | ||
class HealthCheckMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping HealthCheck | ||
|
||
scoped :read, :create, :update do | ||
property :protocol | ||
property :port | ||
property :path | ||
property :check_interval_seconds | ||
property :response_timeout_seconds | ||
property :healthy_threshold | ||
property :unhealthy_threshold | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module DropletKit | ||
class LoadBalancerMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping LoadBalancer | ||
root_key singular: 'load_balancer', plural: 'load_balancers', scopes: [:read] | ||
|
||
scoped :read do | ||
property :id | ||
property :ip | ||
property :status | ||
property :created_at | ||
property :region, include: RegionMapping | ||
end | ||
|
||
scoped :read, :update, :create do | ||
property :name | ||
property :algorithm | ||
property :tag | ||
property :redirect_http_to_https | ||
property :droplet_ids | ||
property :sticky_sessions, include: StickySessionMapping | ||
property :health_check, include: HealthCheckMapping | ||
property :forwarding_rules, plural: true, include: ForwardingRuleMapping | ||
end | ||
|
||
scoped :update, :create do | ||
property :region | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module DropletKit | ||
class StickySessionMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping StickySession | ||
|
||
scoped :read, :create, :update do | ||
property :type | ||
property :cookie_name | ||
property :cookie_ttl_seconds | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module DropletKit | ||
class Certificate < BaseModel | ||
attribute :id | ||
attribute :name | ||
attribute :not_after | ||
attribute :sha1_fingerprint | ||
attribute :created_at | ||
attribute :private_key | ||
attribute :leaf_certificate | ||
attribute :certificate_chain | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module DropletKit | ||
class ForwardingRule < BaseModel | ||
attribute :entry_protocol | ||
attribute :entry_port | ||
attribute :target_protocol | ||
attribute :target_port | ||
attribute :certificate_id | ||
attribute :tls_passthrough | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module DropletKit | ||
class HealthCheck < BaseModel | ||
attribute :protocol | ||
attribute :port | ||
attribute :path | ||
attribute :check_interval_seconds | ||
attribute :response_timeout_seconds | ||
attribute :healthy_threshold | ||
attribute :unhealthy_threshold | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module DropletKit | ||
class LoadBalancer < BaseModel | ||
attribute :id | ||
attribute :ip | ||
attribute :name | ||
attribute :algorithm | ||
attribute :status | ||
attribute :created_at | ||
attribute :tag | ||
attribute :region | ||
attribute :redirect_http_to_https | ||
attribute :droplet_ids | ||
attribute :sticky_sessions | ||
attribute :health_check | ||
attribute :forwarding_rules | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module DropletKit | ||
class StickySession < BaseModel | ||
attribute :type | ||
attribute :cookie_name | ||
attribute :cookie_ttl_seconds | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module DropletKit | ||
class CertificateResource < ResourceKit::Resource | ||
include ErrorHandlingResourcable | ||
|
||
resources do | ||
action :find, 'GET /v2/certificates/:id' do | ||
handler(200) { |response| CertificateMapping.extract_single(response.body, :read) } | ||
end | ||
|
||
action :all, 'GET /v2/certificates' do | ||
query_keys :per_page, :page | ||
handler(200) { |response| CertificateMapping.extract_collection(response.body, :read) } | ||
end | ||
|
||
action :create, 'POST /v2/certificates' do | ||
body { |certificate| CertificateMapping.representation_for(:create, certificate) } | ||
handler(201) { |response| CertificateMapping.extract_single(response.body, :read) } | ||
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) } | ||
end | ||
|
||
action :delete, 'DELETE /v2/certificates/:id' do | ||
handler(204) { |_| true } | ||
end | ||
end | ||
|
||
def all(*args) | ||
PaginatedResource.new(action(:all), self, *args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module DropletKit | ||
class LoadBalancerResource < ResourceKit::Resource | ||
include ErrorHandlingResourcable | ||
|
||
resources do | ||
action :find, 'GET /v2/load_balancers/:id' do | ||
handler(200) { |response| LoadBalancerMapping.extract_single(response.body, :read) } | ||
end | ||
|
||
action :all, 'GET /v2/load_balancers' do | ||
query_keys :per_page, :page | ||
handler(200) { |response| LoadBalancerMapping.extract_collection(response.body, :read) } | ||
end | ||
|
||
action :create, 'POST /v2/load_balancers' do | ||
body { |load_balancer| LoadBalancerMapping.representation_for(:create, load_balancer) } | ||
handler(202) { |response| LoadBalancerMapping.extract_single(response.body, :read) } | ||
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) } | ||
end | ||
|
||
action :update, 'PUT /v2/load_balancers/:id' do | ||
body {|load_balancer| LoadBalancerMapping.representation_for(:update, load_balancer) } | ||
handler(200) { |response| LoadBalancerMapping.extract_single(response.body, :read) } | ||
handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) } | ||
end | ||
|
||
action :delete, 'DELETE /v2/load_balancers/:id' do | ||
handler(204) { |_| true } | ||
end | ||
|
||
action :add_droplets, 'POST /v2/load_balancers/:id/droplets' do | ||
body { |droplet_ids| { droplet_ids: droplet_ids }.to_json } | ||
handler(204) { |_| true } | ||
end | ||
|
||
action :remove_droplets, 'DELETE /v2/load_balancers/:id/droplets' do | ||
body { |droplet_ids| { droplet_ids: droplet_ids }.to_json } | ||
handler(204) { |_| true } | ||
end | ||
|
||
action :add_forwarding_rules, 'POST /v2/load_balancers/:id/forwarding_rules' do | ||
body { |forwarding_rules| ForwardingRuleMapping.represent_collection_for(:create, forwarding_rules) } | ||
handler(204) { |_| true } | ||
end | ||
|
||
action :remove_forwarding_rules, 'DELETE /v2/load_balancers/:id/forwarding_rules' do | ||
body { |forwarding_rules| ForwardingRuleMapping.represent_collection_for(:update, forwarding_rules) } | ||
handler(204) { |_| true } | ||
end | ||
end | ||
|
||
def all(*args) | ||
PaginatedResource.new(action(:all), self, *args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"certificates": [ | ||
{ | ||
"id": "892071a0-bb95-49bc-8021-3afd67a210bf", | ||
"name": "web-cert-01", | ||
"not_after": "2017-02-22T00:23:00Z", | ||
"sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7", | ||
"created_at": "2017-02-08T16:02:37Z" | ||
} | ||
], | ||
"links": { | ||
}, | ||
"meta": { | ||
"total": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"certificate": { | ||
"id": "892071a0-bb95-49bc-8021-3afd67a210bf", | ||
"name": "web-cert-01", | ||
"not_after": "2017-02-22T00:23:00Z", | ||
"sha1_fingerprint": "dfcc9f57d86bf58e321c2c6c31c7a971be244ac7", | ||
"created_at": "2017-02-08T16:02:37Z" | ||
} | ||
} |
Oops, something went wrong.