Class: DNSUpdater
- Inherits:
-
Object
- Object
- DNSUpdater
- Defined in:
- lib/dnsupdater.rb,
lib/dnsupdater/cli.rb,
lib/dnsupdater/web.rb,
lib/dnsupdater/error.rb,
lib/dnsupdater/utils.rb,
lib/dnsupdater/config.rb,
lib/dnsupdater/version.rb,
lib/dnsupdater/updaters.rb,
lib/dnsupdater/updaters/ssh.rb,
lib/dnsupdater/updaters/http.rb,
lib/dnsupdater/updaters/updater.rb,
lib/dnsupdater/updaters/powerdns.rb
Overview
Do DNS update based on specified target
Defined Under Namespace
Modules: CLI, Updaters, Utils Classes: Config, Error, Web
Constant Summary collapse
- VERSION =
Version
'1.2.0'
Class Method Summary collapse
-
.buildParams(protocol = nil, server = nil, port = nil) ⇒ Object
Create param Hash.
-
.fillPathParams(path, params) ⇒ Hash
Set :Domain and :IPs from path to params.
-
.fillUriParams(uri, params) ⇒ Hash
Set uri info to params.
-
.parseTarget(target) ⇒ Addressable::URI
Process target into URI.
-
.update(protocol, params, config) ⇒ Object
Update DNS using updater identified by specified protocol.
Instance Method Summary collapse
-
#initialize(config) ⇒ DNSUpdater
constructor
A new instance of DNSUpdater.
-
#update(target, targetProtocol = nil) ⇒ Object
Update DNS based on specified target.
Constructor Details
#initialize(config) ⇒ DNSUpdater
Returns a new instance of DNSUpdater.
15 16 17 |
# File 'lib/dnsupdater.rb', line 15 def initialize(config) @Config = config end |
Class Method Details
.buildParams(protocol = nil, server = nil, port = nil) ⇒ Object
Create param Hash
50 51 52 53 54 55 |
# File 'lib/dnsupdater.rb', line 50 def buildParams(protocol = nil, server = nil, port = nil) params = { Protocol: nil, Server: server, Port: port, User: nil, Domain: nil, IPs: [] } params[:Protocol] = protocol.downcase.to_sym if protocol params end |
.fillPathParams(path, params) ⇒ Hash
Set :Domain and :IPs from path to params
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dnsupdater.rb', line 68 def fillPathParams(path, params) parts = path.split('/').map { |part| Addressable::URI.unencode_component(part) } raise Error, 'Not enough parameters!' if parts.count < 3 params[:Domain] = parts[-2] params[:IPs] = parts[-1].to_s.split(',') params end |
.fillUriParams(uri, params) ⇒ Hash
Set uri info to params
83 84 85 86 87 88 89 90 |
# File 'lib/dnsupdater.rb', line 83 def fillUriParams(uri, params) params[:Protocol] = uri.scheme.to_sym unless uri.scheme.to_s.empty? params[:Server] = uri.host unless uri.host.to_s.empty? params[:Port] = uri.port unless uri.port.to_s.empty? params[:User] = uri.user unless uri.user.to_s.empty? params end |
.parseTarget(target) ⇒ Addressable::URI
Process target into URI
60 61 62 |
# File 'lib/dnsupdater.rb', line 60 def parseTarget(target) Addressable::URI.parse(target.to_s) end |
.update(protocol, params, config) ⇒ Object
Update DNS using updater identified by specified protocol
41 42 43 44 45 46 |
# File 'lib/dnsupdater.rb', line 41 def self.update(protocol, params, config) raise Error, "Unsupported protocol: '#{protocol}'!" unless Updaters.has?(protocol) updater = Updaters.get(protocol) updater.new(config).update(params) end |
Instance Method Details
#update(target, targetProtocol = nil) ⇒ Object
Update DNS based on specified target
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dnsupdater.rb', line 22 def update(target, targetProtocol = nil) raise Error, self.class.name + ': Invalid target (empty)!' if target.to_s.empty? uri = self.class.parseTarget(target) params = self.class.buildParams self.class.fillPathParams(uri.path, params) self.class.fillUriParams(uri, params) params[:Protocol] = @Config.getDefaultProtocol if params[:Protocol].to_s.empty? || (params[:Protocol] == :default) @Config.setTargetProtocol(params[:Protocol], targetProtocol) self.class.update(params[:Protocol], params, @Config) end |