azure

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 10 Imported by: 0

README

Azure DNS for libdns

This package implements the libdns interfaces for the Azure DNS API.

Authenticating

This package supports authentication using the Client Credentials (Azure AD Application ID and Secret) through azure-sdk-for-go.

You will need to create a service principal using Azure CLI or Azure Portal, and assign the DNS Zone Contributor role to the service principal for the DNS zones that you want to manage.

Then keep the following information to pass to the Provider struct fields for authentication:

  • TenantId (json:"tenant_id")
    • [Azure Active Directory] > [Properties] > [Tenant ID]
  • ClientId (json:"client_id")
    • [Azure Active Directory] > [App registrations] > Your Application > [Application ID]
  • ClientSecret (json:"client_secret")
    • [Azure Active Directory] > [App registrations] > Your Application > [Certificates & secrets] > [Client secrets] > [Value]
  • SubscriptionId (json:"subscription_id")
    • [DNS zones] > Your Zone > [Subscription ID]
  • ResourceGroupName (json:"resource_group_name")
    • [DNS zones] > Your Zone > [Resource group]

Example

Here's a minimal example of how to get all your DNS records using this libdns provider (see _example/main.go)

package main

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

	"github.com/libdns/azure"
	"github.com/libdns/libdns"
)

// main shows how libdns works with Azure DNS.
//
// In this example, the information required for authentication is passed as environment variables.
func main() {

	// Create new provider instance
	provider := azure.Provider{
		TenantId:          os.Getenv("AZURE_TENANT_ID"),
		ClientId:          os.Getenv("AZURE_CLIENT_ID"),
		ClientSecret:      os.Getenv("AZURE_CLIENT_SECRET"),
		SubscriptionId:    os.Getenv("AZURE_SUBSCRIPTION_ID"),
		ResourceGroupName: os.Getenv("AZURE_RESOURCE_GROUP_NAME"),
	}
	zone := os.Getenv("AZURE_DNS_ZONE_FQDN")

	// List existing records
	fmt.Printf("List existing records\n")
	currentRecords, err := provider.GetRecords(context.TODO(), zone)
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}
	for _, record := range currentRecords {
		fmt.Printf("Exists: %v\n", record)
	}
}

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
}

Client is an abstraction of RecordSetsClient for Azure DNS

type Provider

type Provider struct {
	TenantId          string `json:"tenant_id,omitempty"`
	ClientId          string `json:"client_id,omitempty"`
	ClientSecret      string `json:"client_secret,omitempty"`
	SubscriptionId    string `json:"subscription_id,omitempty"`
	ResourceGroupName string `json:"resource_group_name,omitempty"`
	// contains filtered or unexported fields
}

Provider implements the libdns interfaces for Azure DNS

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. If a record does not have an ID, it will be looked up. 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, either by updating existing records or creating new ones. It returns the updated records.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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