Constructor

Zone

new Zone()

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();

const zone = dns.zone('zone-id');

Properties

baseUrl

string

Default value
"/changes"

baseUrl

string

Default value
"/managedZones"

id

string

metadata

object

name

string

Methods

addRecords

addRecords(record, callback) returns Promise containing ZoneAddRecordsResponse

Add records to this zone. This is a convenience wrapper around Zone#createChange.

Parameter

record

(Record or Array of Record)

The Record object(s) to add.

callback

Optional

ZoneAddRecordsCallback

Callback function.

See also

ManagedZones: create API Documentation

Returns

Promise containing ZoneAddRecordsResponse 

change

change(id) returns Change

Create a reference to a Change object in this zone.

Parameter

id

string

The change id.

Returns

Change 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');
const change = zone.change('change-id');

create

create(metadata, callback) returns Promise containing CreateZoneResponse

Create a zone.

Parameter

metadata

Optional

CreateZoneRequest

Metadata to set for the zone.

callback

Optional

CreateZoneCallback

Callback function.

Returns

Promise containing CreateZoneResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();

const config = {
  dnsName: 'example.com.',
  // ...
};

zone.create(config, (err, zone, apiResponse) => {
  if (!err) {
    // The zone was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.create(config).then((data) => {
  const zone = data[0];
  const apiResponse = data[1];
});

createChange

createChange(config, callback) returns Promise containing CreateChangeResponse

Create a change of resource record sets for the zone.

Parameter

config

CreateChangeRequest

The configuration object.

callback

Optional

CreateChangeCallback

Callback function.

See also

ManagedZones: create API Documentation

Returns

Promise containing CreateChangeResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

const oldARecord = zone.record('a', {
  name: 'example.com.',
  data: '1.2.3.4',
  ttl: 86400
});

const newARecord = zone.record('a', {
  name: 'example.com.',
  data: '5.6.7.8',
  ttl: 86400
});

const config = {
  add: newARecord,
  delete: oldARecord
};

zone.createChange(config, (err, change, apiResponse) => {
  if (!err) {
    // The change was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createChange(config).then((data) => {
  const change = data[0];
  const apiResponse = data[1];
});

empty

empty(callback) returns Promise containing ZoneEmptyResponse

Emptying your zone means leaving only 'NS' and 'SOA' records. This method will first fetch the non-NS and non-SOA records from your zone using Zone#getRecords, then use Zone#createChange to create a deletion change.

Parameter

callback

Optional

ZoneEmptyCallback

Callback function.

See also

ManagedZones: create API Documentation

Returns

Promise containing ZoneEmptyResponse 

exists

exists(callback) returns Promise containing ZoneExistsResponse

Check if the zone exists.

Parameter

callback

Optional

ZoneExistsCallback

Callback function.

Returns

Promise containing ZoneExistsResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

zone.exists((err, exists) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.exists().then((data) => {
  const exists = data[0];
});

export

export(localPath, callback) returns Promise containing ZoneExportResponse

Provide a path to a zone file to copy records into the zone.

Parameter

localPath

string

The fully qualified path to the zone file.

callback

Optional

ZoneExportCallback

Callback function.

See also

ResourceRecordSets: list API Documentation

Returns

Promise containing ZoneExportResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

const zoneFilename = '/Users/stephen/zonefile.zone';

zone.export(zoneFilename, err => {
  if (!err) {
    // The zone file was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.export(zoneFilename).then(() => {});

get

get(options, callback) returns Promise containing GetZoneResponse

Get a zone if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Parameter

options

Optional

options

Configuration object.

Values in options have the following properties:

Parameter

autoCreate

Optional

boolean

Automatically create the object if it does not exist.

callback

Optional

GetZoneCallback

Callback function.

Returns

Promise containing GetZoneResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

zone.get((err, zone, apiResponse) => {
  // `zone.metadata` has been populated.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.get().then(data => {
  const zone = data[0];
  const apiResponse = data[1];
});

getChangesStream

getChangesStream(query) returns ReadableStream

Get the list of Change objects associated with this zone as a readable object stream.

Parameter

query

Optional

GetChangesRequest

Query object for listing changes.

Returns

ReadableStream 

A readable stream that emits Change instances.

Example

zone.getChangesStream()
  .on('error', console.error)
  .on('data', change => {
    // change is a Change object.
  })
  .on('end', () => {
    // All changes retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getChangesStream()
  .on('data', function(change) {
    this.end();
  });

getMetadata

getMetadata(callback) returns Promise containing GetZoneMetadataResponse

Get the metadata for the zone.

Parameter

callback

Optional

GetZoneMetadataCallback

Callback function.

See also

ManagedZones: get API Documentation

Returns

Promise containing GetZoneMetadataResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

zone.getMetadata((err, metadata, apiResponse) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getMetadata().then((data) => {
  const metadata = data[0];
  const apiResponse = data[1];
});

getRecordsStream

getRecordsStream(query) returns ReadableStream

Get the list of {module:dns/record} objects for this zone as a readable object stream.

Parameter

query

Optional

GetRecordsRequest

Query object for listing records.

Returns

ReadableStream 

A readable stream that emits Record instances.

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

zone.getRecordsStream()
  .on('error', console.error)
  .on('data', record => {
    // record is a Record object.
  })
  .on('end', () => {
    // All records retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getRecordsStream()
  .on('data', function(change) {
    this.end();
  });

import

import(localPath, callback) returns Promise containing ZoneImportResponse

Copy the records from a zone file into this zone.

Parameter

localPath

string

The fully qualified path to the zone file.

callback

Optional

ZoneImportCallback

Callback function.

See also

ManagedZones: create API Documentation

Returns

Promise containing ZoneImportResponse 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();
const zone = dns.zone('zone-id');

const zoneFilename = '/Users/dave/zonefile.zone';

zone.import(zoneFilename, (err, change, apiResponse) => {
  if (!err) {
    // The change was created successfully.
  }
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.import(zoneFilename).then(data => {
  const change = data[0];
  const apiResponse = data[1];
});

record

record(type, metadata) returns Record

A Record object can be used to construct a record you want to add to your zone, or to refer to an existing one.

Note that using this method will not itself make any API requests. You will use the object returned in other API calls, for example to add a record to your zone or to delete an existing one.

Parameter

type

string

The type of record to construct or the type of record you are referencing.

metadata

object

The metadata of this record.

Values in metadata have the following properties:

Parameter

name

string

The name of the record, e.g. www.example.com..

data

Array of string

Defined in RFC 1035, section 5 and RFC 1034, section 3.6.1.

ttl

number

Seconds that the resource is cached by resolvers.

Returns

Record 

Example

const {DNS} = require('@google-cloud/dns');
const dns = new DNS();

const zone = dns.zone('zone-id');

//-
// Reference an existing record to delete from your zone.
//-
const oldARecord = zone.record('a', {
  name: 'example.com.',
  data: '1.2.3.4',
  ttl: 86400
});

//-
// Construct a record to add to your zone.
//-
const newARecord = zone.record('a', {
  name: 'example.com.',
  data: '5.6.7.8',
  ttl: 86400
});

//-
// Use these records together to create a change.
//-
zone.createChange({
  add: newARecord,
  delete: oldARecord
}, (err, change, apiResponse) => {});