infomaniak

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 13 Imported by: 3

README

infomaniak for libdns

Go Reference

This package implements the libdns interfaces for infomaniak based on their API reference, allowing you to manage DNS records.

Code example

import "github.com/libdns/infomaniak"
provider := &infomaniak.Provider{
    APIToken:  "YOUR_API_TOKEN"
}

Create Your API Token

Please login to your infomaniak account and then navigate here to issue your API access token. The scope of your token has to include "domain:read", "dns:read" and "dns:write".

⚠ All releases up to and including v0.1.3 use an unsupported API version and require a different scope for your token. If you use any of these releases, please make sure the "domain" scope is include for your token instead of the ones listed above.

Development

Setup

The repository contains configurations for a Visual Studio Code dev container. Please install the Visual Studio Code extension ms-vscode-remote.remote-containers to make use of it.

Testing With Caddy

If you use the provided Dev Container, you can easily test your changes directly with caddy. Start by replacing the three placeholders for email, API token and domain in .devcontainer/.caddyfile (make sure to never commit these changes). You can then use the commands below directly in your Dev Container.

After each change, you have to rebuild caddy with the following command - make sure to enter a valid version of caddy: xcaddy build <caddy_version> --with dns.providers.infomaniak=/workspaces/caddy-dns-infomaniak --replace github.com/libdns/infomaniak=/workspaces/libdns-infomaniak --output /workspaces/caddy/caddy

Run caddy with the following command and monitor the output: /workspaces/caddy/caddy run --config /workspaces/caddy/.caddyfile

If caddy managed to successfully issue the certificate and you would like to test from scratch again, you have to delete the previously issued certificate by running rm -R /home/vscode/.local/share/caddy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// infomaniak API token
	Token string

	// http client used for requests
	HttpClient *http.Client
}

Client that abstracts and calls infomaniak API

func (*Client) CreateOrUpdateRecord

func (c *Client) CreateOrUpdateRecord(ctx context.Context, zone string, record IkRecord) (*IkRecord, error)

CreateOrUpdateRecord creates a record if its Id property is not set, otherwise it updates the record

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(ctx context.Context, zone string, recordId string) error

DeleteRecord deletes an existing dns record for a given zone

func (*Client) GetDnsRecordsForZone

func (c *Client) GetDnsRecordsForZone(ctx context.Context, zone string) ([]IkRecord, error)

GetDnsRecordsForZone loads all dns records for a given zone

func (*Client) GetFqdnOfZoneForDomain added in v0.2.0

func (c *Client) GetFqdnOfZoneForDomain(ctx context.Context, domain string) (string, error)

GetFqdnOfZoneForDomain returns the FQDN of the zone managed by infomaniak

type IkClient

type IkClient interface {
	// DeleteRecord deletes record with given ID
	DeleteRecord(ctx context.Context, zone string, id string) error

	// CreateOrUpdateRecord creates record if it has no ID property set, otherwise it updates the record with the given ID
	CreateOrUpdateRecord(ctx context.Context, zone string, record IkRecord) (*IkRecord, error)

	// GetDnsRecordsForZone returns all records of the given zone
	GetDnsRecordsForZone(ctx context.Context, zone string) ([]IkRecord, error)

	// GetFqdnOfZoneForDomain returns the FQDN of the zone managed by infomaniak
	GetFqdnOfZoneForDomain(ctx context.Context, domain string) (string, error)
}

IkClient interface to abstract infomaniak client

type IkIntValueAttribute added in v0.2.0

type IkIntValueAttribute struct {
	// Attribute value
	Value int `json:"value,omitempty"`
	// Human readable value of attribute
	Label string `json:"label,omitempty"`
}

type IkRecord

type IkRecord struct {
	// ID of this record on infomaniak's side
	ID int `json:"id,omitempty"`

	// Type of this record
	Type string `json:"type,omitempty"`

	// Absolute Source / Name
	Source string `json:"source,omitempty"`

	// Value of this record
	Target string `json:"target,omitempty"`

	// TTL in seconds
	TtlInSec int `json:"ttl,omitempty"`

	// Record Description
	Description IkRecordDescription `json:"description,omitempty"`
}

IkRecord infomaniak API record return type

func ToInfomaniakRecord

func ToInfomaniakRecord(libdnsRec libdns.Record, zoneMapping *ZoneMapping) IkRecord

ToInfomaniakRecord maps a libdns record to a infomaniak dns record

func (*IkRecord) ToLibDnsRecord

func (ikr *IkRecord) ToLibDnsRecord(zoneMapping *ZoneMapping) (libdns.Record, error)

ToLibDnsRecord maps a infomaniak dns record to a libdns record

type IkRecordDescription added in v0.2.0

type IkRecordDescription struct {
	// Only available for SRV and MX records
	Priority IkIntValueAttribute `json:"priority,omitempty"`

	// Only available for SRV records
	Port IkIntValueAttribute `json:"port,omitempty"`

	// Only available for SRV records
	Weight IkIntValueAttribute `json:"weight,omitempty"`

	// Only available for SRV and DNSKEY records
	Protocol IkStringValueAttribute `json:"protocol,omitempty"`

	// Only available for CAA and DNSKEY records
	Flags IkIntValueAttribute `json:"flags,omitempty"`

	// Only available for CAA records
	Tag IkStringValueAttribute `json:"tag,omitempty"`
}

type IkResponse

type IkResponse struct {
	// Result of the API call: either "success" or "error"
	Result string `json:"result"`

	// Data is set if API call was successful and contains the actual response
	Data json.RawMessage `json:"data,omitempty"`

	// Error is set if the API call failed and contains all errors that occurred
	Error json.RawMessage `json:"error,omitempty"`
}

IkResponse infomaniak API response

type IkStringValueAttribute added in v0.2.0

type IkStringValueAttribute struct {
	// Attribute value
	Value string `json:"value,omitempty"`
	// Human readable value of attribute
	Label string `json:"label,omitempty"`
}

type IkZone added in v0.2.0

type IkZone struct {
	// Zone's FQDN on infomaniak's side
	Fqdn string `json:"fqdn"`
}

IkZone infomaniak API zone return type

type Provider

type Provider struct {
	//infomaniak API token
	APIToken string `json:"api_token,omitempty"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with infomaniak.

func (*Provider) AppendRecords

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

AppendRecords creates the inputted records in the given zone and returns the populated records that were created. It never changes existing records.

Therefore, it makes little sense to use this method with CNAME-type records since if there are no existing records with the same name, it behaves the same as libdns.RecordSetter.SetRecords, and if there are existing records with the same name, it will either fail or leave the zone in an invalid state.

func (*Provider) DeleteRecords

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

DeleteRecords deletes the given records from the zone if they exist in the zone and exactly match the input. If the input records do not exist in the zone, they are silently ignored. DeleteRecords returns only the the records that were deleted, and does not return any records that were provided in the input but did not exist in the zone.

DeleteRecords only deletes records from the zone that *exactly* match the input records—that is, the name, type, TTL, and value all must be identical to a record in the zone for it to be deleted.

As a special case, you may leave any of the fields libdns.Record.Type, libdns.Record.TTL, or libdns.Record.Value empty ("", 0, and "" respectively). In this case, DeleteRecords will delete any records that match the other fields, regardless of the value of the fields that were left empty. Note that this behavior does *not* apply to the libdns.Record.Name field, which must always be specified.

func (*Provider) GetRecords

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

GetRecords returns all the records in the DNS zone.

DNSKEY and DS are DNSSEC-related record types that are included in the output.

func (*Provider) SetRecords

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

SetRecords updates the zone so that the records described in the input are reflected in the output.

For any (name, type) pair in the input, SetRecords ensures that the only records in the output zone with that (name, type) pair are those that were provided in the input.

In RFC 9499 terms, SetRecords appends, modifies, or deletes records in the zone so that for each RRset in the input, the records provided in the input are the only members of their RRset in the output zone.

DNSSEC-related records of type DS are supported.

Calls to SetRecords are not to be presumed atomic; that is, if err == nil, then all of the requested changes were made; if err != nil, then some changes might have been applied already. In other words, errors may result in partial changes to the zone.

If SetRecords is used to add a CNAME record to a name with other existing non-DNSSEC records, implementations may either fail with an error, add the CNAME and leave the other records in place (in violation of the DNS standards), or add the CNAME and remove the other preexisting records. Therefore, users should proceed with caution when using SetRecords with CNAME records.

type ZoneMapping added in v0.2.0

type ZoneMapping struct {
	// Zone that is mangaged by infomaniak
	InfomaniakManagedZone string `json:"fqdn"`

	// Zone that is provided by libdns
	LibDnsZone string
}

ZoneMapping represents input zone coming from the caller and the zone that is actually managed by infomaniak

func (*ZoneMapping) ToRelativeInfomaniakName added in v0.2.0

func (zoneMapping *ZoneMapping) ToRelativeInfomaniakName(relativeName string) string

ToRelativeInfomaniakName converts a relative name from input zone of the libdns caller to the infomaniak managed zone

func (*ZoneMapping) ToRelativeLibdnsName added in v0.2.0

func (zoneMapping *ZoneMapping) ToRelativeLibdnsName(relativeName string) string

ToRelativeLibdnsName converts a relative name from the infomaniak managed zone to the input zone of the libdns caller

Jump to

Keyboard shortcuts

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