Skip to content

feat: add support for optional subdirectory in PowerDNS API path - #174

Closed
pkolmann wants to merge 2 commits into
exonet:masterfrom
pkolmann:subdirectory
Closed

feat: add support for optional subdirectory in PowerDNS API path#174
pkolmann wants to merge 2 commits into
exonet:masterfrom
pkolmann:subdirectory

Conversation

@pkolmann

Copy link
Copy Markdown

Description

Currently powerdns-php does not support powerdns-admin to be hosted in a subdirectory

Motivation and context

I host my powerdns-admin in a subdirectory rather then their own hostname. The API currently can't handle this. I have added the subDirectory option to specify this in the connection URL.

How has this been tested?

I used the provided tests and also used the updated library on my own setup.

Screenshots (if appropriate)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests pass.

  • [x ] I have read the CONTRIBUTING document.
  • [ x] My pull request addresses exactly one patch/feature.
  • [ x] My pull request contains a title that can be used as a release note.
  • [ x] I have created a branch for this patch/feature.
  • [ x] Each individual commit in the pull request is meaningful.
  • [ x] I have added tests to cover my changes.
  • [ x] If my change requires a change to the documentation, I have updated it accordingly.

@trizz

trizz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR.

The use case is real, but I don't think this belongs in the client. powerdns-php talks to the PowerDNS Authoritative HTTP API, and that API always lives at /api/v1. A subdirectory in front of it isn't a PowerDNS thing.

So I'm going to close this one. Thanks again for taking the time.

@trizz trizz closed this Jul 13, 2026
@pkolmann

Copy link
Copy Markdown
Author

Hi @trizz,

thanks for your comment. My Usecase is, that I want to interact with PowerDNS-Admin where I can limit the zones per api key the script has access to. And this Web-service is located in a subdirectory.

Maybe you could re-consider this PR.
thanks, Philipp

@trizz

trizz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks, Philipp — I know it'd work against PDA's proxied endpoints, but I'd still rather not merge this into the client.

A path prefix isn't part of the PowerDNS Authoritative API (that contract is fixed at /api/v1) — it's an artifact of running a reverse proxy in front of it. And PowerDNS-Admin is effectively in legacy/maintenance-only mode now (rebranded to pda-legacy), so we don't want to bake its deployment shape into the client.

The good news is you don't need a library change for this. buildUrl() is protected and the client accepts any ConnectorInterface, so you can override just the path building and inject your own connector:

use Exonet\Powerdns\Connector;
use Exonet\Powerdns\Powerdns;
use GuzzleHttp\HandlerStack;

final class SubdirectoryConnector extends Connector
{
    public function __construct(
        private readonly Powerdns $client,
        private readonly string $subdirectory,
        ?HandlerStack $handlerStack = null,
    ) {
        parent::__construct($client, $handlerStack);
    }

    protected function buildUrl(string $path): string
    {
        $config = $this->client->getConfig();

        return rtrim(sprintf(
            '%s:%d/%s/api/v1/servers/%s/%s',
            $config['host'],
            $config['port'],
            trim($this->subdirectory, '/'),
            $config['server'],
            $path,
        ), '/');
    }
}
$powerdns = new Powerdns();
$powerdns->setConnector(new SubdirectoryConnector($powerdns, 'pdns-admin'));
$powerdns->connect('https://dns.example.com', 443)->useKey('your-key');

That keeps your subdirectory setup working without the client having to carry configuration for a specific proxy layout. Thanks again for the PR and for taking the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants