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 +4 -4
- data/lib/pdns_api/api.rb +6 -3
- data/lib/pdns_api/client.rb +2 -2
- data/lib/pdns_api/config.rb +10 -8
- data/lib/pdns_api/cryptokey.rb +7 -6
- data/lib/pdns_api/http.rb +1 -0
- data/lib/pdns_api/metadata.rb +7 -6
- data/lib/pdns_api/override.rb +7 -6
- data/lib/pdns_api/server.rb +15 -14
- data/lib/pdns_api/version.rb +1 -1
- data/lib/pdns_api/zone.rb +16 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1a4f09dcbfd236725e10397468a523a9b9a19d4
|
4
|
+
data.tar.gz: 4294fc6d7f39065d5c64bdfe902a290def36b48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
@
|
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(@
|
33
|
+
@http.post("#{@parent.url}/#{@class}", @info)
|
31
34
|
end
|
32
35
|
|
33
36
|
# Get/set info
|
data/lib/pdns_api/client.rb
CHANGED
@@ -10,11 +10,11 @@ module PDNS
|
|
10
10
|
|
11
11
|
## Main methods
|
12
12
|
def servers(id = nil)
|
13
|
-
return Server.new(@http,
|
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(@
|
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
|
data/lib/pdns_api/config.rb
CHANGED
@@ -4,20 +4,22 @@ module PDNS
|
|
4
4
|
class Config < API
|
5
5
|
attr_accessor :name, :value
|
6
6
|
|
7
|
-
def initialize(http,
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
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
|
-
@
|
21
|
+
@value = value
|
22
|
+
@info = { type: 'ConfigSetting', name: @name, value: value }
|
21
23
|
end
|
22
24
|
|
23
25
|
# Get configuration value
|
data/lib/pdns_api/cryptokey.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
module PDNS
|
3
3
|
# Zone CryptoKey
|
4
4
|
class CryptoKey < API
|
5
|
-
def initialize(http,
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
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
data/lib/pdns_api/metadata.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
module PDNS
|
3
3
|
# Zone Metadata
|
4
4
|
class Metadata < API
|
5
|
-
def initialize(http,
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
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
|
data/lib/pdns_api/override.rb
CHANGED
@@ -4,12 +4,13 @@ module PDNS
|
|
4
4
|
class Override < API
|
5
5
|
attr_reader :id, :url, :info
|
6
6
|
|
7
|
-
def initialize(http,
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
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
|
data/lib/pdns_api/server.rb
CHANGED
@@ -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
|
10
|
-
|
11
|
-
def initialize(http,
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
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,
|
49
|
-
return Config.new(@http,
|
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,
|
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,
|
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,
|
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,
|
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
|
data/lib/pdns_api/version.rb
CHANGED
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
|
9
|
-
|
10
|
-
def initialize(http,
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
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,
|
59
|
-
return Metadata.new(@http,
|
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,
|
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,
|
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
|
-
|
182
|
+
modify(rrsets)
|
182
183
|
end
|
183
184
|
end
|
184
185
|
end
|