-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have most of the Models and Requests in place.
- Loading branch information
1 parent
2ef2e68
commit 764ea1f
Showing
16 changed files
with
607 additions
and
5 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 |
---|---|---|
@@ -1 +1 @@ | ||
ruby-2.2.5 | ||
ruby-2.3.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
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,28 @@ | ||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
class Domain < Fog::Model | ||
identity :name | ||
attribute :ttl | ||
attribute :zone_file | ||
# attribute :ip_address | ||
|
||
def create | ||
requires :name, :ip_address | ||
merge_attributes(service.create_domain(name, ip_address).body['name']) | ||
true | ||
end | ||
|
||
def delete | ||
requires :name | ||
service.delete_domain name | ||
end | ||
|
||
def get | ||
requires :name | ||
service.get_domain name | ||
end | ||
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,40 @@ | ||
require 'fog/digitalocean/models/paging_collection' | ||
|
||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
class Domains < Fog::Compute::DigitalOcean::PagingCollection | ||
model Fog::DNS::DigitalOcean::Domain | ||
|
||
# Returns list of domains | ||
# @return [Fog::DNS::DigitalOceanV2::Domains] Retrieves a list of ssh keys. | ||
# @raise [Fog::DNS::DigitalOceanV2::NotFound] - HTTP 404 | ||
# @raise [Fog::DNS::DigitalOceanV2::BadRequest] - HTTP 400 | ||
# @raise [Fog::DNS::DigitalOceanV2::InternalServerError] - HTTP 500 | ||
# @raise [Fog::DNS::DigitalOceanV2::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-keys | ||
def all(filters = {}) | ||
data = service.list_domains(filters) | ||
links = data.body["links"] | ||
get_paged_links(links) | ||
keys = data.body["domains"] | ||
load(keys) | ||
end | ||
|
||
# Returns domain | ||
# @return [Fog::DNS::DigitalOceanV2::Domains] Retrieves a list of ssh keys. | ||
# @raise [Fog::DNS::DigitalOceanV2::NotFound] - HTTP 404 | ||
# @raise [Fog::DNS::DigitalOceanV2::BadRequest] - HTTP 400 | ||
# @raise [Fog::DNS::DigitalOceanV2::InternalServerError] - HTTP 500 | ||
# @raise [Fog::DNS::DigitalOceanV2::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-key | ||
def get(id) | ||
key = service.get_domain(id).body['name'] | ||
new(key) if key | ||
rescue Fog::Errors::NotFound | ||
nil | ||
end | ||
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,32 @@ | ||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
class Record < Fog::Model | ||
identity :id # number A unique identifier for each domain record. | ||
attribute :type # string The type of the DNS record (ex: A, CNAME, TXT, ...). | ||
attribute :name # string The name to use for the DNS record. | ||
attribute :data # string The value to use for the DNS record. | ||
attribute :priority # nullable number The priority for SRV and MX records. | ||
attribute :port # nullable number The port for SRV records. | ||
attribute :weight # nullable number The weight for SRV records. | ||
|
||
def create | ||
requires :name, :type, :data | ||
merge_attributes(service.create_domain_record(name, type, data).body['id']) | ||
true | ||
end | ||
|
||
def delete | ||
requires :id | ||
service.delete_domain_record name | ||
end | ||
|
||
def update | ||
requires :id, :name, :type, :data | ||
service.create_domain_record name, type, data | ||
service.delete_domain_record id | ||
end | ||
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,40 @@ | ||
require 'fog/digitalocean/models/paging_collection' | ||
|
||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
class Records < Fog::Compute::DigitalOcean::PagingCollection | ||
model Fog::DNS::DigitalOcean::Record | ||
|
||
# Returns list of records | ||
# @return [Fog::DNS::DigitalOceanV2::Records] Retrieves a list of domains. | ||
# @raise [Fog::DNS::DigitalOceanV2::NotFound] - HTTP 404 | ||
# @raise [Fog::DNS::DigitalOceanV2::BadRequest] - HTTP 400 | ||
# @raise [Fog::DNS::DigitalOceanV2::InternalServerError] - HTTP 500 | ||
# @raise [Fog::DNS::DigitalOceanV2::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-keys | ||
def all(filters = {}) | ||
data = service.list_domain_records(filters) | ||
links = data.body["links"] | ||
get_paged_links(links) | ||
keys = data.body["records"] | ||
load(keys) | ||
end | ||
|
||
# Returns record | ||
# @return [Fog::DNS::DigitalOceanV2::Records] Retrieves a list of records | ||
# @raise [Fog::DNS::DigitalOceanV2::NotFound] - HTTP 404 | ||
# @raise [Fog::DNS::DigitalOceanV2::BadRequest] - HTTP 400 | ||
# @raise [Fog::DNS::DigitalOceanV2::InternalServerError] - HTTP 500 | ||
# @raise [Fog::DNS::DigitalOceanV2::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-key | ||
def get(id) | ||
key = service.get_domain(id).body['id'] | ||
new(key) if key | ||
rescue Fog::Errors::NotFound | ||
nil | ||
end | ||
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,42 @@ | ||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
# noinspection RubyStringKeysInHashInspection | ||
class Real | ||
|
||
def create_domain(name, ip_address) | ||
create_options = { | ||
:name => name, | ||
:ip_address => ip_address, | ||
} | ||
|
||
encoded_body = Fog::JSON.encode(create_options) | ||
|
||
request( | ||
:expects => [201], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'POST', | ||
:path => '/v2/domains', | ||
:body => encoded_body, | ||
) | ||
end | ||
end | ||
|
||
# noinspection RubyStringKeysInHashInspection | ||
class Mock | ||
def create_domain(name, ip_address) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
|
||
response.body ={ | ||
'domain' => data[:domains].last | ||
} | ||
|
||
response | ||
end | ||
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,44 @@ | ||
module Fog | ||
module DNS | ||
class DigitalOcean | ||
# noinspection RubyStringKeysInHashInspection | ||
class Real | ||
|
||
def create_record(name, rec={}) | ||
create_options = { | ||
:type => rec[:type], | ||
} | ||
%w(name data priority port weight).each do |fld| | ||
create_options[fld.to_sym] = rec[fld.to_sym] if rec[fld.to_sym] | ||
end | ||
|
||
encoded_body = Fog::JSON.encode(create_options) | ||
|
||
request( | ||
:expects => [201], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'POST', | ||
:path => "/v2/domains/#{name}/records", | ||
:body => encoded_body, | ||
) | ||
end | ||
end | ||
|
||
# noinspection RubyStringKeysInHashInspection | ||
class Mock | ||
def create_record(name, rec={}) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
|
||
response.body = { | ||
"domain_record" => data[:domain_records][name].last | ||
} | ||
|
||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.