Version 0.2.0 - required ruby>=2.7. **-kw-options. BETA
This commit is contained in:
parent
0a0392d532
commit
6af5922217
1
Gemfile
1
Gemfile
|
@ -1,4 +1,5 @@
|
|||
source "https://rubygems.org"
|
||||
ruby '>=2.7'
|
||||
|
||||
# Specify your gem's dependencies in knot.gemspec
|
||||
gemspec
|
||||
|
|
|
@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|||
spec.summary = %q{Provides interface to knot-server.}
|
||||
spec.description = %q{Implements knot-protocol to provide an interface to knot-DNS-server}
|
||||
spec.homepage = 'https://git.denkn.at/deac/knot'
|
||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
||||
|
||||
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
||||
|
||||
|
|
10
lib/knot.rb
10
lib/knot.rb
|
@ -2,3 +2,13 @@ require 'knot/version'
|
|||
require 'knot/errors'
|
||||
require 'knot/protocol'
|
||||
require 'knot/interface'
|
||||
|
||||
module Knot
|
||||
class <<self
|
||||
def new *as, **os
|
||||
Protocol.new *as, **os
|
||||
end
|
||||
alias connect new
|
||||
alias open new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,7 +69,7 @@ class Knot::Zone
|
|||
|
||||
def read() @protocol.call command: 'zone-read', zone: @zone end
|
||||
def diff() @protocol.call command: 'zone-diff', zone: @zone end
|
||||
|
||||
|
||||
# setting record
|
||||
# if data is nil, it will be unset.
|
||||
def set owner, ttl = nil, type, data
|
||||
|
@ -153,33 +153,36 @@ class Knot::Conf
|
|||
|
||||
$~.named_captures.delete_if {|_,v| v.nil? }
|
||||
|
||||
when nil
|
||||
{}
|
||||
|
||||
else
|
||||
raise ArgumentError, "Invalid Item-format"
|
||||
end
|
||||
end
|
||||
|
||||
def get item = nil
|
||||
@protocol.call (item ? parse_item( item) : {}).update( command: 'conf-get')
|
||||
@protocol.call **parse_item( item).update( command: 'conf-get')
|
||||
end
|
||||
|
||||
# Sets or adds a new value to item.
|
||||
# knot knows single-value items like `server.rundir` and multi-value items like `server.listen`.
|
||||
# If you set a single-value, it will replace the old value. On a multi-value, it will add it.
|
||||
def set item, value
|
||||
@protocol.call parse_item( item).update( command: 'conf-set', data: value)
|
||||
@protocol.call **parse_item( item).update( command: 'conf-set', data: value)
|
||||
end
|
||||
|
||||
# Removes value from item. If you provide a value, this value will be removed.
|
||||
def unset item, value = nil
|
||||
@protocol.call parse_item( item).update( command: 'conf-unset', data: value)
|
||||
@protocol.call **parse_item( item).update( command: 'conf-unset', data: value)
|
||||
end
|
||||
alias delete unset
|
||||
|
||||
def list item = nil
|
||||
@protocol.call (item ? parse_item( item) : {}).update( command: 'conf-list')
|
||||
@protocol.call **parse_item( item).update( command: 'conf-list')
|
||||
end
|
||||
|
||||
def read item = nil
|
||||
@protocol.call (item ? parse_item( item) : {}).update( command: 'conf-read')
|
||||
@protocol.call **parse_item( item).update( command: 'conf-read')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'iounpack'
|
||||
require 'stringio'
|
||||
require_relative 'errors'
|
||||
|
||||
module Knot
|
||||
|
@ -51,6 +52,26 @@ module Knot::Protocol::Type
|
|||
end
|
||||
end
|
||||
|
||||
#class Knot::KnotC
|
||||
# attr_accessor :debug, :binary
|
||||
#
|
||||
# def initialize path = nil, binary: nil
|
||||
# @path = path
|
||||
# @binary = binary || 'knotc'
|
||||
# @conf = Knot::Conf.new self
|
||||
# @zones = Hash.new {|h, zone| h[zone] = Knot::Zone.new zone, self }
|
||||
# end
|
||||
#
|
||||
# def call command:, flags: nil, section: nil, item: nil, id: nil, zone: nil, owner: nil, ttl: nil, type: nil, data: nil, filter: nil
|
||||
# cs =
|
||||
# case command.to_s
|
||||
# when 'conf-begin', 'conf-commit', 'conf-abort', 'status', 'stop', 'reload'
|
||||
# [@binary, command, ]
|
||||
# else raise ArgumentError, "Unknown Command: #{command}"
|
||||
# end
|
||||
# end
|
||||
#end
|
||||
|
||||
module Knot::Protocol::Idx
|
||||
Idx = [
|
||||
:command, # 10, :CMD, # Control command name.
|
||||
|
@ -117,7 +138,7 @@ class Knot::Protocol
|
|||
STDERR.puts( {data: data, _: s}.inspect) if @debug
|
||||
rsock.write s
|
||||
rsock.flush
|
||||
end
|
||||
end
|
||||
|
||||
class RecordIO
|
||||
attr_reader :str
|
||||
|
@ -153,7 +174,7 @@ class Knot::Protocol
|
|||
when 1, 2
|
||||
type = t
|
||||
ret.push( r = {})
|
||||
else
|
||||
else
|
||||
raise Knot::Errors::EINVAL, "Missing Type before: #{t}" if ret.empty?
|
||||
i = Idx::Idx[t - 0x10] or raise Knot::Errors::EINVAL, "Unknown index: #{t-0x10}"
|
||||
l = sock.unpack1 'n'
|
||||
|
@ -167,7 +188,7 @@ class Knot::Protocol
|
|||
|
||||
def call sock: nil, **data
|
||||
snd sock: sock, **data
|
||||
rcv( sock: sock).each do |r|
|
||||
rcv( sock: sock).each do |r|
|
||||
if r[:error]
|
||||
if e = Knot::Errors.err2exc[r[:error]]
|
||||
raise e, r[:error]
|
||||
|
@ -179,10 +200,10 @@ class Knot::Protocol
|
|||
|
||||
def zone( zone) @zones[zone.to_s.to_sym] end
|
||||
|
||||
def conf_set( **opts) call **opts.update( command: 'conf-set') end
|
||||
def conf_unset( **opts) call **opts.update( command: 'conf-set') end
|
||||
def conf_set( **opts) call **opts.update( command: 'conf-set') end
|
||||
def conf_unset( **opts) call **opts.update( command: 'conf-unset') end
|
||||
|
||||
def zone_set( **opts) call **opts.update( command: 'zone-set') end
|
||||
def zone_set( **opts) call **opts.update( command: 'zone-set') end
|
||||
def zone_unset( **opts) call **opts.update( command: 'zone-unset') end
|
||||
def zone_get( **opts) call **opts.update( command: 'zone-get') end
|
||||
def zone_get( **opts) call **opts.update( command: 'zone-get') end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Knot
|
||||
VERSION = "0.1.2"
|
||||
VERSION = "0.2.0"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue