adachsoft / dns-zone-ovh
OVH DNS zone adapter for the provider-independent AdachSoft DNS zone contracts.
Requires
- php: ^8.3
- adachsoft/dns-zone-contracts: ^0.1
- ovh/ovh: ^3.5
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/dns-zone-ovh implements the provider-independent adachsoft/dns-zone-contracts API for managing OVH DNS zones. It uses the official ovh/ovh SDK and supports listing, creating, updating, deleting, and publishing DNS records.
Requirements and installation
- PHP 8.3 or later
- Composer
- OVH API credentials with DNS-zone permissions
Install the adapter with Composer:
composer require adachsoft/dns-zone-ovh
The adapter installs its required DNS contracts and OVH SDK dependencies automatically.
Create an OVH API key
Create an API key at eu.api.ovh.com/createToken. Grant the following rights:
| Method | Path |
|---|---|
| GET | /domain/zone |
| GET | /domain/zone/* |
| POST | /domain/zone/* |
| PUT | /domain/zone/* |
| DELETE | /domain/zone/* |
Permissions can be restricted to a specific zone. When a key cannot access GET /domain/zone/{zone}, the adapter checks the zone through GET /domain/zone/{zone}/record instead.
Credentials file
Store the endpoint, application key, application secret, and consumer key in an INI-compatible file. Keep this file outside version control and restrict its filesystem permissions.
OVH_ENDPOINT=ovh-eu
OVH_APPLICATION_KEY=your-application-key
OVH_APPLICATION_SECRET="your-application-secret"
OVH_CONSUMER_KEY=your-consumer-key
Supported endpoint identifiers include ovh-eu, ovh-ca, and ovh-us. Quote values containing INI comment characters or other special syntax. OvhCredentials::fromEnvFile() reports missing variables by name without including credential values in its error message.
Usage
Quick start
Use RecordSetSynchronizer to add missing mail records without replacing unrelated records in the zone:
<?php
declare(strict_types=1);
use AdachSoft\DnsZoneContracts\Model\DnsRecord;
use AdachSoft\DnsZoneContracts\Model\DnsRecordCollection;
use AdachSoft\DnsZoneContracts\Model\DnsRecordTypeEnum;
use AdachSoft\DnsZoneContracts\Model\RecordName;
use AdachSoft\DnsZoneContracts\Model\SyncModeEnum;
use AdachSoft\DnsZoneContracts\Model\ZoneName;
use AdachSoft\DnsZoneContracts\Service\RecordSetSynchronizer;
use AdachSoft\DnsZoneOvh\Model\OvhCredentials;
use AdachSoft\DnsZoneOvh\OvhDnsZone;
$zone = OvhDnsZone::create(OvhCredentials::fromEnvFile(__DIR__ . '/.env.ovh'));
$zoneName = new ZoneName('example.com');
$desiredRecords = new DnsRecordCollection([
new DnsRecord(
new RecordName(''),
DnsRecordTypeEnum::MX,
'mx1.mail.example.com.',
3600,
10,
),
new DnsRecord(
new RecordName(''),
DnsRecordTypeEnum::MX,
'mx2.mail.example.com.',
3600,
20,
),
new DnsRecord(
new RecordName(''),
DnsRecordTypeEnum::TXT,
'v=spf1 include:mail.example.com ~all',
3600,
),
]);
$changes = (new RecordSetSynchronizer($zone))->ensure(
$zoneName,
$desiredRecords,
SyncModeEnum::ADD_MISSING,
);
printf("Created %d DNS records.\n", count($changes->created));
RecordSetSynchronizer publishes non-empty change sets by calling applyChanges(). For direct writes, call $zone->applyChanges($zoneName) after creating, updating, or deleting records.
OVH record behavior
- OVH record listing returns identifiers, so the adapter fetches each record separately.
listRecords()therefore makes one collection request plus one request per returned record. - The adapter passes
fieldTypeandsubDomainfilters to OVH. An apex filter is sent assubDomain=. - Contract TXT values are unquoted. OVH TXT presentation quotes are removed on reads and added on writes; embedded quotes and backslashes are escaped, and values longer than 255 bytes are split into quoted chunks.
- Legacy OVH
SPFrecords are returned as contractTXTrecords. New TXT records are always written withfieldType=TXT. - OVH record types not represented by
DnsRecordTypeEnumare omitted fromlistRecords(). - An OVH TTL of
0represents the zone default and is returned asnull. AnullTTL is omitted when creating a record and sent as0when updating one.
Integration test
The OVH integration test uses a dedicated test zone and creates and removes random TXT records. It is skipped unless both OVH_TEST_ENV_FILE and OVH_TEST_ZONE are set. Configure them only in an isolated test environment, then run:
OVH_TEST_ENV_FILE=/secure/path/ovh-test.env \
OVH_TEST_ZONE=example.com \
vendor/bin/phpunit --testsuite integration
The test creates a random _dns-zone-ovh-test-* TXT record, lists and updates it, checks that ADD_MISSING is idempotent, removes the records in a finally block, and refreshes the zone.