pdsql

package module
v0.0.0-...-231f7ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2024 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README


title: "pdsql" description: "pdsql use powerdns generic sql as backend." weight: 10 tags: [ "plugin" , "pdsql" ] categories: [ "plugin", "external" ] date: "2017-12-09T10:26:00+08:00" repo: "https://github.com/wenerme/coredns-pdsql" home: "https://github.com/wenerme/coredns-pdsql/blob/master/README.md"

this fork of pdsql

For pdsql to work with sqlite properly, I have to use newer gorm. Its architecture changed a bit , so dialects are not registered under names, but passed to gorm.Open as gorm.Dialectors. I adapted setup.go to include all the drivers I might need: pure-Go sqlite3, and the standard gorm postgres and mysql drivers. Hence no need to add them to coredns plugin.cfg anymore, and you can't add a driver and have it supported automatically, like it was in the original version.

pdsql

pdsql use PowerDNS generic sql as backend.

Use jinzhu/gorm to handle database, support many database as gorm dose.

Syntax

pdsql <dialect> <arg> {
    # enable debug mode
    debug [db]
    # create table for test
    auto-migrate
}

Install Driver

pdsql need db driver for dialect, to install a driver you need to add import in plugin.cfg, like

pdsql_mysql:github.com/jinzhu/gorm/dialects/mysql
pdsql_sqlite:github.com/jinzhu/gorm/dialects/sqlite

pdsql_mysql and pdsql_sqlite are meaningless, choose to prevent duplicated.

Examples

Start a server on the 1053 port, use test.db as backend.

test.:1053 {
    pdsql sqlite3 ./test.db {
        debug db
        auto-migrate
    }
}

Prepare data for test.

# Insert records for wener.test
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","A","192.168.1.1",3600,0)'
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","TXT","TXT Here",3600,0)'

When queried for "wener.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	A

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1

When queried for "wener.test. ANY", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	ANY

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1
wener.test.		3600	IN	TXT	"TXT Here"

Wildcard

# domain id 1
sqlite3 ./test.db 'insert into domains(name,type)values("example.test","NATIVE")'
sqlite3 ./test.db 'insert into records(domain_id,name,type,content,ttl,disabled)values(1,"*.example.test","A","192.168.1.1",3600,0)'

When queried for "first.example.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;first.example.test.		IN	A

;; ANSWER SECTION:
first.example.test.	3600	IN	A	192.168.1.1

TODO

  • support wildcard record

Documentation

Overview

Package pdsql implements a plugin that query powerdns database to resolve the coredns query

Index

Constants

View Source
const Name = "pdsql"

Variables

This section is empty.

Functions

func ParseSOA

func ParseSOA(rr *dns.SOA, line string) bool

func WildcardMatch

func WildcardMatch(s1, s2 string) bool

Dummy wildcard match

Types

type PowerDNSGenericSQLBackend

type PowerDNSGenericSQLBackend struct {
	*gorm.DB
	Debug bool
	Next  plugin.Handler
}

func (PowerDNSGenericSQLBackend) AutoMigrate

func (pdb PowerDNSGenericSQLBackend) AutoMigrate() error

func (PowerDNSGenericSQLBackend) Name

func (pdb PowerDNSGenericSQLBackend) Name() string

func (PowerDNSGenericSQLBackend) SearchWildcard

func (pdb PowerDNSGenericSQLBackend) SearchWildcard(qname string, qtype uint16) (redords []*pdnsmodel.Record, err error)

func (PowerDNSGenericSQLBackend) ServeDNS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址