fog-dnsimple 0.0.1 → 1.0.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: dcf65e13872990212aa464afd0e7b722ac833e1f
4
- data.tar.gz: d4231b7ca89911e60c350aa5d1e423c3b987d051
3
+ metadata.gz: 0354086ffbb0b1f2866f487a18268ba11eb6be51
4
+ data.tar.gz: ccfcba77bec25c5a529c1f0458fd324e7ada83dc
5
5
  SHA512:
6
- metadata.gz: 7bc69069676be810e0300ab1f921a765a62c24d96e473cee7c1af5cd794326dceb112364381df5e4be8f9e6f128abf2cb3e4af06b1f0e419772f97d741ff92c5
7
- data.tar.gz: c79c093383b298e0485d890c1be103023939c9a7b1e9bcec9d797a9687c9d46fc57f7938420af9afd8f94a7efd8a91bb325527c124af664d9263e263a5f7c7a0
6
+ metadata.gz: 7ef2487be043841076620e863a78c8553f658710b315b1fed129cdf67b28460998fb0016d89a8def934f3727ceae2a8819aeb014ac02d9f242d1b7a37072be7c
7
+ data.tar.gz: 48ff4ad4dc4d169df5d2527d98a0e1d85b8111cda50351c6e0a8ad3db7d93ca5c480ca9fbb4035f77787fd28ba66951ce5c1064784b6b79d500953a734a1bb16
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ fog-dnsimple
data/.travis.yml CHANGED
@@ -1,5 +1,18 @@
1
- sudo: false
2
1
  language: ruby
2
+
3
3
  rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
4
7
  - 2.3.1
5
- before_install: gem install bundler -v 1.12.5
8
+ - ruby-head
9
+ - jruby9k
10
+ - jruby-head
11
+
12
+ before_install:
13
+ - gem install bundler
14
+
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: jruby-head
18
+ - rvm: jruby9k
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ #### Release 1.0
4
+
5
+ Initial version, extracted from `fog`.
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-2016 Aetrion LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Fog::Dnsimple
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fog/dnsimple`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/fog/fog-dnsimple.svg?branch=master)](https://travis-ci.org/fog/fog-dnsimple)
4
+
5
+
6
+ ## API Version
7
+
8
+ This library currently uses the [DNSimple API v1](https://developer.dnsimple.com/v1/)
9
+ and it is fully compatible with the legacy implementation bundled with the `fog` gem.
10
+
11
+ In other words, this is a drop-in replacement. Please note that the `dnsimple` provider
12
+ will eventually be removed from the `fog` gem in favor of this fog-specific module.
4
13
 
5
- TODO: Delete this and the text above, and describe your gem
6
14
 
7
15
  ## Installation
8
16
 
@@ -20,22 +28,57 @@ Or install it yourself as:
20
28
 
21
29
  $ gem install fog-dnsimple
22
30
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
31
 
27
- ## Development
32
+ ## Usage
28
33
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+ Initialize a `Fog::DNS` object using the DNSimple provider.
30
35
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+ ```ruby
37
+ dns = Fog::DNS.new({
38
+ provider: "DNSimple",
39
+ dnsimple_email: "YOUR_EMAIL",
40
+ dnsimple_token: "YOUR_API_V1_TOKEN",
41
+ })
42
+ ```
32
43
 
33
- ## Contributing
44
+ This can then be used like other [Fog DNS](http://fog.io/dns/) providers.
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-dnsimple. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+ ```ruby
47
+ zone = dns.zones.create(
48
+ domain: "example.com
49
+ )
50
+ record = zone.records.create(
51
+ name: "example.com,
52
+ value: "1.2.3.4,
53
+ type: "A"
54
+ )
55
+ ```
36
56
 
57
+ The following configurations are supported:
37
58
 
38
- ## License
59
+ ```ruby
60
+ dns = Fog::DNS.new({
61
+ # Use dnsimple_url to provide a different base URL, e.g. the Sandbox URL
62
+ dnsimple_url: "https://api.sandbox.dnsimple.com/",
63
+
64
+ # API v1 token-based authentication
65
+ dnsimple_email: "...",
66
+ dnsimple_token: "...",
67
+
68
+ # API v1 basic-auth
69
+ dnsimple_email: "...",
70
+ dnsimple_password: "...",
71
+
72
+ # API v1 domain-token authentication
73
+ dnsimple_domain: "example.com",
74
+ dnsimple_token: "...",
75
+ })
76
+ ```
39
77
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+ ## Contributing
41
79
 
80
+ 1. Fork it ( https://github.com/fog/fog-dnsimple/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,3 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
2
3
 
3
4
  task :default => :test
5
+
6
+ mock = ENV['FOG_MOCK'] || 'true'
7
+ task :test do
8
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
9
+ end
data/fog-dnsimple.gemspec CHANGED
@@ -10,11 +10,19 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["weppos@weppos.net"]
11
11
 
12
12
  spec.summary = %q{Module for the 'fog' gem to support DNSimple.}
13
- spec.description = %q{This is currently a stub. The full gem will be released soon.}
13
+ spec.description = %q{This library can be used as a module for `fog` or as standalone provider
14
+ to use the DNSimple in applications.}
14
15
  spec.homepage = "https://github.com/fog/fog-dnsimple"
15
16
  spec.license = "MIT"
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
20
  spec.require_paths = ["lib"]
20
- end
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "shindo", "~> 0.3"
25
+
26
+ spec.add_dependency 'fog-core', '~> 1.38'
27
+ spec.add_dependency 'fog-json', '~> 1.0'
28
+ end
@@ -0,0 +1,28 @@
1
+ class Dnsimple < Fog::Bin
2
+ class << self
3
+ def class_for(key)
4
+ case key
5
+ when :dns
6
+ Fog::DNS::Dnsimple
7
+ else
8
+ raise ArgumentError, "Unrecognized service: #{key}"
9
+ end
10
+ end
11
+
12
+ def [](service)
13
+ @@connections ||= Hash.new do |hash, key|
14
+ hash[key] = case key
15
+ when :dns
16
+ Fog::DNS.new(:provider => 'Dnsimple')
17
+ else
18
+ raise ArgumentError, "Unrecognized service: #{key.inspect}"
19
+ end
20
+ end
21
+ @@connections[service]
22
+ end
23
+
24
+ def services
25
+ Fog::Dnsimple.services
26
+ end
27
+ end
28
+ end
data/lib/fog/dnsimple.rb CHANGED
@@ -1,7 +1,14 @@
1
- require "fog/dnsimple/version"
1
+ require "fog/core"
2
+ require_relative "dnsimple/version"
2
3
 
3
4
  module Fog
4
5
  module Dnsimple
5
- # Your code goes here...
6
+ extend Fog::Provider
7
+
8
+ service(:dns, 'DNS')
9
+ end
10
+
11
+ module DNS
12
+ autoload :Dnsimple, File.expand_path('../dnsimple/dns', __FILE__)
6
13
  end
7
14
  end
@@ -0,0 +1,118 @@
1
+ require "fog/core"
2
+ require "fog/json"
3
+
4
+ module Fog
5
+ module DNS
6
+ class Dnsimple < Fog::Service
7
+ recognizes :dnsimple_email, :dnsimple_password, :dnsimple_token, :dnsimple_domain, :dnsimple_url
8
+
9
+ model_path 'fog/dnsimple/models/dns'
10
+ model :record
11
+ collection :records
12
+ model :zone
13
+ collection :zones
14
+
15
+ request_path 'fog/dnsimple/requests/dns'
16
+ request :list_domains
17
+ request :create_domain
18
+ request :get_domain
19
+ request :delete_domain
20
+ request :create_record
21
+ request :list_records
22
+ request :update_record
23
+ request :delete_record
24
+ request :get_record
25
+
26
+ class Mock
27
+ def self.data
28
+ @data ||= Hash.new do |hash, key|
29
+ hash[key] = {
30
+ :domains => [],
31
+ :records => {}
32
+ }
33
+ end
34
+ end
35
+
36
+ def self.reset
37
+ @data = nil
38
+ end
39
+
40
+ def initialize(options={})
41
+ @dnsimple_email = options[:dnsimple_email]
42
+ @dnsimple_password = options[:dnsimple_password]
43
+ @dnsimple_token = options[:dnsimple_token]
44
+ @dnsimple_domain = options[:dnsimple_domain]
45
+ end
46
+
47
+ def data
48
+ self.class.data[@dnsimple_email]
49
+ end
50
+
51
+ def reset_data
52
+ self.class.data.delete(@dnsimple_email)
53
+ end
54
+ end
55
+
56
+ class Real
57
+ def initialize(options={})
58
+ @dnsimple_email = options[:dnsimple_email]
59
+ @dnsimple_password = options[:dnsimple_password]
60
+ @dnsimple_token = options[:dnsimple_token]
61
+ @dnsimple_domain = options[:dnsimple_domain]
62
+
63
+ if options[:dnsimple_url]
64
+ uri = URI.parse(options[:dnsimple_url])
65
+ options[:host] = uri.host
66
+ options[:port] = uri.port
67
+ options[:scheme] = uri.scheme
68
+ end
69
+
70
+ connection_options = options[:connection_options] || {}
71
+ connection_options[:headers] ||= {}
72
+ connection_options[:headers]["User-Agent"] = "#{Fog::Core::Connection.user_agents} fog-dnsimple/#{Fog::Dnsimple::VERSION}"
73
+
74
+ host = options[:host] || "api.dnsimple.com"
75
+ persistent = options[:persistent] || false
76
+ port = options[:port] || 443
77
+ scheme = options[:scheme] || 'https'
78
+ @connection = Fog::Core::Connection.new("#{scheme}://#{host}:#{port}", persistent, connection_options)
79
+ end
80
+
81
+ def reload
82
+ @connection.reset
83
+ end
84
+
85
+ def request(params)
86
+ params[:headers] ||= {}
87
+
88
+ if(@dnsimple_password)
89
+ key = "#{@dnsimple_email}:#{@dnsimple_password}"
90
+ params[:headers].merge!("Authorization" => "Basic " + Base64.encode64(key).gsub("\n",''))
91
+ elsif(@dnsimple_token)
92
+ if(@dnsimple_domain)
93
+ params[:headers].merge!("X-DNSimple-Domain-Token" => @dnsimple_token)
94
+ else
95
+ params[:headers].merge!("X-DNSimple-Token" => "#{@dnsimple_email}:#{@dnsimple_token}")
96
+ end
97
+ else
98
+ raise ArgumentError.new("Insufficient credentials to properly authenticate!")
99
+ end
100
+ params[:headers].merge!(
101
+ "Accept" => "application/json",
102
+ "Content-Type" => "application/json"
103
+ )
104
+
105
+ version = params.delete(:version) || 'v1'
106
+ params[:path] = File.join('/', version, params[:path])
107
+
108
+ response = @connection.request(params)
109
+
110
+ unless response.body.empty?
111
+ response.body = Fog::JSON.decode(response.body)
112
+ end
113
+ response
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,59 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module DNS
5
+ class Dnsimple
6
+ class Record < Fog::Model
7
+ identity :id
8
+
9
+ attribute :zone_id, :aliases => "domain_id"
10
+ attribute :name
11
+ attribute :value, :aliases => "content"
12
+ attribute :ttl
13
+ attribute :priority, :aliases => "prio"
14
+ attribute :type, :aliases => "record_type"
15
+ attribute :created_at
16
+ attribute :updated_at
17
+
18
+ def initialize(attributes={})
19
+ super
20
+ end
21
+
22
+ def destroy
23
+ service.delete_record(zone.id, identity)
24
+ true
25
+ end
26
+
27
+ def zone
28
+ @zone
29
+ end
30
+
31
+ def save
32
+ requires :name, :type, :value
33
+ options = {}
34
+ options[:prio] = priority if priority
35
+ options[:ttl] = ttl if ttl
36
+
37
+ # decide whether its a new record or update of an existing
38
+ if id.nil?
39
+ data = service.create_record(zone.id, name, type, value, options)
40
+ else
41
+ options[:name] = name if name
42
+ options[:content] = value if value
43
+ options[:type] = type if type
44
+ data = service.update_record(zone.id, id, options)
45
+ end
46
+
47
+ merge_attributes(data.body["record"])
48
+ true
49
+ end
50
+
51
+ private
52
+
53
+ def zone=(new_zone)
54
+ @zone = new_zone
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/dnsimple/models/dns/record'
3
+
4
+ module Fog
5
+ module DNS
6
+ class Dnsimple
7
+ class Records < Fog::Collection
8
+ attribute :zone
9
+
10
+ model Fog::DNS::Dnsimple::Record
11
+
12
+ def all
13
+ requires :zone
14
+ clear
15
+ data = service.list_records(zone.id).body.map {|record| record['record']}
16
+ load(data)
17
+ end
18
+
19
+ def get(record_id)
20
+ requires :zone
21
+ data = service.get_record(zone.id, record_id).body["record"]
22
+ new(data)
23
+ rescue Excon::Errors::NotFound
24
+ nil
25
+ end
26
+
27
+ def new(attributes = {})
28
+ requires :zone
29
+ super({ :zone => zone }.merge!(attributes))
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end