ovh

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2025 License: MIT Imports: 8 Imported by: 6

README

OVH DNS for libdns

godoc reference

This package implements the libdns interfaces for the OVH DNS API using the OVH API GO SDK

Authenticating

To authenticate you need to create script credentials in your region account and specify these API rights :

For multiple domains :

GET /domain/zone/*/record
POST /domain/zone/*/record
GET /domain/zone/*/record/*
PUT /domain/zone/*/record/*
DELETE /domain/zone/*/record/*
GET /domain/zone/*/soa
POST /domain/zone/*/refresh

For a single domain or delegation :

GET /domain/zone/yourdomain.com/record
POST /domain/zone/yourdomain.com/record
GET /domain/zone/yourdomain.com/record/*
PUT /domain/zone/yourdomain.com/record/*
DELETE /domain/zone/yourdomain.com/record/*
GET /domain/zone/yourdomain.com/soa
POST /domain/zone/yourdomain.com/refresh

Example

Here's a minimal example of how to get all DNS records for zone. See also: provider_test.go

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/libdns/ovh"
)

func main() {
	endPoint := os.Getenv("LIBDNS_OVH_TEST_ENDPOINT")
	if endPoint == "" {
		fmt.Printf("LIBDNS_OVH_TEST_ENDPOINT not set\n")
		return
	}

	applicationKey := os.Getenv("LIBDNS_OVH_TEST_APPLICATION_KEY")
	if applicationKey == "" {
		fmt.Printf("LIBDNS_OVH_TEST_APPLICATION_KEY not set\n")
		return
	}

	applicationSecret := os.Getenv("LIBDNS_OVH_TEST_APPLICATION_SECRET")
	if applicationSecret == "" {
		fmt.Printf("LIBDNS_OVH_TEST_APPLICATION_SECRET not set\n")
		return
	}

	consumerKey := os.Getenv("LIBDNS_OVH_TEST_CONSUMER_KEY")
	if consumerKey == "" {
		fmt.Printf("LIBDNS_OVH_TEST_CONSUMER_KEY not set\n")
		return
	}

	zone := os.Getenv("LIBDNS_OVH_TEST_ZONE")
	if zone == "" {
		fmt.Printf("LIBDNS_OVH_TEST_ZONE not set\n")
		return
	}

	p := &ovh.Provider{
		Endpoint: endPoint,
		ApplicationKey: applicationKey,
		ApplicationSecret: applicationSecret,
		ConsumerKey: consumerKey,
	}

	records, err := p.GetRecords(context.TODO(), zone)
	if err != nil {
        fmt.Printf("Error: %w", err)
        return
	}

	for _, rec := range records {
		fmt.Printf("%#v", rec)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Provider

type Provider struct {
	Endpoint          string `json:"endpoint,omitempty"`
	ApplicationKey    string `json:"application_key,omitempty"`
	ApplicationSecret string `json:"application_secret,omitempty"`
	ConsumerKey       string `json:"consumer_key,omitempty"`
	// contains filtered or unexported fields
}

Provider implements the libdns interfaces for OVH.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone by updating existing records or creating new ones. It returns the records that were added during the operation.

Since OVH does not support batch operations, this implementation attempts to simulate atomic behavior. If any record creation fails, the function attempts to roll back by deleting all records that were successfully added during the operation.

If the rollback succeeds, an [AtomicErr] is returned to indicate that the zone remains in a consistent state. If the rollback itself fails (e.g., some added records could not be deleted), a non-atomic error is returned, and the zone may be left in an inconsistent state.

Similarly, after all record creations have succeeded, any obsolete records are deleted to match the desired state. If these deletions fail, a non-atomic error is returned to indicate partial success, and the caller should assume the zone may be inconsistent.

This implementation ensures that a nil error is returned **only if** all intended changes (additions and deletions) were successfully applied.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL