Skip to content

Commit 3a6bf46

Browse files
Add Google Cloud DNS
1 parent 7efd2a8 commit 3a6bf46

File tree

19 files changed

+3722
-1
lines changed

19 files changed

+3722
-1
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To run the system tests, first create and configure a project in the Google Deve
2121

2222
- **GCLOUD_TESTS_PROJECT_ID**: Developers Console project's ID (e.g. bamboo-shift-455)
2323
- **GCLOUD_TESTS_KEY**: The path to the JSON key file.
24+
- ***GCLOUD_TESTS_DNS_DOMAIN*** (*optional*): A domain you own managed by Google Cloud DNS (expected format: `'gcloud-node.com.'`).
2425

2526
Install the [gcloud command-line tool][gcloudcli] to your machine and use it to create the indexes used in the datastore system tests with indexes found in `system-test/data/index/yaml`:
2627

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This client supports the following Google Cloud Platform services:
1212

1313
* [Google BigQuery](#google-bigquery)
1414
* [Google Cloud Datastore](#google-cloud-datastore)
15+
* [Google Cloud DNS](#google-cloud-dns)
1516
* [Google Cloud Storage](#google-cloud-storage)
1617
* [Google Cloud Pub/Sub](#google-cloud-pubsub-beta) (Beta)
1718
* [Google Cloud Search](#google-cloud-search-alpha) (Alpha)
@@ -165,6 +166,46 @@ dataset.save({
165166
```
166167

167168

169+
## Google Cloud DNS
170+
171+
- [API Documentation][gcloud-dns-docs]
172+
- [Official Documentation][cloud-dns-docs]
173+
174+
#### Preview
175+
176+
```js
177+
var gcloud = require('gcloud');
178+
179+
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
180+
// global basis (see Authorization section above).
181+
182+
var dns = gcloud.dns({
183+
keyFilename: '/path/to/keyfile.json',
184+
projectId: 'my-project'
185+
});
186+
187+
// Create a managed zone.
188+
dns.createZone('my-new-zone', {
189+
dnsName: 'my-domain.com.'
190+
}, function(err, zone) {});
191+
192+
// Reference an existing zone.
193+
var zone = dns.zone('my-existing-zone');
194+
195+
// Create an NS record.
196+
var nsRecord = zone.record('ns', {
197+
ttl: 86400,
198+
name: 'my-domain.com.',
199+
data: 'ns-cloud1.googledomains.com.'
200+
});
201+
202+
zone.addRecord(nsRecord, function(err, change) {});
203+
204+
// Create a zonefile from the records in your zone.
205+
zone.export('/zonefile.zone', function(err) {});
206+
```
207+
208+
168209
## Google Cloud Storage
169210

170211
- [API Documentation][gcloud-storage-docs]
@@ -319,6 +360,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
319360
[gcloud-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs
320361
[gcloud-bigquery-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/bigquery
321362
[gcloud-datastore-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/datastore
363+
[gcloud-dns-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/dns
322364
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub
323365
[gcloud-search-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/search
324366
[gcloud-storage-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/storage
@@ -339,6 +381,8 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
339381
[cloud-datastore-docs]: https://cloud.google.com/datastore/docs
340382
[cloud-datastore-activation]: https://cloud.google.com/datastore/docs/activate
341383

384+
[cloud-dns-docs]: https://cloud.google.com/dns/docs
385+
342386
[cloud-pubsub-docs]: https://cloud.google.com/pubsub/docs
343387

344388
[cloud-search-docs]: https://cloud.google.com/search/

docs/site/components/docs/docs-values.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ angular.module('gcloud.docs')
7373
]
7474
},
7575

76+
dns: {
77+
title: 'DNS',
78+
_url: '{baseUrl}/dns',
79+
pages: [
80+
{
81+
title: 'Zone',
82+
url: '/zone'
83+
},
84+
{
85+
title: 'Record',
86+
url: '/record'
87+
},
88+
{
89+
title: 'Change',
90+
url: '/change'
91+
}
92+
]
93+
},
94+
7695
pubsub: {
7796
title: 'PubSub',
7897
_url: '{baseUrl}/pubsub',
@@ -158,6 +177,9 @@ angular.module('gcloud.docs')
158177
'>=0.10.0': ['bigquery'],
159178

160179
// introduce search api.
161-
'>=0.16.0': ['search']
180+
'>=0.16.0': ['search'],
181+
182+
// introduce dns api.
183+
'>=0.17.0': ['dns']
162184
}
163185
});

lib/common/util.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,55 @@ function getType(value) {
249249
return Object.prototype.toString.call(value).match(/\s(\w+)\]/)[1];
250250
}
251251

252+
/**
253+
* Iterate through an array, invoking a function by the provided name.
254+
*
255+
* @param {string} name - The name of the function that exists as a property on
256+
* each member of the iterated array.
257+
* @return {function}
258+
*
259+
* @example
260+
* var people = [
261+
* {
262+
* getName: function() { return 'Stephen'; }
263+
* },
264+
* {
265+
* getName: function() { return 'Dave'; }
266+
* }
267+
* };
268+
*
269+
* var names = people.map(exec('getName'));
270+
* // names = [ 'Stephen', 'Dave' ]
271+
*
272+
* //-
273+
* // Aguments can also be provided.
274+
* //-
275+
* var people = [
276+
* {
277+
* getName: function(prefix) { return prefix + ' Stephen'; }
278+
* },
279+
* {
280+
* getName: function(prefix) { return prefix + ' Dave'; }
281+
* }
282+
* ];
283+
*
284+
* var names = people.map(exec('getName', 'Mr.'));
285+
* // names = [ 'Mr. Stephen', 'Mr. Dave' ];
286+
*/
287+
function exec(name) {
288+
var initialArguments = [].slice.call(arguments, 1);
289+
290+
return function(item) {
291+
if (util.is(item[name], 'function')) {
292+
var invokedArguments = [].slice.call(arguments, 1);
293+
return item[name].apply(item, initialArguments.concat(invokedArguments));
294+
}
295+
return item[name];
296+
};
297+
}
298+
299+
util.exec = exec;
300+
252301
/**
253302
* Used in an Array iterator usually, this will return the value of a property
254303
* in an object by its name.

lib/dns/change.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*!
2+
* Copyright 2014 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*!
18+
* @module dns/change
19+
*/
20+
21+
'use strict';
22+
23+
/**
24+
* @constructor
25+
* @alias module:dns/change
26+
*
27+
* @param {module:dns/zone} zone - The parent zone object.
28+
* @param {string} id - ID of the change.
29+
*
30+
* @example
31+
* var gcloud = require('gcloud');
32+
*
33+
* var dns = gcloud.dns({
34+
* keyFilename: '/path/to/keyfile.json',
35+
* projectId: 'grape-spaceship-123'
36+
* });
37+
*
38+
* var zone = dns.zone('zone-id');
39+
* var change = zone.change('change-id');
40+
*/
41+
function Change(zone, id) {
42+
this.zoneName = zone.name;
43+
this.id = id;
44+
45+
this.metadata = {};
46+
this.makeReq_ = zone.dns.makeReq_.bind(zone.dns);
47+
}
48+
49+
/**
50+
* Get the metadata for the change in the zone.
51+
*
52+
* @param {function} callback - The callback function.
53+
* @param {?error} callback.err - An API error.
54+
* @param {?object} callback.metadata - Metadata of the change from the API.
55+
* @param {object} callback.apiResponse - Raw API response.
56+
*
57+
* @example
58+
* change.getMetadata(function(err, metadata, apiResponse) {
59+
* if (!err) {
60+
* // metadata = {
61+
* // kind: 'dns#change',
62+
* // additions: [{...}],
63+
* // deletions: [{...}],
64+
* // startTime: '2015-07-21T14:40:06.056Z',
65+
* // id: '1',
66+
* // status: 'done'
67+
* // }
68+
* }
69+
* });
70+
*/
71+
Change.prototype.getMetadata = function(callback) {
72+
var self = this;
73+
var path = '/managedZones/' + this.zoneName + '/changes/' + this.id;
74+
75+
this.makeReq_('GET', path, null, null, function(err, resp) {
76+
if (err) {
77+
callback(err, null, resp);
78+
return;
79+
}
80+
81+
self.metadata = resp;
82+
83+
callback(null, self.metadata, resp);
84+
});
85+
};
86+
87+
module.exports = Change;

0 commit comments

Comments
 (0)