Skip to content

Commit

Permalink
Merge 7532049 into d3b5025
Browse files Browse the repository at this point in the history
  • Loading branch information
dldinternet committed Apr 1, 2017
2 parents d3b5025 + 7532049 commit 41fde11
Show file tree
Hide file tree
Showing 43 changed files with 1,675 additions and 31 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*.sw?
.rbenv
.rvmrc
.ruby-gemset
.ruby-version

# https://github.com/fog/fog/wiki/Create-New-Provider-from-Scratch
#.ruby-gemset
#.ruby-version

.bundle
.DS_Store
.idea
Expand All @@ -28,3 +31,4 @@ tags
tests/digitalocean/fixtures/

providers/*/doc
.rakeTasks
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fog-digitalocean
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.3.1
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ language: ruby

sudo: false

script: bundle exec rake test
script:
|
bundle config disable_exec_load true
bundle exec rake test

cache: bundler

rvm:
- 2.0
- 2.1
- 2.2
- jruby-head
# Unable to make these work right now [2017-03-25 Christo]
- 2.3.1
- 2.4.0

gemfile:
- Gemfile
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ New contributors are always welcome, when it doubt please ask questions. We stri
### Coding

* Pick a task:
* Offer feedback on open [pull requests](https://github.com/fog/fog/pulls).
* Review open [issues](https://github.com/fog/fog/issues) for things to help on.
* [Create an issue](https://github.com/fog/fog/issues/new) to start a discussion on additions or features.
* Offer feedback on open [pull requests](https://github.com/fog/fog-digitalocean/pulls).
* Review open [issues](https://github.com/fog/fog-digitalocean/issues) for things to help on.
* [Create an issue](https://github.com/fog/fog-digitalocean/issues/new) to start a discussion on additions or features.
* Fork the project, add your changes and tests to cover them in a topic branch.
* Commit your changes and rebase against `fog/fog` to ensure everything is up to date.
* [Submit a pull request](https://github.com/fog/fog/compare/)
* Commit your changes and rebase against `fog/fog-digitalocean` to ensure everything is up to date.
* [Submit a pull request](https://github.com/fog/fog-digitalocean/compare/)

### Non-Coding

* Offer feedback on open [issues](https://github.com/fog/fog/issues).
* Offer feedback on open [issues](https://github.com/fog/fog-digitalocean/issues).
* Write and help edit [documentation](https://github.com/fog/fog.github.com).
* Translate [documentation](https://github.com/fog/fog.github.com) in to other languages.
* Organize or volunteer at events.
Expand Down
10 changes: 8 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
source "https://rubygems.org"
source "https://rubygems.org" do

gem "coveralls", require: false
group :development, :test, :integration do
gem 'coveralls', require: false
gem 'term-ansicolor', require: false
gem 'zonefile', '>= 1.0.4', require: false
end

end

gemspec
2 changes: 2 additions & 0 deletions fog-digitalocean.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Gem::Specification.new do |s|
s.add_dependency 'fog-json', '>= 1.0'
s.add_dependency 'fog-xml', '>= 0.1'
s.add_dependency 'ipaddress', '>= 0.5'
s.add_dependency 'activesupport', '~> 4.2'
s.add_dependency 'zonefile', '>= 1.04'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/Gemfile-edge
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ gem "fog-json", :github => "fog/fog-json"

group :development, :test do
# This is here because gemspec doesn"t support require: false
gem "coveralls", :require => false
gem "coveralls", require: false
gem "term-ansicolor", require: false
gem "netrc", :require => false
gem "octokit", :require => false
end
Expand Down
1 change: 1 addition & 0 deletions lib/fog/digitalocean.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'fog/digitalocean/compute'
require 'fog/digitalocean/dns'
9 changes: 7 additions & 2 deletions lib/fog/digitalocean/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ def request(params)
response = @connection.request(params)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
NotFound.slurp(error)
when Excon::Errors::NotFound
klasa = self.class.name.split('::')
klasa[-1] = 'NotFound'
klass = klasa.inject(Object) { |mod, class_name|
mod.const_get(class_name)
}
klass.slurp(error)
else
error
end
Expand Down
1 change: 1 addition & 0 deletions lib/fog/digitalocean/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module Fog
module DigitalOcean
extend Fog::Provider
service(:compute, 'Compute')
service(:dns, 'DNS')
end
end
204 changes: 204 additions & 0 deletions lib/fog/digitalocean/dns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
require 'fog/digitalocean/core'
require 'active_support/core_ext/hash/indifferent_access'

module Fog
module DNS
class DigitalOcean < Fog::Service
requires :digitalocean_token

model_path 'fog/digitalocean/models/dns'
model :domain
collection :domains
model :record
collection :records

request_path 'fog/digitalocean/requests/dns'
request :list_domains
request :create_domain
request :get_domain
request :delete_domain

request :list_records
request :create_record
request :get_record
request :update_record
request :delete_record

class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:domains => [
{
"name" => "domain.com",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.com.\n$TTL 1800\ndomain.com. IN SOA ns1.digitalocean.com. hostmaster.domain.com. 1490145863 10800 3600 604800 1800\ndomain.com. 1800 IN NS ns1.digitalocean.com.\ndomain.com. 1800 IN NS ns2.digitalocean.com.\ndomain.com. 1800 IN NS ns3.digitalocean.com.\ndomain.com. 1800 IN A 127.0.0.3\n"
},
{
"name" => "domain.net",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.net.\n$TTL 1800\ndomain.net. IN SOA ns1.digitalocean.com. hostmaster.domain.net. 1488909707 10800 3600 604800 1800\ndomain.net. 1800 IN NS ns1.digitalocean.com.\ndomain.net. 1800 IN NS ns2.digitalocean.com.\ndomain.net. 1800 IN NS ns3.digitalocean.com.\ndomain.net. 1800 IN A 64.99.64.37\n"
},
{
"name" => "domain.org",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.org.\n$TTL 1800\ndomain.org. IN SOA ns1.digitalocean.com. hostmaster.domain.org. 1488395060 10800 3600 604800 1800\ndomain.org. 1800 IN NS ns1.digitalocean.com.\ndomain.org. 1800 IN NS ns2.digitalocean.com.\ndomain.org. 1800 IN NS ns3.digitalocean.com.\ndomain.org. 3600 IN A 208.38.128.210\ndomain.org. 1800 IN MX 1 aspmx.l.google.com.\ndomain.org. 1800 IN MX 5 alt1.aspmx.l.google.com.\ndomain.org. 1800 IN MX 5 alt2.aspmx.l.google.com.\ndomain.org. 1800 IN MX 10 alt3.aspmx.l.google.com.\ndomain.org. 1800 IN MX 10 alt4.aspmx.l.google.com.\n"
}
],
:domain_records => {
'domain.com' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
'domain.net' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
'domain.org' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
}
}
end
end

def initialize(options={})
@digitalocean_token = options[:digitalocean_token]
end

def data
self.class.data[@digitalocean_token]
end

def reset_data
self.class.data.delete(@digitalocean_token)
end
end

class Real < Fog::Compute::DigitalOcean::Real
# def initialize(options={})
# digitalocean_token = options[:digitalocean_token]
# persistent = false
# options = {
# headers: {
# 'Authorization' => "Bearer #{digitalocean_token}",
# }
# }
# @connection = Fog::Core::Connection.new 'https://api.digitalocean.com', persistent, options
# end
#
# def request(params)
# params[:headers] ||= {}
# begin
# response = @connection.request(params)
# rescue Excon::Errors::HTTPStatusError => error
# raise case error
# when Excon::Errors::NotFound
# NotFound.slurp(error)
# else
# error
# end
# end
# unless response.body.empty?
# response.body = Fog::JSON.decode(response.body)
# end
# response
# end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/fog/digitalocean/models/compute/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Images < Fog::Compute::DigitalOcean::PagingCollection
# @see https://developers.digitalocean.com/documentation/v2/#list-all-images
def all(filters = {})
data = service.list_images(filters)
links = data.body["links"]
links = data.body['meta']['links']
get_paged_links(links)
images = data.body["images"]
load(images)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/digitalocean/models/compute/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Servers < Fog::Compute::DigitalOcean::PagingCollection
# @see https://developers.digitalocean.com/documentation/v2/#droplets
def all(filters = {})
data = service.list_servers(filters)
links = data.body["links"]
links = data.body['meta']['links']
get_paged_links(links)
droplets = data.body["droplets"]
load(droplets)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/digitalocean/models/compute/ssh_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SshKeys < Fog::Compute::DigitalOcean::PagingCollection
# @see https://developers.digitalocean.com/documentation/v2/#list-all-keys
def all(filters = {})
data = service.list_ssh_keys(filters)
links = data.body["links"]
links = data.body['meta']['links']
get_paged_links(links)
keys = data.body["ssh_keys"]
load(keys)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/digitalocean/models/compute/volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Volumes < Fog::Compute::DigitalOcean::PagingCollection
# @see https://developers.digitalocean.com/documentation/v2/#list-all-images
def all(filters = {})
data = service.list_volumes(filters)
links = data.body["links"]
links = data.body['meta']['links']
get_paged_links(links)
volumes = data.body["volumes"]
load(volumes)
Expand Down

0 comments on commit 41fde11

Please sign in to comment.