Skip to content

Commit

Permalink
Drop Dependencies version constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Jun 22, 2018
1 parent 5650fda commit b9937ef
Show file tree
Hide file tree
Showing 33 changed files with 217 additions and 154 deletions.
24 changes: 24 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Style/Documentation:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/LineLength:
Max: 120

Metrics/BlockLength:
Enabled: false

Layout/ExtraSpacing:
AllowForAlignment: false
ForceEqualSignAlignment: false

Style/ExpandPathArguments:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fog-powerdns
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in fog-dns.gemspec
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

1. Fork it ( https://github.com/[my-github-username]/fog-powerdns/fork )
1. Fork it ( https://github.com/fog/fog-powerdns/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
18 changes: 10 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

def name
@name ||= Dir['*.gemspec'].first.split('.').first
require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs.push %w[spec]
t.test_files = FileList['spec/**/*_spec.rb']
t.verbose = true
end

desc "Open an irb session preloaded with this library"
task :console do
puts "#{name}"
sh "irb -rubygems -r ./lib/fog/powerdns.rb"
end
desc 'Default Task'
task default: [:test]
7 changes: 4 additions & 3 deletions bin/console
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "fog/powerdns"
require 'bundler/setup'
require 'fog/powerdns'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require "fog/powerdns"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start
38 changes: 20 additions & 18 deletions fog-powerdns.gemspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fog/powerdns/version'

Gem::Specification.new do |spec|
spec.name = "fog-powerdns"
spec.version = Fog::PowerDNS::VERSION
spec.authors = ["Chris Luo"]
spec.email = ["[email protected]"]
spec.name = 'fog-powerdns'
spec.version = Fog::PowerDNS::VERSION
spec.authors = ['Chris Luo']
spec.email = ['[email protected]']

spec.summary = %q{Module for the 'fog' gem to support PowerDNS DNS services.}
spec.description = %q{This library can be used as a module for 'fog' or as a standalone provider to use PowerDNS DNS services in applications.}
spec.homepage = "http://github.com/cluobah/fog-powerdns"
spec.license = "MIT"
spec.summary = "Module for the 'fog' gem to support PowerDNS DNS services."
spec.description = "This library can be used as a module for 'fog' or as a standalone provider to use PowerDNS DNS services in applications."
spec.homepage = 'http://github.com/cluobah/fog-powerdns'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency "bundler", "~> 1.8"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'

spec.add_dependency 'fog-core', '~> 1.27'
spec.add_dependency 'fog-json', '~>1.0'
spec.add_dependency 'fog-xml', '~>0.1'
spec.add_dependency 'fog-core'
spec.add_dependency 'fog-json'
spec.add_dependency 'fog-xml'
end
24 changes: 14 additions & 10 deletions lib/fog/bin/powerdns.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# frozen_string_literal: true

class PowerDNS < Fog::Bin
class << self
def class_for(key)
case key

when :dns
Fog::DNS::PowerDNS
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
when :dns
Fog::DNS::PowerDNS
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
end

def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :dns
Fog::Logger.warning("PowerDNS[:dns] is not recommended, use DNS[:powerdns] for portability")
Fog::DNS.new(:provider => :powerdns)
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
when :dns
Fog::Logger.warning('PowerDNS[:dns] is not recommended, use DNS[:powerdns] for portability')
Fog::DNS.new(provider: :powerdns)
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end
end
@@connections[service]
end

def services
Fog::PowerDNS.services
end
end
end
end
31 changes: 15 additions & 16 deletions lib/fog/dns/powerdns.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

module Fog
module DNS
class PowerDNS < Fog::Service
requires :pdns_api_key
recognizes :host, :port, :persistent, :scheme, :timeout

model_path 'fog/dns/powerdns/models'
model :zone
collection :zones
model :zone
collection :zones
# collection :rrsets

request_path 'fog/dns/powerdns/requests'
Expand All @@ -32,16 +34,15 @@ class Mock
end

class Real
def initialize(options={})

def initialize(options = {})
@pdns_api_key = options[:pdns_api_key]
@connection_options = options[:connection_options] || {}
@host = options[:host] || "127.0.0.1"
@persistent = options[:persistent]|| false
@port = options[:port] || 8081
@scheme = options[:scheme] || 'http'
@api_version= options[:api_version] || 'v1'
@host = options[:host] || '127.0.0.1'
@persistent = options[:persistent] || false
@port = options[:port] || 8081
@scheme = options[:scheme] || 'http'
@api_version = options[:api_version] || 'v1'

@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Expand All @@ -51,17 +52,15 @@ def reload

def request(params)
params[:headers] ||= {}
params[:headers].merge!("X-API-key" => "#{@pdns_api_key}")
params[:headers]['X-API-key'] = @pdns_api_key.to_s
params[:headers].merge!(
"Accept" => "application/json",
"Content-Type" => "application/json"
'Accept' => 'application/json',
'Content-Type' => 'application/json'
)

response = @connection.request(params)

unless response.body.empty?
response.body = Fog::JSON.decode(response.body)
end
response.body = Fog::JSON.decode(response.body) unless response.body.empty?
response
end
end
Expand Down
9 changes: 6 additions & 3 deletions lib/fog/dns/powerdns/models/record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'fog/core/model'

module Fog
Expand All @@ -13,19 +15,20 @@ class Record < Fog::Model
attribute :disabled
attribute :set_ptr

def initialize(attributes={})
def initialize(attributes = {})
super
end

def domain
name
end

def destroy
# service.delete_record(id)
# TODO: maybe hack our own delete? this does nothing for now
true
end

end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/fog/dns/powerdns/models/records.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'fog/core/collection'

module Fog
Expand All @@ -13,9 +15,7 @@ def all
data = service.get_zone(zone)[:records]
load(data)
end


end
end
end
end
end
15 changes: 7 additions & 8 deletions lib/fog/dns/powerdns/models/zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'fog/core/model'

module Fog
Expand All @@ -6,34 +8,31 @@ class PowerDNS
class Zone < Fog::Model
identity :zone_id

attribute :zone, :aliases => 'name'
attribute :zone, aliases: 'name'
attribute :server_id

def destroy
service.delete_zone(identity)
true
end


def records
# TODO: Should rewrite this
@records ||= begin
Fog::DNS::PowerDNS::Records.new(
:zone => self,
:service => service
zone: self,
service: service
)
end
end


def save
requires :zone
data = service.create_zone(zone).body["zone"]
data = service.create_zone(zone).body['zone']
merge_attributes(data)
true
end

end
end
end
end
end
5 changes: 3 additions & 2 deletions lib/fog/dns/powerdns/models/zones.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'fog/core/collection'
require 'fog/dns/powerdns/models/zone'

Expand All @@ -22,8 +24,7 @@ def get(zone)
rescue Fog::Service::NotFound
puts 'help!'
end

end
end
end
end
end
20 changes: 11 additions & 9 deletions lib/fog/dns/powerdns/requests/create_zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Fog
module DNS
class PowerDNS
Expand Down Expand Up @@ -38,19 +40,19 @@ class Real

def create_zone(server, name, nameservers, options = {})
body = {
"name" => name,
"nameservers" => nameservers
'name' => name,
'nameservers' => nameservers
}

options.each { |option, value|
body[option] = value;
}
options.each do |option, value|
body[option] = value
end

request(
:body => Fog::JSON.encode(body),
:expects => 201,
:method => 'POST',
:path => "/api/#{@api_version}/servers/#{server}/zones"
body: Fog::JSON.encode(body),
expects: 201,
method: 'POST',
path: "/api/#{@api_version}/servers/#{server}/zones"
).body
end
end
Expand Down
Loading

0 comments on commit b9937ef

Please sign in to comment.