knot-ruby 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d24b7dfed91ed556ec5c2ee1b6c765eb96879e2d7d5fdd4dfaf060e474f4c91
4
- data.tar.gz: 66c899d76cbd7ff9ea68d7f3f0fad98dc8bf21a1e136d156379f25ee42046ad1
3
+ metadata.gz: 102f6dc54dc3b034d4b71e890c921cdd3067ef32999cf92e829b56e6cf661266
4
+ data.tar.gz: 847a1e73410dd0dbe17793c7c2819e22879dfbe47f728ec0625e02b88dcb7c2a
5
5
  SHA512:
6
- metadata.gz: 5763ee24991d9d75ef48da2bb203acba69dc89dc4d982d35abd23980792f0649062ef4e58b8a9f5982a341cda9c20ac810873de1476d057c69cc733105fa5ecc
7
- data.tar.gz: b932a258e7340a0e3baa7a0a833868b6a5a9ae8eb6f5d1149601193238c1279abe3710d3dda9e1e5cc193ba74baa3fad61411ad34820b60fdffca52d6a7035f5
6
+ metadata.gz: e87bfff66910c223c3046dbc0ea63929d7c60d62434e06f1dccac5f2bca3ffc8b9e0652b32c1f4137ff6912cca50f26855dd989a64ec8f2a1c2f741f34307637
7
+ data.tar.gz: bcd68e1fa196ec799970697180b2dd375c6816da752c721dab9b0bf4bb82405d5909f090f5f10185713ee4c28166af0a64f103ff926ede60a519fc41a13a2e6a
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
+ ruby '>=2.7'
2
3
 
3
4
  # Specify your gem's dependencies in knot.gemspec
4
5
  gemspec
data/knot-ruby.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = %q{Provides interface to knot-server.}
11
11
  spec.description = %q{Implements knot-protocol to provide an interface to knot-DNS-server}
12
12
  spec.homepage = 'https://git.denkn.at/deac/knot'
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
14
 
15
15
  #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
16
 
@@ -69,7 +69,7 @@ class Knot::Zone
69
69
 
70
70
  def read() @protocol.call command: 'zone-read', zone: @zone end
71
71
  def diff() @protocol.call command: 'zone-diff', zone: @zone end
72
-
72
+
73
73
  # setting record
74
74
  # if data is nil, it will be unset.
75
75
  def set owner, ttl = nil, type, data
@@ -153,33 +153,36 @@ class Knot::Conf
153
153
 
154
154
  $~.named_captures.delete_if {|_,v| v.nil? }
155
155
 
156
+ when nil
157
+ {}
158
+
156
159
  else
157
160
  raise ArgumentError, "Invalid Item-format"
158
161
  end
159
162
  end
160
163
 
161
164
  def get item = nil
162
- @protocol.call (item ? parse_item( item) : {}).update( command: 'conf-get')
165
+ @protocol.call **parse_item( item).update( command: 'conf-get')
163
166
  end
164
167
 
165
168
  # Sets or adds a new value to item.
166
169
  # knot knows single-value items like `server.rundir` and multi-value items like `server.listen`.
167
170
  # If you set a single-value, it will replace the old value. On a multi-value, it will add it.
168
171
  def set item, value
169
- @protocol.call parse_item( item).update( command: 'conf-set', data: value)
172
+ @protocol.call **parse_item( item).update( command: 'conf-set', data: value)
170
173
  end
171
174
 
172
175
  # Removes value from item. If you provide a value, this value will be removed.
173
176
  def unset item, value = nil
174
- @protocol.call parse_item( item).update( command: 'conf-unset', data: value)
177
+ @protocol.call **parse_item( item).update( command: 'conf-unset', data: value)
175
178
  end
176
179
  alias delete unset
177
180
 
178
181
  def list item = nil
179
- @protocol.call (item ? parse_item( item) : {}).update( command: 'conf-list')
182
+ @protocol.call **parse_item( item).update( command: 'conf-list')
180
183
  end
181
184
 
182
185
  def read item = nil
183
- @protocol.call (item ? parse_item( item) : {}).update( command: 'conf-read')
186
+ @protocol.call **parse_item( item).update( command: 'conf-read')
184
187
  end
185
188
  end
data/lib/knot/protocol.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'iounpack'
2
+ require 'stringio'
2
3
  require_relative 'errors'
3
4
 
4
5
  module Knot
@@ -51,6 +52,26 @@ module Knot::Protocol::Type
51
52
  end
52
53
  end
53
54
 
55
+ #class Knot::KnotC
56
+ # attr_accessor :debug, :binary
57
+ #
58
+ # def initialize path = nil, binary: nil
59
+ # @path = path
60
+ # @binary = binary || 'knotc'
61
+ # @conf = Knot::Conf.new self
62
+ # @zones = Hash.new {|h, zone| h[zone] = Knot::Zone.new zone, self }
63
+ # end
64
+ #
65
+ # def call command:, flags: nil, section: nil, item: nil, id: nil, zone: nil, owner: nil, ttl: nil, type: nil, data: nil, filter: nil
66
+ # cs =
67
+ # case command.to_s
68
+ # when 'conf-begin', 'conf-commit', 'conf-abort', 'status', 'stop', 'reload'
69
+ # [@binary, command, ]
70
+ # else raise ArgumentError, "Unknown Command: #{command}"
71
+ # end
72
+ # end
73
+ #end
74
+
54
75
  module Knot::Protocol::Idx
55
76
  Idx = [
56
77
  :command, # 10, :CMD, # Control command name.
@@ -117,7 +138,7 @@ class Knot::Protocol
117
138
  STDERR.puts( {data: data, _: s}.inspect) if @debug
118
139
  rsock.write s
119
140
  rsock.flush
120
- end
141
+ end
121
142
 
122
143
  class RecordIO
123
144
  attr_reader :str
@@ -153,7 +174,7 @@ class Knot::Protocol
153
174
  when 1, 2
154
175
  type = t
155
176
  ret.push( r = {})
156
- else
177
+ else
157
178
  raise Knot::Errors::EINVAL, "Missing Type before: #{t}" if ret.empty?
158
179
  i = Idx::Idx[t - 0x10] or raise Knot::Errors::EINVAL, "Unknown index: #{t-0x10}"
159
180
  l = sock.unpack1 'n'
@@ -167,7 +188,7 @@ class Knot::Protocol
167
188
 
168
189
  def call sock: nil, **data
169
190
  snd sock: sock, **data
170
- rcv( sock: sock).each do |r|
191
+ rcv( sock: sock).each do |r|
171
192
  if r[:error]
172
193
  if e = Knot::Errors.err2exc[r[:error]]
173
194
  raise e, r[:error]
@@ -179,10 +200,10 @@ class Knot::Protocol
179
200
 
180
201
  def zone( zone) @zones[zone.to_s.to_sym] end
181
202
 
182
- def conf_set( **opts) call **opts.update( command: 'conf-set') end
183
- def conf_unset( **opts) call **opts.update( command: 'conf-set') end
203
+ def conf_set( **opts) call **opts.update( command: 'conf-set') end
204
+ def conf_unset( **opts) call **opts.update( command: 'conf-unset') end
184
205
 
185
- def zone_set( **opts) call **opts.update( command: 'zone-set') end
206
+ def zone_set( **opts) call **opts.update( command: 'zone-set') end
186
207
  def zone_unset( **opts) call **opts.update( command: 'zone-unset') end
187
- def zone_get( **opts) call **opts.update( command: 'zone-get') end
208
+ def zone_get( **opts) call **opts.update( command: 'zone-get') end
188
209
  end
data/lib/knot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Knot
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/knot.rb CHANGED
@@ -2,3 +2,13 @@ require 'knot/version'
2
2
  require 'knot/errors'
3
3
  require 'knot/protocol'
4
4
  require 'knot/interface'
5
+
6
+ module Knot
7
+ class <<self
8
+ def new *as, **os
9
+ Protocol.new *as, **os
10
+ end
11
+ alias connect new
12
+ alias open new
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Knauf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iounpack
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 2.3.0
60
+ version: 2.7.0
61
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - ">="