Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'pg' | ||
|
||
module Proxy::Dns::Powerdns::Backend | ||
class Postgresql < ::Proxy::Dns::Powerdns::Record | ||
|
||
attr_reader :connection_str | ||
|
||
def initialize(a_server = nil, a_ttl = nil) | ||
@connection_str = Proxy::Dns::Powerdns::Plugin.settings.powerdns_postgresql_connection | ||
|
||
super(a_server, a_ttl) | ||
end | ||
|
||
def connection | ||
@connection ||= PG.connect(connection_str) | ||
end | ||
|
||
def get_zone name | ||
domain = nil | ||
|
||
connection.exec_params("SELECT LENGTH(name) domain_length, id, name FROM domains WHERE $1 LIKE CONCAT('%%.', name) ORDER BY domain_length DESC LIMIT 1", [name]) do |result| | ||
result.each do |row| | ||
domain = row | ||
end | ||
end | ||
|
||
raise Proxy::Dns::Error, "Unable to determine zone. Zone must exist in PowerDNS." unless domain | ||
|
||
domain | ||
end | ||
|
||
def create_record domain_id, name, type, content | ||
result = connection.exec_params("INSERT INTO records (domain_id, name, ttl, content, type) VALUES ($1::int, $2, $3::int, $4, $5)", [domain_id, name, ttl, content, type]) | ||
result.cmdtuples == 1 | ||
end | ||
|
||
def delete_record domain_id, name, type | ||
result = connection.exec_params("DELETE FROM records WHERE domain_id=$1::int AND name=$2 AND type=$3", [domain_id, name, type]) | ||
result.cmdtuples == 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'test_helper' | ||
|
||
require 'smart_proxy_dns_powerdns/dns_powerdns_plugin' | ||
require 'smart_proxy_dns_powerdns/dns_powerdns_main' | ||
require 'smart_proxy_dns_powerdns/backend/postgresql' | ||
|
||
class DnsPowerdnsBackendPostgresqlTest < Test::Unit::TestCase | ||
# Test that correct initialization works | ||
def test_initialize_dummy_with_settings | ||
Proxy::Dns::Powerdns::Plugin.load_test_settings(:powerdns_postgresql_connection => 'dbname=powerdns') | ||
provider = klass.new | ||
assert_equal 'dbname=powerdns', provider.connection_str | ||
end | ||
|
||
private | ||
|
||
def klass | ||
Proxy::Dns::Powerdns::Backend::Postgresql | ||
end | ||
end |