googleclouddns

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: MIT Imports: 8 Imported by: 1

README

Google Cloud DNS for libdns

godoc reference

This package implements the libdns interfaces for Google Cloud.

Authenticating

The googleclouddns package will authenticate using the supported authentication methods found in the google-cloud-go library:

  • the environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to a service account file
  • ServiceAccountJSON (json:"gcp_application_default")
    • The path to a service account JSON file

The package also requires the project where the Google Cloud DNS zone exists

  • Project (json:"gcp_project")
    • The ID of the GCP Project

Google Cloud DNS for libdns

Go Reference

This package implements the libdns interfaces for Google Cloud DNS, allowing you to manage DNS records.

Example

Here's a minimal example of how to get all your DNS records using this libdns provider:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/libdns/googleclouddns"
)

// main shows how libdns works with Google Cloud DNS.
//
// In this example, the project where the Cloud DNS zone exists is passed 
// as an environment variable. Auth data is determined through normal 
// Google Cloud Go API sources.
func main() {
	// Create new provider instance
	googleProvider := googleclouddns.Provider{
		Project: os.Getenv("GCP_PROJECT"),
	}
	zone := `example.localhost`

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

Note: The Google Cloud DNS API returns 1-n values for each Google DNS recordset. This is converted to a slice of libdns.Records each with the same name but unique values.

This also applies to AppendRecords and SetRecords. If multiple fields are desired for a Google Cloud DNS entry, pass a slice of libdns.Record entries into those functions and they will be added to the Google DNS record in the order of the slice.

Testing

Testing relies on the Google httpreplay package. If an updated request to the Google API servers is required, you can do the following:

  • install the Google Cloud SDK
  • generate application default credentials: gcloud auth application-default login
  • delete the appropriate JSON file in the replay directory
  • rerun that test step, this will give you a fresh JSON file for that test

Documentation

Overview

Package googleclouddns implements a DNS record management client compatible with the libdns interfaces for Google Cloud DNS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	Project            string `json:"gcp_project,omitempty"`
	ServiceAccountJSON string `json:"gcp_application_default,omitempty"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with Google Cloud 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. 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.

Jump to

Keyboard shortcuts

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