feat: add support for optional subdirectory in PowerDNS API path - #174
feat: add support for optional subdirectory in PowerDNS API path#174pkolmann wants to merge 2 commits into
Conversation
|
Thanks for the PR. The use case is real, but I don't think this belongs in the client. So I'm going to close this one. Thanks again for taking the time. |
|
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 — 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 The good news is you don't need a library change for this. 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. |
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
xin 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.