This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
dns.js
126 lines (102 loc) · 3.23 KB
/
dns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
var join = require('url-join');
var verymodel = require('verymodel');
var pick = require('lodash/pick');
var DNSRecord = new verymodel.Model({
id: {type: 'string', static: true, max: 32},
type: {type: 'enum', values: ['A', 'AAAA', 'CNAME', 'TXT', 'SRV', 'LOC', 'MX', 'NS', 'SPF']},
name: {type: 'string', max: 255},
content: {type: 'string'},
proxiable: {type: 'boolean', static: true},
proxied: {type: 'boolean'},
ttl: {type: 'integer'},
locked: {type: 'boolean', static: true},
zoneId: {type: 'string', static: true, max: 32, alias: 'zone_id'},
zoneName: {type: 'string', static: true, alias: 'zone_name'},
createdOn: {type: 'date', alias: 'created_on', processIn: function (val) {
return new Date(val);
}, processOut: function (val) {
return val.toISOString();
}, default: function () {
return new Date();
}, static: true},
modifiedOn: {type: 'date', alias: 'modified_on', processIn: function (val) {
return new Date(val);
}, processOut: function (val) {
return val.toISOString();
}, default: function () {
return new Date();
}, static: true},
data: {},
meta: {}
});
DNSRecord.is = function (o) {
if (o && o.__verymeta && o.__verymeta.model) {
return o.__verymeta.model === this;
}
return false;
};
function browse(z, query, options) {
options = options || {};
options.query = query;
var CF = this.constructor;
var zid = CF.Zone.is(z) ? z.id : z;
var uri = join('zones', zid, 'dns_records');
return this._got(uri, options).then(function (response) {
var records = response.body.result.map(function (rr) {
return DNSRecord.create(rr);
});
return this._paginateResponse(records, response.body.result_info);
}.bind(this));
}
function read(did, z, options) {
var CF = this.constructor;
var zid;
if (!zid && CF.Zone.is(z)) {
zid = z.id;
} else {
zid = z;
}
var uri = join('zones', zid, 'dns_records', did);
return this._got(uri, options).then(function (response) {
return DNSRecord.create(response.body.result);
});
}
function edit(rr, options) {
options = options || {};
var did = rr.id;
var zid = rr.zoneId;
var uri = join('zones', zid, 'dns_records', did);
options.method = 'PUT';
options.body = JSON.stringify(rr.toJSON({useAliases: true}));
return this._got(uri, options).then(function (response) {
return DNSRecord.create(response.body.result);
});
}
function add(rr, options) {
options = options || {};
var zid = rr.zoneId;
var uri = join('zones', zid, 'dns_records');
var body = pick(rr.toJSON({useAliases: true}), ['type', 'name', 'content', 'ttl']);
options.method = 'POST';
options.body = JSON.stringify(body);
return this._got(uri, options).then(function (response) {
return DNSRecord.create(response.body.result);
});
}
function remove(rr, options) {
options = options || {};
var did = rr.id;
var zid = rr.zoneId;
var uri = join('zones', zid, 'dns_records', did);
options.method = 'DELETE';
return this._got(uri, options).then(function (response) {
return response.body.result;
});
}
module.exports.browse = browse;
module.exports.read = read;
module.exports.edit = edit;
module.exports.add = add;
module.exports.delete = remove;
module.exports.DNSRecord = DNSRecord;