pdns_api 0.0.4 → 0.0.5

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: e775769016b6af7782ddfa3baec55322b779ef01
4
- data.tar.gz: a782baf51327ab968e84dfb96d1460caf2623df1
3
+ metadata.gz: c1a4f09dcbfd236725e10397468a523a9b9a19d4
4
+ data.tar.gz: 4294fc6d7f39065d5c64bdfe902a290def36b48d
5
5
  SHA512:
6
- metadata.gz: e58156e4d03ee86e35cded0a95b35b6210d0c6af8294fc6618aaa818cf4cbe04df7b5e606aa2c9d0ba8b732c8a4e578d8adfc1ca1e1ed68ee563aae962c25696
7
- data.tar.gz: ddc4ba236a91245518f8bb751a62efdcaf3912167435b5da82b63d0c0ccc5fbe80b87d84d380219807d429fa95bc40102efee8d9024c6a8d76eb23b974ebb507
6
+ metadata.gz: 5ddabc8ebca91f59ddb30cded068d20aba62054266d1c6faf7d89781037bfef3064ba0d046085dd78daecfd085c5a5bbbdd9021e4ba0af590d2fbb06b1073b9f
7
+ data.tar.gz: d26e976a7a9e62d8225193d848894337afe5b39a5272b7e78e92bb175cab7ae86f3b79575c6839ba85e0369878d0da815dfc248d66548e6aa9bf9412a29304fd
data/lib/pdns_api/api.rb CHANGED
@@ -4,11 +4,14 @@ require 'pdns_api/http'
4
4
  module PDNS
5
5
  # Class for interacting with the API
6
6
  class API
7
+ attr_reader :url, :class, :version
8
+
7
9
  def initialize(args)
8
- @version = args.key?(:version) ? args[:version] : 1
10
+ @class = :client
9
11
  @http = PDNS::HTTP.new(args)
12
+ @version = @http.version
13
+ @parent = self
10
14
  @url = @http.uri
11
- @r_url = @url
12
15
  @info = {}
13
16
  end
14
17
 
@@ -27,7 +30,7 @@ module PDNS
27
30
  # Create this object on the server
28
31
  def create(info = nil)
29
32
  info(info)
30
- @http.post(@r_url, @info)
33
+ @http.post("#{@parent.url}/#{@class}", @info)
31
34
  end
32
35
 
33
36
  # Get/set info
@@ -10,11 +10,11 @@ module PDNS
10
10
 
11
11
  ## Main methods
12
12
  def servers(id = nil)
13
- return Server.new(@http, @url, id) unless id.nil?
13
+ return Server.new(@http, self, id) unless id.nil?
14
14
 
15
15
  # Return a hash of server objects
16
16
  servers = @http.get "#{@url}/servers"
17
- servers.map! { |s| [s[:id], Server.new(@url, s[:id], s)] }.to_h
17
+ servers.map! { |s| [s[:id], Server.new(@http, self, s[:id], s)] }.to_h
18
18
  end
19
19
 
20
20
  alias server servers
@@ -4,20 +4,22 @@ module PDNS
4
4
  class Config < API
5
5
  attr_accessor :name, :value
6
6
 
7
- def initialize(http, t_url, name, value = nil)
8
- @http = http
9
- @name = name
10
- @r_url = "#{t_url}/config"
11
- @url = "#{t_url}/config/#{name}"
12
- @value = value.get if value.nil?
13
- value(value)
7
+ def initialize(http, parent, name, value = nil)
8
+ @class = :config
9
+ @http = http
10
+ @parent = parent
11
+ @name = name
12
+ @url = "#{parent.url}/#{@class}/#{name}"
13
+ @value = value.get if value.nil?
14
+ value(@value)
14
15
  end
15
16
 
16
17
  ## Simple interfaces to metadata
17
18
  # Get/set config value
18
19
  def value(value = nil)
19
20
  return @info[:value] if value.nil?
20
- @info = { type: 'ConfigSetting', namen: @name, value: value }
21
+ @value = value
22
+ @info = { type: 'ConfigSetting', name: @name, value: value }
21
23
  end
22
24
 
23
25
  # Get configuration value
@@ -2,12 +2,13 @@
2
2
  module PDNS
3
3
  # Zone CryptoKey
4
4
  class CryptoKey < API
5
- def initialize(http, t_url, id, info = {})
6
- @http = http
7
- @id = id
8
- @info = info
9
- @r_url = "#{t_url}/metadata"
10
- @url = "#{t_url}/metadata/#{kind}"
5
+ def initialize(http, parent, id, info = {})
6
+ @class = :cryptokeys
7
+ @http = http
8
+ @parent = parent
9
+ @id = id
10
+ @info = info
11
+ @url = "#{parent.url}/#{@class}/#{id}"
11
12
  end
12
13
 
13
14
  ## Simple interfaces to metadata
data/lib/pdns_api/http.rb CHANGED
@@ -3,6 +3,7 @@ module PDNS
3
3
  # Class for doing HTTP requests
4
4
  class HTTP
5
5
  attr_accessor :headers
6
+ attr_reader :version
6
7
 
7
8
  def initialize(args)
8
9
  @host = args[:host]
@@ -2,12 +2,13 @@
2
2
  module PDNS
3
3
  # Zone Metadata
4
4
  class Metadata < API
5
- def initialize(http, t_url, kind, info = {})
6
- @http = http
7
- @kind = kind
8
- @info = info
9
- @r_url = "#{t_url}/metadata"
10
- @url = "#{t_url}/metadata/#{kind}"
5
+ def initialize(http, parent, kind, info = {})
6
+ @class = :metadata
7
+ @http = http
8
+ @parent = parent
9
+ @kind = kind
10
+ @info = info
11
+ @url = "#{parent.url}/metadata/#{kind}"
11
12
  end
12
13
 
13
14
  ## Simple interfaces to metadata
@@ -4,12 +4,13 @@ module PDNS
4
4
  class Override < API
5
5
  attr_reader :id, :url, :info
6
6
 
7
- def initialize(http, t_url, id, info = {})
8
- @http = http
9
- @id = id
10
- @info = info
11
- @r_url = "#{t_url}/metadata"
12
- @url = "#{t_url}/metadata/#{kind}"
7
+ def initialize(http, parent, id, info = {})
8
+ @class = :overrides
9
+ @http = http
10
+ @parent = parent
11
+ @id = id
12
+ @info = info
13
+ @url = "#{parent.url}/#{@class}/#{id}"
13
14
  end
14
15
 
15
16
  ## Simple interfaces to overrides
@@ -6,14 +6,15 @@ require 'pdns_api/zone'
6
6
  module PDNS
7
7
  # PDNS Server
8
8
  class Server < API
9
- attr_reader :id, :url
10
-
11
- def initialize(http, t_url, id, info = {})
12
- @http = http
13
- @id = id
14
- @r_url = "#{t_url}/servers"
15
- @url = "#{t_url}/servers/#{id}"
16
- @info = info
9
+ attr_reader :id
10
+
11
+ def initialize(http, parent, id, info = {})
12
+ @class = :servers
13
+ @http = http
14
+ @parent = parent
15
+ @id = id
16
+ @url = "#{parent.url}/#{@class}/#{id}"
17
+ @info = info
17
18
  end
18
19
 
19
20
  ## Server interfaces
@@ -45,8 +46,8 @@ module PDNS
45
46
 
46
47
  # Get or set server config
47
48
  def config(name = nil, value = nil)
48
- return Config.new(@http, @url, name, value).create unless name.nil? || value.nil?
49
- return Config.new(@http, @url, name) unless name.nil?
49
+ return Config.new(@http, self, name, value).create unless name.nil? || value.nil?
50
+ return Config.new(@http, self, name) unless name.nil?
50
51
 
51
52
  # Get all current configuration
52
53
  config = @http.get("#{@url}/config")
@@ -55,18 +56,18 @@ module PDNS
55
56
 
56
57
  # Get or set server overrides, not yet implemented
57
58
  def overrides(id = nil)
58
- return Override.new(@http, @url, id) unless id.nil?
59
+ return Override.new(@http, self, id) unless id.nil?
59
60
 
60
61
  overrides = @http.get("#{@url}/config")
61
- overrides.map { |o| [o[:id], Override.new(@http, @url, o[:id], o)] }.to_h
62
+ overrides.map { |o| [o[:id], Override.new(@http, self, o[:id], o)] }.to_h
62
63
  end
63
64
 
64
65
  # Get zones or create one
65
66
  def zones(zone_id = nil)
66
- return Zone.new(@http, @url, zone_id) unless zone_id.nil?
67
+ return Zone.new(@http, self, zone_id) unless zone_id.nil?
67
68
 
68
69
  zones = @http.get("#{@url}/zones")
69
- zones.map { |z| [z[:id], Zone.new(@http, @url, z[:id], z)] }.to_h
70
+ zones.map { |z| [z[:id], Zone.new(@http, self, z[:id], z)] }.to_h
70
71
  end
71
72
 
72
73
  alias override overrides
@@ -1,4 +1,4 @@
1
1
  # PDNS version
2
2
  module PDNS
3
- VERSION = '0.0.4'.freeze
3
+ VERSION = '0.0.5'.freeze
4
4
  end
data/lib/pdns_api/zone.rb CHANGED
@@ -5,14 +5,15 @@ module PDNS
5
5
 
6
6
  # Zone
7
7
  class Zone < API
8
- attr_reader :id, :url
9
-
10
- def initialize(http, t_url, id, info = {})
11
- @http = http
12
- @id = id
13
- @info = info
14
- @r_url = "#{t_url}/zones"
15
- @url = "#{t_url}/zones/#{id}"
8
+ attr_reader :id
9
+
10
+ def initialize(http, parent, id, info = {})
11
+ @class = :zones
12
+ @http = http
13
+ @parent = parent
14
+ @id = id
15
+ @info = info
16
+ @url = "#{parent.url}/#{@class}/#{id}"
16
17
  end
17
18
 
18
19
  ## Zone interfaces
@@ -55,8 +56,8 @@ module PDNS
55
56
 
56
57
  # Manipulate metadata for a zone
57
58
  def metadata(kind = nil, value = nil)
58
- return Metadata.new(@http, @url, kind, value).create unless kind.nil? || value.nil?
59
- return Metadata.new(@http, @url, kind) unless kind.nil?
59
+ return Metadata.new(@http, self, kind, value).create unless kind.nil? || value.nil?
60
+ return Metadata.new(@http, self, kind) unless kind.nil?
60
61
 
61
62
  # Get all current metadata
62
63
  metadata = @http.get("#{@url}/metadata")
@@ -70,13 +71,13 @@ module PDNS
70
71
 
71
72
  # Change cryptokeys for a zone
72
73
  def cryptokeys(id = nil)
73
- return CryptoKey.new(@http, @url, id) unless id.nil?
74
+ return CryptoKey.new(@http, self, id) unless id.nil?
74
75
 
75
76
  # Get all current metadata
76
77
  cryptokeys = @http.get("#{@url}/cryptokeys")
77
78
 
78
79
  # Convert cryptokeys to hash
79
- cryptokeys.map! { |c| [c[:id], CryptoKey.new(@http, @url, c[:id], c)] }.to_h
80
+ cryptokeys.map! { |c| [c[:id], CryptoKey.new(@http, self, c[:id], c)] }.to_h
80
81
  end
81
82
 
82
83
  ## Additional methods
@@ -108,7 +109,7 @@ module PDNS
108
109
  record[:disabled] ||= !!rrset[:disabled]
109
110
 
110
111
  # Return record
111
- next record unless @version == 0
112
+ next record unless @http.version == 0
112
113
 
113
114
  # But add some more for APIv0
114
115
  record.merge(name: rrset[:name], type: rrset[:type], ttl: rrset[:ttl])
@@ -126,7 +127,7 @@ module PDNS
126
127
  return data if data.key?(:error)
127
128
 
128
129
  # Run v0 version
129
- return add_v0(rrsets, data) if @version == 0
130
+ return add_v0(rrsets, data) if @http.version == 0
130
131
 
131
132
  # Add these records to the rrset
132
133
  rrsets.map! do |rrset|
@@ -178,7 +179,7 @@ module PDNS
178
179
  rrset[:changetype] = 'DELETE'
179
180
  rrset
180
181
  end
181
- apply(rrsets)
182
+ modify(rrsets)
182
183
  end
183
184
  end
184
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdns_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silke Hofstra