pdns-remotebackend 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
2
 
3
+ require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "yard"
6
+ require "yard/rake/yardoc_task"
5
7
 
6
8
  RSpec::Core::RakeTask.new
9
+ YARD::Rake::YardocTask.new
7
10
 
8
11
  task :default => :spec
9
12
  task :test => :spec
data/contrib/example.rb CHANGED
@@ -28,9 +28,9 @@ class RequestHandler < Pdns::Remotebackend::Handler
28
28
  def do_getdomainmetadata(args)
29
29
  if args["name"] == "example.com"
30
30
  if args["kind"] == "NSEC3NARROW"
31
- result = "1"
31
+ @result = "1"
32
32
  elsif args["kind"] == "NSEC3PARAM"
33
- result = "1 1 1 fe"
33
+ @result = "1 1 1 fe"
34
34
  end
35
35
  end
36
36
  end
@@ -40,7 +40,7 @@ class RequestHandler < Pdns::Remotebackend::Handler
40
40
  ## generate these
41
41
  def do_getdomainkeys(args)
42
42
  if args["name"] == "example.com"
43
- result = [
43
+ @result = [
44
44
  {
45
45
  "id" => 1,
46
46
  "flags" => 257,
@@ -81,26 +81,26 @@ Coefficient: 5lP9IFknvFgaXKCs8MproehHSFhFTWac4557HIn03KrnlGOKDcY6DC/vgu1e42bEZ4J
81
81
  ## and dynamic A record for anything else in example.com domain
82
82
  def do_lookup(args)
83
83
  if args["qname"] == "example.com" and args["qtype"].downcase == "soa"
84
- result = [
85
- record("SOA","example.com", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
84
+ @result = [
85
+ record("example.com", "SOA", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
86
86
  ]
87
87
  elsif args["qname"] == "example.com" and args["qtype"].downcase == "any"
88
- result = [
89
- record("SOA","example.com", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
90
- record("NS","example.com","sns.dns.icann.org"),
91
- record_prio("MX","example.com","test.example.com",10)
88
+ @result = [
89
+ record("SOA","example.com", "SOA", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
90
+ record("example.com", "NS", "sns.dns.icann.org"),
91
+ record_prio("example.com", "MX", "test.example.com",10)
92
92
  ]
93
93
  elsif args["qname"] == "test.example.com" and args["qtype"].downcase == "any"
94
- result = [
95
- record("A","test.example.com","127.0.0.1")
94
+ @result = [
95
+ record("test.example.com", "A", "127.0.0.1")
96
96
  ]
97
97
  elsif args["qname"] =~ /(.*)\.example\.com$/ and args["qtype"].downcase == "any"
98
98
  ip = 0
99
99
  $1.downcase.each_byte do |b| ip = ip + b end
100
100
  ip_2 = ip/256
101
101
  ip = ip%256
102
- result = [
103
- record("A",args["qname"], "127.0.#{ip_2}.#{ip}")
102
+ @result = [
103
+ record(args["qname"], "A", "127.0.#{ip_2}.#{ip}")
104
104
  ]
105
105
  end
106
106
  end
@@ -111,11 +111,11 @@ Coefficient: 5lP9IFknvFgaXKCs8MproehHSFhFTWac4557HIn03KrnlGOKDcY6DC/vgu1e42bEZ4J
111
111
  ## for sake of having an example. Do not do ths in production.
112
112
  def do_list(args)
113
113
  if args["zonename"] == "example.com"
114
- result = [
115
- record("SOA","example.com", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
116
- record("NS","example.com","sns.dns.icann.org"),
117
- record_prio("MX","example.com","test.example.com",10),
118
- record("A","test.example.com","127.0.0.1")
114
+ @result = [
115
+ record("example.com", "SOA", "sns.dns.icann.org noc.dns.icann.org 2013012485 7200 3600 1209600 3600"),
116
+ record("example.com", "NS", "sns.dns.icann.org"),
117
+ record_prio("example.com", "MX", "test.example.com",10),
118
+ record("test.example.com", "A", "127.0.0.1")
119
119
  ]
120
120
  end
121
121
  end
@@ -1,5 +1,5 @@
1
1
  module Pdns
2
2
  module Remotebackend
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -7,26 +7,51 @@ module Pdns
7
7
  class Handler
8
8
  attr_accessor :log, :result, :ttl
9
9
 
10
+ # Initialize with defaults values
10
11
  def initialize
11
12
  @log = []
12
13
  @result = false
13
14
  @ttl = 300
14
15
  @params = {}
15
16
  end
16
-
17
- def record_prio_ttl(qtype,qname,content,prio,ttl,auth=1)
17
+
18
+ # Generates a hash of resource record
19
+ #
20
+ # @param [String] qname name of record
21
+ # @param [String] qtype type of record
22
+ # @param [String] content record contents
23
+ # @param [Integer] prio Record priority
24
+ # @param [Integer] ttl Record TTL
25
+ # @param [Integer] auth Whether we are authoritative for the record or not
26
+ # @return [Hash] A resource record hash
27
+ def record_prio_ttl(qname,qtype,content,prio,ttl,auth=1)
18
28
  {:qtype => qtype, :qname => qname, :content => content, :priority => prio, :ttl => ttl, :auth => auth}
19
29
  end
20
30
 
21
- def record_prio(qtype,qname,content,prio,auth=1)
22
- record_prio_ttl(qtype,qname,content,prio,@ttl,auth)
31
+ # Generates a hash of resource record
32
+ #
33
+ # @param [String] qname name of record
34
+ # @param [String] qtype type of record
35
+ # @param [String] content record contents
36
+ # @param [Integer] prio Record priority
37
+ # @param [Integer] auth Whether we are authoritative for the record or not
38
+ # @return [Hash] A resource record hash
39
+ def record_prio(qname,qtype,content,prio,auth=1)
40
+ record_prio_ttl(qname,qtype,content,prio,@ttl,auth)
23
41
  end
24
42
 
25
- def record(qtype,qname,content,auth=1)
26
- record_prio_ttl(qtype,qname,content,0,@ttl,auth)
27
- end
28
-
29
- def do_initialize(args)
43
+ # Generates a hash of resource record
44
+ #
45
+ # @param [String] qname name of record
46
+ # @param [String] qtype type of record
47
+ # @param [String] content record contents
48
+ # @param [Integer] auth Whether we are authoritative for the record or not
49
+ # @return [Hash] A resource record hash
50
+ def record(qname,qtype,content,auth=1)
51
+ record_prio_ttl(qname,qtype,content,0,@ttl,auth)
52
+ end
53
+
54
+ def do_initialize(*args)
30
55
  @params = args
31
56
  @log << "PowerDNS ruby remotebackend version #{Pdns::Remotebackend::VERSION} initialized"
32
57
  @result = true
@@ -117,16 +142,13 @@ module Pdns
117
142
  @options = options
118
143
  end
119
144
 
120
- def open
121
- [STDIN,STDOUT]
122
- end
123
-
124
- def close
125
- end
126
-
127
- def mainloop
145
+ # Reads one line at a time from remotebackend, and calls approriate method
146
+ #
147
+ # @param [Socket] reader Socket to read from'
148
+ # @param [Socket] writer Socket to write to
149
+ protected
150
+ def mainloop(reader,writer)
128
151
  h = @handler.new
129
- reader,writer = self.open
130
152
 
131
153
  begin
132
154
  reader.each_line do |line|
@@ -137,17 +159,15 @@ module Pdns
137
159
  begin
138
160
  input = JSON.parse(line)
139
161
  method = "do_#{input["method"].downcase}"
140
- args = input["parameters"] || []
162
+ args = input["parameters"] || {}
141
163
 
142
164
  h.result = false
143
165
  h.log = []
144
-
166
+
145
167
  if h.respond_to?(method.to_sym) == false
146
168
  res = false
147
- elsif args.size > 0
148
- h.send(method,args)
149
169
  else
150
- h.send(method)
170
+ h.send(method,args)
151
171
  end
152
172
 
153
173
  writer.puts ({:result => h.result, :log => h.log}).to_json
@@ -158,27 +178,26 @@ module Pdns
158
178
  end
159
179
  rescue SystemExit, Interrupt
160
180
  end
161
- self.close
162
181
  end
163
182
  end
164
- end
165
183
 
166
- class Pipe
167
- def run
168
- mainloop
169
- end
170
- end
184
+ class Pipe < Connector
185
+ def run
186
+ mainloop STDIN,STDOUT
187
+ end
188
+ end
171
189
 
172
- class Unix
190
+ class Unix < Connector
173
191
  def run
174
192
  @path = options[:path] || "/tmp/remotebackend.sock"
175
193
  Socket.unix_server_loop(@path) do |sock, client_addrinfo|
176
- begin
177
- mainloop sock, sock
178
- ensure
179
- sock.close
180
- end
194
+ begin
195
+ mainloop sock, sock
196
+ ensure
197
+ sock.close
198
+ end
181
199
  end
182
200
  end
201
+ end
183
202
  end
184
203
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["cmouse@desteem.org"]
7
7
  gem.description = %q{This gem provides a base class and helpers for writing remotebackend servers for pipe/unix/. It is intended to make using remotebackend easier. For http support, see pdns-remotebackend-http.}
8
8
  gem.summary = %q{This gem provides a base class and helpers for writing remotebackend servers for pipe/unix/http post/json modes}
9
- gem.homepage = "http://github.com/cmouse/pdns-remotebackend"
9
+ gem.homepage = "http://github.com/cmouse/pdns-remotebackend-gem"
10
10
  gem.license = "MIT"
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -17,5 +17,8 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency 'rake'
19
19
  gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'yard'
21
+ gem.add_development_dependency 'redcarpet'
22
+
20
23
  gem.add_runtime_dependency 'json'
21
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdns-remotebackend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &6278620 !ruby/object:Gem::Requirement
16
+ requirement: &6907400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *6278620
24
+ version_requirements: *6907400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &6278200 !ruby/object:Gem::Requirement
27
+ requirement: &6906980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,32 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *6278200
35
+ version_requirements: *6906980
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &6906560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *6906560
47
+ - !ruby/object:Gem::Dependency
48
+ name: redcarpet
49
+ requirement: &6906140 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *6906140
36
58
  - !ruby/object:Gem::Dependency
37
59
  name: json
38
- requirement: &6277780 !ruby/object:Gem::Requirement
60
+ requirement: &6905720 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
63
  - - ! '>='
@@ -43,7 +65,7 @@ dependencies:
43
65
  version: '0'
44
66
  type: :runtime
45
67
  prerelease: false
46
- version_requirements: *6277780
68
+ version_requirements: *6905720
47
69
  description: This gem provides a base class and helpers for writing remotebackend
48
70
  servers for pipe/unix/. It is intended to make using remotebackend easier. For http
49
71
  support, see pdns-remotebackend-http.
@@ -64,7 +86,7 @@ files:
64
86
  - pdns-remotebackend.gemspec
65
87
  - spec/lib/pdns_remotebackend_spec.rb
66
88
  - spec/spec_helper.rb
67
- homepage: http://github.com/cmouse/pdns-remotebackend
89
+ homepage: http://github.com/cmouse/pdns-remotebackend-gem
68
90
  licenses:
69
91
  - MIT
70
92
  post_install_message:
@@ -93,3 +115,4 @@ summary: This gem provides a base class and helpers for writing remotebackend se
93
115
  test_files:
94
116
  - spec/lib/pdns_remotebackend_spec.rb
95
117
  - spec/spec_helper.rb
118
+ has_rdoc: