Search by

adachsoft / dns-zone-ovh

Arkadiusz Adach

OVH DNS zone adapter for the provider-independent AdachSoft DNS zone contracts.

Package info

gitlab.com/a.adach/dns-zone-ovh

Issues

pkg:composer/adachsoft/dns-zone-ovh

Statistics

Installs: 4

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-26 15:01 UTC

This package is auto-updated.

Last update: 2026-11-26 14:01:36 UTC


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:

MethodPath
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 fieldType and subDomain filters to OVH. An apex filter is sent as subDomain=.
  • 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 SPF records are returned as contract TXT records. New TXT records are always written with fieldType=TXT.
  • OVH record types not represented by DnsRecordTypeEnum are omitted from listRecords().
  • An OVH TTL of 0 represents the zone default and is returned as null. A null TTL is omitted when creating a record and sent as 0 when 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.