couchdb

package module
v0.0.0-...-80a1fb5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

Description

The couchdb plugin is a plugin to compile with CoreDNS that enables reading zone data from CouchDB server.

Syntax

Use rhinoman/couchdb-go to handle database.

couchdb 

couchdb loads authoritative zones from couchdb server

Address and port will default to local couchdb server (localhost:5984/) and it's possible configure HTTP basic authentication by providing username and password.

couchdb {
    address  COUCHDB ADDRESS
    port     COUCHDB PORT
    dbname   COUCHDB DBNAME
    username USERNAME BASIC AUTH
    password PASSWORD BASIC AUTH
}

all parameters

  • address defaults to localhost.
  • port defaults to 5984.
  • dbname defaults to zones.
  • username username to basic auth. Defaults none.
  • password password to basic auth. Defaults none.

This plugin is intended to appear at the end of the plugin list, usually near the proxy plugin declaration.

Example

Enable couchdb plugin at localhost with port 5984

. {
	couchdb {
		address 127.0.0.1
		port 5984
	}
	errors
}

zone format in couchdb db

Data record format representing DNS Messages in JSON such as RFC 8427 (Draft) https://tools.ietf.org/html/draft-hoffman-dns-in-json-16

Each zones is stored in database "zones" as a document.

First, must create database zones:

# curl -H 'Content-Type: application/json' -X PUT http://127.0.0.1:5984/zones
{"ok":true}

Add some documents:

# curl -0 http://127.0.0.1:5984/zones \
-H 'Content-Type: application/json' \
-d @- << EOF
{
    "_id": "example.com.",
    "data": [
        {
            "name": "",
            "data": "127.0.0.2",
            "TTL": 3600,
            "type": 1
        },
        {
            "name": "ns1",
            "data": "127.0.0.2",
            "TTL": 3600,
            "type": 1
        },
        {
            "name": "ns2",
            "data": "127.0.0.2",
            "TTL": 3600,
            "type": 1
        },        
        {
            "name": "www",
            "data": "example.com.",
            "TTL": 3600,
            "type": 5
        },
        {
            "name": "",
            "data": "ns1.example.com.",
            "TTL": 3600,
            "type": 2
        },
        {
            "name": "",
            "data": "ns2.example.com.",
            "TTL": 3600,
            "type": 2
        },
        {
            "name": "",
            "data": "0 example.com.",
            "TTL": 3600,
            "type": 15
        },
        {
            "name": "",
            "data": "\"v=spf1 +a +mx +ip4:127.0.0.2 ~all\"",
            "TTL": 3600,
            "type": 16
        },
        {
            "name": "",
            "data": "ns1.example.com. webmaster.example.com. 2018071304 3600 7200 1209600 86400",
            "TTL": 3600,
            "type": 6
        },
        {
            "name": "_sip._tcp",
            "data": "20 0 5060 www.example.com.",
            "TTL": 3600,
            "type": 33
        }
    ]
}
EOF
{"ok":true,"id":"example.com.","rev":"1-223911e169ce700d846e62ee4ff2c087"}

Do some queries:

# --------------
# A 
# --------------
# dig @127.0.0.1 example.com a
...
;; ANSWER SECTION:
example.com.		3600	IN	A	127.0.0.2

# --------------
# MX
# --------------
# dig @127.0.0.1 example.com mx
...
;; ANSWER SECTION:
example.com.		3600	IN	MX	0 example.com.

;; ADDITIONAL SECTION:
example.com.		3600	IN	A	127.0.0.2

# --------------
# NS
# --------------
# dig @127.0.0.1 example.com ns
...
;; ANSWER SECTION:
example.com.		3600	IN	NS	ns1.example.com.
example.com.		3600	IN	NS	ns2.example.com.

;; ADDITIONAL SECTION:
ns1.example.com.	3600	IN	A	127.0.0.2
ns2.example.com.	3600	IN	A	127.0.0.2

# --------------
# SRV
# --------------
# dig @127.0.0.1 _sip._tcp.example.com srv
...
;; ANSWER SECTION:
_sip._tcp.example.com.	3600	IN	SRV	20 0 5060 www.example.com.

;; ADDITIONAL SECTION:
www.example.com.	3600	IN	CNAME	example.com.

# --------------
# SOA
# --------------
# dig @127.0.0.1 example.com soa
...
;; ANSWER SECTION:
example.com.		3600	IN	SOA	ns1.example.com. webmaster.example.com. 2018071304 3600 7200 1209600 86400

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CouchDB

type CouchDB struct {
	Next plugin.Handler // Next handler in the list of plugins.

	Connection *couchdb.Connection
	DB         *couchdb.Database

	// Addr is the address of the CouchDB server.
	Address string
	Port    int
	DBname  string

	// BasicAuth for couchdb
	BasicAuth couchdb.Auth
}

CouchDB is the implementation of the "couchdb" CoreDNS plugin.

func New

func New() *CouchDB

New constructs a new instance of a couchdb plugin.

func (*CouchDB) A

func (couchDB *CouchDB) A(query string, z *Zone) (answers, extras []dns.RR)

A returns A DNS records that matches with the query.

func (*CouchDB) AAAA

func (couchDB *CouchDB) AAAA(query string, z *Zone) (answers, extras []dns.RR)

AAAA returns AAAA DNS records that matches with the query.

func (*CouchDB) CAA

func (couchDB *CouchDB) CAA(query string, z *Zone) (answers, extras []dns.RR)

CAA returns CAA DNS records that matches with the query. Data record format such as RFC 4408 https://tools.ietf.org/html/rfc4408

func (*CouchDB) CNAME

func (couchDB *CouchDB) CNAME(query string, z *Zone) (answers, extras []dns.RR)

CNAME returns CNAME DNS records that matches with the query.

func (*CouchDB) Find

func (couchDB *CouchDB) Find(qname string) (qrecord string, z Zone)

Find DNS zone by qname.

func (*CouchDB) MX

func (couchDB *CouchDB) MX(query string, z *Zone) (answers, extras []dns.RR)

MX returns MX DNS records that matches with the query. Data record format such as RFC 974 https://tools.ietf.org/html/rfc974

func (*CouchDB) NS

func (couchDB *CouchDB) NS(query string, z *Zone) (answers, extras []dns.RR)

NS returns NS DNS records that matches with the query.

func (*CouchDB) Name

func (couchDB *CouchDB) Name() string

Name of the plugin, returns "couchdb".

func (*CouchDB) SOA

func (couchDB *CouchDB) SOA(query string, z *Zone) (answers, extras []dns.RR)

SOA returns SOA record that matches with the query.

func (*CouchDB) SRV

func (couchDB *CouchDB) SRV(query string, z *Zone) (answers, extras []dns.RR)

SRV returns SRV DNS records that matches with the query. Data record format such as RFC 2782 https://tools.ietf.org/html/rfc2782 RDATA: Priority Weight Port Target

func (*CouchDB) ServeDNS

func (couchDB *CouchDB) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface. The values the integer can take are the DNS RCODEs, dns.RcodeServerFailure, dns.RcodeNotImplemented, dns.RcodeSuccess, etc.. A successful return value indicates the plugin has written to the client.

func (*CouchDB) TXT

func (couchDB *CouchDB) TXT(query string, z *Zone) (answers, extras []dns.RR)

TXT returns TXT DNS records that matches with the query. Data record format such as RFC 4408 https://tools.ietf.org/html/rfc4408

type Record

type Record struct {
	Name string `json:"name"`
	Data string `json:"data"`
	Type uint16 `json:"type"`
	TTL  uint32 `json:"TTL"`
}

Record defines a DNS Record in JSON such as RFC 8427 (Representing DNS Messages in JSON) https://tools.ietf.org/html/draft-hoffman-dns-in-json-16

type Zone

type Zone struct {
	ID   string   `json:"_id"`
	Rev  string   `json:"_rev,omitempty"`
	Data []Record `json:"data,omitempty"`
}

Zone defines a DNS Zone stored in couchDB.

Jump to

Keyboard shortcuts

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