Project

pdns-ruby

0.0
No release in over 3 years
A simple Ruby client for managing zones and records via the PowerDNS HTTP API. Supports zone CRUD, rrset management, and record operations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

pdns-ruby

A simple Ruby client for the PowerDNS HTTP API. Zero dependencies beyond Ruby's standard library.

Installation

gem 'pdns-ruby'

Usage

require 'pdns_ruby'

client = PdnsRuby::Client.new(
  host: 'http://localhost:8081',
  api_key: 'your-api-key'
)

Zones

# list all zones
client.zones

# get a zone
zone = client.zone('example.com')

# check if zone exists
client.zone_exists?('example.com')

# create a zone
zone = client.create_zone('example.com', nameservers: ['ns1.example.com', 'ns2.example.com'])

# delete a zone
client.delete_zone('example.com')
# or
zone.delete!

Records

zone = client.zone('example.com')

# add/update a record
zone.add_record('www.example.com.', 'A', '1.2.3.4', ttl: 3600)

# add MX record
zone.add_record('example.com.', 'MX', '10 mail.example.com.', ttl: 3600)

# delete a record
zone.delete_record('www.example.com.', 'A')

# get all rrsets
zone.rrsets

# find specific rrset
zone.find_rrset('www.example.com.', 'A')

Batch Updates

rrsets = [
  PdnsRuby::Rrset.replace(
    name: 'www.example.com.',
    type: 'A',
    ttl: 3600,
    records: [{ content: '1.2.3.4' }, { content: '5.6.7.8' }]
  ),
  PdnsRuby::Rrset.delete(
    name: 'old.example.com.',
    type: 'CNAME'
  )
]

client.update_rrsets('example.com', rrsets)

Error Handling

begin
  client.zone('nonexistent.com')
rescue PdnsRuby::NotFoundError => e
  puts "Zone not found"
rescue PdnsRuby::AuthError => e
  puts "Invalid API key"
rescue PdnsRuby::ApiError => e
  puts "API error: #{e.message}"
end

Features

  • Zero external dependencies — uses only Ruby's net/http and json
  • Zone management (list, get, create, delete)
  • Record management via rrsets (add, update, delete, batch)
  • Automatic trailing dot normalization for domain names
  • Typed error classes for easy error handling
  • Works with PowerDNS 4.x API

License

MIT