class PowerdnsApiClient (View source)

Constants

private API_VERSION_PATH

private MAX_CACHED_READS

One save reads about five distinct narrowed endpoints for a single name, so this covers it with room for a second name

private RRSET_FILTER_MIN_VERSION

Filtered zone reads only return disabled records from this version on

Methods

__construct(HttpClient $httpClient, string $serverName, LoggerInterface|null $logger = null, string|null $serverVersion = null)

No description

bool
rectifyZone(Zone $zone)

Rectify a zone

bool
secureZone(Zone $zone)

Enable DNSSEC for a zone

bool
unsecureZone(Zone $zone)

Disable DNSSEC for a zone

array
getAllZones(bool $withDnssec = true)

Get all zones from the PowerDNS server

array
getAllZoneStats(bool $withDnssec = true)

Get zone stats (DNSSEC, serial) for all zones in a single API call.

array
getAllZoneKinds(bool $withDnssec = false)

Get zone kind/masters/catalog for all zones in a single API call. Used to keep the local zones-table cache aligned with PowerDNS when zone kinds change outside Poweradmin (e.g. via pdnsutil set-kind), and to resolve catalog membership without a per-zone lookup.

static string
canonicalZoneName(string $name)

The form PowerDNS itself stores in domains.catalog: lowercase, no trailing dot. Its member lookup is an exact string match, so anything else produces a zone that is accepted and then silently never published.

bool
createZone(Zone $zone)

Create a new zone

bool
updateZone(Zone $zone)

Update a zone

bool
deleteZone(Zone $zone)

Delete a zone

array
getZoneKeys(Zone $zone)

Get DNSSEC keys for a zone

bool
addZoneKey(Zone $zone, CryptoKey $key)

Add a DNSSEC key to a zone

bool
importZoneKey(Zone $zone, string $keyType, string $algorithm, string $privateKeyPem)

Import a DNSSEC key from a PEM-encoded private key. Requires PowerDNS 4.7+ which accepts the privatekey field on POST /cryptokeys (per docs/changelog/4.7.rst PR #11590). The server derives bits and picks the right algorithm slot from the PEM contents.

array|null
getZoneKeyWithPrivate(Zone $zone, int $keyId)

Fetch a single cryptokey including its privatekey field, which PowerDNS only returns from the per-key GET endpoint (the list view omits it). Returns null when the key cannot be retrieved.

bool
activateZoneKey(Zone $zone, CryptoKey $key)

Activate a DNSSEC key

bool
deactivateZoneKey(Zone $zone, CryptoKey $key)

Deactivate a DNSSEC key

bool
removeZoneKey(Zone $zone, CryptoKey $key)

Remove a DNSSEC key

bool
isZoneSecured(Zone $zone)

Check if a zone is secured with DNSSEC

array
getZoneMetadata(Zone $zone)

Get all metadata for a zone

array
getZoneMetadataKind(Zone $zone, string $kind)

Get a specific metadata kind for a zone

bool
createZoneMetadata(Zone $zone, string $kind, array $metadata)

Create metadata for a zone

bool
updateZoneMetadata(Zone $zone, string $kind, array $metadata)

Update metadata for a zone, replacing existing entries of the given kind

bool
deleteZoneMetadata(Zone $zone, string $kind)

Delete all metadata of a given kind for a zone

array
getConfig()

Get PowerDNS configuration

array
getServerInfo()

Get PowerDNS server information

array
getServerConfig()

getConfig() flattened to a name => value map for settings lookups.

array
getMetrics()

Get PowerDNS server metrics

array|null
getZoneRrset(string $zoneName, string $rrsetName, string|null $rrsetType = null)

Fetch the RRsets at one name instead of the whole zone body. Leaving the type out returns every type at that name.

array|null
getZone(string $zoneName, bool $includeRrsets = true, array $filters = [])

Get a single zone with its RRsets

array|null
createZoneWithData(array $zoneData)

Create a zone with full data and return the response

bool
updateZoneProperties(string $zoneName, array $data)

Update zone properties (kind, masters, account, etc.)

bool
retrieveZone(string $zoneName)

Trigger an immediate AXFR transfer of a secondary zone from its master.

bool
patchZoneRRsets(string $zoneName, array $rrsets)

Patch zone RRsets (add, modify, or delete records)

array
searchData(string $query, string $objectType = 'all', int $max = 100)

Search across zones, records, and comments

array
getAutoprimaries()

Get all autoprimaries

bool
addAutoprimary(string $ip, string $nameserver, string $account = '')

Add an autoprimary

bool
deleteAutoprimary(string $ip, string $nameserver)

Delete an autoprimary

array
getTsigKeys()

Get all TSIG keys

array|null
createTsigKey(string $name, string $algorithm, string $key = '')

Create a TSIG key

bool
deleteTsigKey(string $keyId)

Delete a TSIG key

bool
updateTsigKey(string $keyId, array $data)

Update a TSIG key

array
listViews()

List all views configured on the server.

array
listViewZones(string $view)

List zones assigned to a specific view. Zone strings are returned in the upstream "zone..variant" form (e.g. "example.com..trusted").

bool
addZoneToView(string $view, string $zoneName)

Add a zone (in "zone..variant" form) to a view. Creates the view if it doesn't exist yet, per upstream behaviour.

bool
removeZoneFromView(string $view, string $zoneName)

No description

array
listNetworks()

List all network -> view mappings. Each entry is of the form ['network' => '192.168.0.0/16', 'view' => 'trusted'].

bool
setNetworkView(string $cidr, string $view)

Assign a CIDR block to a view. PowerDNS expects the CIDR in path form, e.g. PUT /networks/192.168.0.0/16.

bool
deleteNetwork(string $cidr)

No description

Details

__construct(HttpClient $httpClient, string $serverName, LoggerInterface|null $logger = null, string|null $serverVersion = null)

No description

Parameters

HttpClient $httpClient
string $serverName
LoggerInterface|null $logger
string|null $serverVersion

Skips the capability probe when the caller already knows the PowerDNS version

bool rectifyZone(Zone $zone)

Rectify a zone

Parameters

Zone $zone

Return Value

bool

bool secureZone(Zone $zone)

Enable DNSSEC for a zone

Parameters

Zone $zone

Return Value

bool

bool unsecureZone(Zone $zone)

Disable DNSSEC for a zone

Parameters

Zone $zone

Return Value

bool

array getAllZones(bool $withDnssec = true)

Get all zones from the PowerDNS server

Parameters

bool $withDnssec

Set false when the caller ignores DNSSEC state

Return Value

array

array getAllZoneStats(bool $withDnssec = true)

Get zone stats (DNSSEC, serial) for all zones in a single API call.

The zone list response carries no record count, so callers that need one must fetch it per zone.

Parameters

bool $withDnssec

Set false when the caller needs neither the DNSSEC flag nor edited_serial

Return Value

array

array getAllZoneKinds(bool $withDnssec = false)

Get zone kind/masters/catalog for all zones in a single API call. Used to keep the local zones-table cache aligned with PowerDNS when zone kinds change outside Poweradmin (e.g. via pdnsutil set-kind), and to resolve catalog membership without a per-zone lookup.

Only kind/masters/catalog are read here, so the DNSSEC lookup is skipped by default. Callers that also read the zone list with DNSSEC state should pass true so both reads share one response rather than fetching the list under two different URLs.

Parameters

bool $withDnssec

Match the endpoint a companion list call uses

Return Value

array

static string canonicalZoneName(string $name)

The form PowerDNS itself stores in domains.catalog: lowercase, no trailing dot. Its member lookup is an exact string match, so anything else produces a zone that is accepted and then silently never published.

Parameters

string $name

Return Value

string

bool createZone(Zone $zone)

Create a new zone

Parameters

Zone $zone

Return Value

bool

bool updateZone(Zone $zone)

Update a zone

Parameters

Zone $zone

Return Value

bool

bool deleteZone(Zone $zone)

Delete a zone

Parameters

Zone $zone

Return Value

bool

array getZoneKeys(Zone $zone)

Get DNSSEC keys for a zone

Parameters

Zone $zone

Return Value

array

bool addZoneKey(Zone $zone, CryptoKey $key)

Add a DNSSEC key to a zone

Parameters

Zone $zone
CryptoKey $key

Return Value

bool

bool importZoneKey(Zone $zone, string $keyType, string $algorithm, string $privateKeyPem)

Import a DNSSEC key from a PEM-encoded private key. Requires PowerDNS 4.7+ which accepts the privatekey field on POST /cryptokeys (per docs/changelog/4.7.rst PR #11590). The server derives bits and picks the right algorithm slot from the PEM contents.

Parameters

Zone $zone
string $keyType
string $algorithm
string $privateKeyPem

Return Value

bool

array|null getZoneKeyWithPrivate(Zone $zone, int $keyId)

Fetch a single cryptokey including its privatekey field, which PowerDNS only returns from the per-key GET endpoint (the list view omits it). Returns null when the key cannot be retrieved.

Parameters

Zone $zone
int $keyId

Return Value

array|null

bool activateZoneKey(Zone $zone, CryptoKey $key)

Activate a DNSSEC key

Parameters

Zone $zone
CryptoKey $key

Return Value

bool

bool deactivateZoneKey(Zone $zone, CryptoKey $key)

Deactivate a DNSSEC key

Parameters

Zone $zone
CryptoKey $key

Return Value

bool

bool removeZoneKey(Zone $zone, CryptoKey $key)

Remove a DNSSEC key

Parameters

Zone $zone
CryptoKey $key

Return Value

bool

bool isZoneSecured(Zone $zone)

Check if a zone is secured with DNSSEC

Parameters

Zone $zone

Return Value

bool

array getZoneMetadata(Zone $zone)

Get all metadata for a zone

Parameters

Zone $zone

Return Value

array

Array of metadata entries [['kind' => string, 'metadata' => string[]], ...]

array getZoneMetadataKind(Zone $zone, string $kind)

Get a specific metadata kind for a zone

Parameters

Zone $zone
string $kind

Metadata kind (e.g., 'ALLOW-AXFR-FROM', 'TSIG-ALLOW-AXFR')

Return Value

array

Metadata entry ['kind' => string, 'metadata' => string[]]

bool createZoneMetadata(Zone $zone, string $kind, array $metadata)

Create metadata for a zone

Parameters

Zone $zone
string $kind

Metadata kind

array $metadata

Array of metadata values

Return Value

bool

bool updateZoneMetadata(Zone $zone, string $kind, array $metadata)

Update metadata for a zone, replacing existing entries of the given kind

Parameters

Zone $zone
string $kind

Metadata kind

array $metadata

Array of metadata values

Return Value

bool

bool deleteZoneMetadata(Zone $zone, string $kind)

Delete all metadata of a given kind for a zone

Parameters

Zone $zone
string $kind

Metadata kind

Return Value

bool

array getConfig()

Get PowerDNS configuration

Return Value

array

array getServerInfo()

Get PowerDNS server information

Return Value

array

array getServerConfig()

getConfig() flattened to a name => value map for settings lookups.

Return Value

array

array getMetrics()

Get PowerDNS server metrics

Return Value

array

array|null getZoneRrset(string $zoneName, string $rrsetName, string|null $rrsetType = null)

Fetch the RRsets at one name instead of the whole zone body. Leaving the type out returns every type at that name.

PowerDNS below 4.7 does not know these filters, ignores them and returns the entire zone, so callers must still scan the RRsets they get back.

Parameters

string $zoneName

Zone name (with trailing dot)

string $rrsetName
string|null $rrsetType

Return Value

array|null

Zone data carrying the matching RRsets, or null if not found

array|null getZone(string $zoneName, bool $includeRrsets = true, array $filters = [])

Get a single zone with its RRsets

Parameters

string $zoneName

Zone name (with trailing dot)

bool $includeRrsets

Set false to fetch zone metadata only (skips records on large zones)

array $filters

Extra query parameters, e.g. an RRset filter - prefer getZoneRrset()

Return Value

array|null

Zone data or null if not found

array|null createZoneWithData(array $zoneData)

Create a zone with full data and return the response

Parameters

array $zoneData

Zone creation payload

Return Value

array|null

Zone data from response or null on failure

bool updateZoneProperties(string $zoneName, array $data)

Update zone properties (kind, masters, account, etc.)

Parameters

string $zoneName

Zone name (with trailing dot)

array $data

Zone properties to update

Return Value

bool

bool retrieveZone(string $zoneName)

Trigger an immediate AXFR transfer of a secondary zone from its master.

Asks PowerDNS to pull the zone now instead of waiting for the next scheduled refresh. Returns false when the master refuses the transfer.

Parameters

string $zoneName

Zone name (with trailing dot)

Return Value

bool

bool patchZoneRRsets(string $zoneName, array $rrsets)

Patch zone RRsets (add, modify, or delete records)

Parameters

string $zoneName

Zone name (with trailing dot)

array $rrsets

Array of RRset change objects

Return Value

bool

array searchData(string $query, string $objectType = 'all', int $max = 100)

Search across zones, records, and comments

Parameters

string $query

Search query (supports * and ? wildcards)

string $objectType

Filter: 'all', 'zone', 'record', or 'comment'

int $max

Maximum number of results

Return Value

array

Search results

array getAutoprimaries()

Get all autoprimaries

Return Value

array

bool addAutoprimary(string $ip, string $nameserver, string $account = '')

Add an autoprimary

Parameters

string $ip

IP address

string $nameserver

Nameserver hostname

string $account

Account name

Return Value

bool

bool deleteAutoprimary(string $ip, string $nameserver)

Delete an autoprimary

Parameters

string $ip

IP address

string $nameserver

Nameserver hostname

Return Value

bool

array getTsigKeys()

Get all TSIG keys

Return Value

array

array|null createTsigKey(string $name, string $algorithm, string $key = '')

Create a TSIG key

Parameters

string $name

Key name

string $algorithm

Key algorithm (e.g., hmac-md5, hmac-sha256)

string $key

Key material (empty to let server generate)

Return Value

array|null

Created key data or null on failure

bool deleteTsigKey(string $keyId)

Delete a TSIG key

Parameters

string $keyId

TSIG key ID

Return Value

bool

bool updateTsigKey(string $keyId, array $data)

Update a TSIG key

Parameters

string $keyId

TSIG key ID

array $data

Key properties to update

Return Value

bool

array listViews()

List all views configured on the server.

Return Value

array

array listViewZones(string $view)

List zones assigned to a specific view. Zone strings are returned in the upstream "zone..variant" form (e.g. "example.com..trusted").

Parameters

string $view

Return Value

array

bool addZoneToView(string $view, string $zoneName)

Add a zone (in "zone..variant" form) to a view. Creates the view if it doesn't exist yet, per upstream behaviour.

Parameters

string $view
string $zoneName

Return Value

bool

bool removeZoneFromView(string $view, string $zoneName)

No description

Parameters

string $view
string $zoneName

Return Value

bool

array listNetworks()

List all network -> view mappings. Each entry is of the form ['network' => '192.168.0.0/16', 'view' => 'trusted'].

Return Value

array

bool setNetworkView(string $cidr, string $view)

Assign a CIDR block to a view. PowerDNS expects the CIDR in path form, e.g. PUT /networks/192.168.0.0/16.

Parameters

string $cidr
string $view

Return Value

bool

bool deleteNetwork(string $cidr)

No description

Parameters

string $cidr

Return Value

bool