Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,24 @@ class Request {

_requestOptions(opts) {
let parsedUrl = url.parse(opts.url);
const hasBody = opts.body !== undefined && opts.body !== null;

return {
const request = {
host: parsedUrl.host,
url: opts.url,
method: opts.method ? opts.method.toUpperCase() : 'GET',
path: parsedUrl.path,
headers: {
'Content-Type': 'application/json'
},
body: opts.body ? JSON.stringify(opts.body) : ''
service: this.config.service || 'VinylDNS',
region: this.config.region || 'us-east-1',
headers: {},
body: hasBody ? JSON.stringify(opts.body) : undefined
};

if (hasBody) {
request.headers['Content-Type'] = 'application/json';
}

return request;
}

_request(opts) {
Expand All @@ -67,7 +74,9 @@ class Request {
});

// axios expects a 'data'; aws4.sign expects a 'body'
signedReq.data = opts.body;
if (opts.body !== undefined) {
signedReq.data = opts.body;
}

return new Promise((fulfill, reject) => {
axios(signedReq)
Expand Down
118 changes: 118 additions & 0 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ class Urls {
return `${this.zonesBase()}/name/${name}`;
}

zoneDetails(id) {
return `${this.zone(id)}/details`;
}

zoneBackendIds() {
return `${this.zonesBase()}/backendids`;
}

zoneChangesFailure(query) {
return `${this.apiUrl}/metrics/health/zonechangesfailure${this.queryString(query)}`;
}

zonesDeletedChanges(query) {
return `${this.zonesBase()}/deleted/changes${this.queryString(query)}`;
}

zoneAclRules(id) {
return `${this.zone(id)}/acl/rules`;
}

syncZone(id) {
return `${this.zone(id)}/sync`;
}
Expand All @@ -55,6 +75,18 @@ class Urls {
return `${this.recordSetsBase(details.zoneId)}/${details.id || details.recordSetId}`;
}

recordSetCount(zoneId) {
return `${this.zone(zoneId)}/recordsetcount`;
}

recordSetChangeHistory(query) {
return `${this.apiUrl}/recordsetchange/history${this.queryString(query)}`;
}

recordSetChangesFailure(zoneId, query) {
return `${this.apiUrl}/metrics/health/zones/${zoneId}/recordsetchangesfailure${this.queryString(query)}`;
}

recordSetChanges(zoneId, query) {
return `${this.zone(zoneId)}/recordsetchanges${this.queryString(query)}`;
}
Expand All @@ -71,6 +103,18 @@ class Urls {
return `${this.batchChanges()}/${id}`;
}

batchChangeApprove(id) {
return `${this.batchChange(id)}/approve`;
}

batchChangeReject(id) {
return `${this.batchChange(id)}/reject`;
}

batchChangeCancel(id) {
return `${this.batchChange(id)}/cancel`;
}

groupsBase() {
return `${this.apiUrl}/groups`;
}
Expand All @@ -87,6 +131,14 @@ class Urls {
return `${this.group(id)}/activity${this.queryString(query)}`;
}

groupChange(id) {
return `${this.groupsBase()}/change/${id}`;
}

groupValidDomains() {
return `${this.groupsBase()}/valid/domains`;
}

getGroupAdmins(id) {
return `${this.group(id)}/admins`;
}
Expand All @@ -95,6 +147,72 @@ class Urls {
return `${this.group(id)}/members${this.queryString(query)}`;
}

user(id) {
return `${this.apiUrl}/users/${id}`;
}

userLock(id) {
return `${this.user(id)}/lock`;
}

userUnlock(id) {
return `${this.user(id)}/unlock`;
}

ping() {
return `${this.apiUrl}/ping`;
}

health() {
return `${this.apiUrl}/health`;
}

color() {
return `${this.apiUrl}/color`;
}

metricsPrometheus(names) {
if (!names || names.length === 0) {
return `${this.apiUrl}/metrics/prometheus`;
}

const query = names.map(name => `name=${name}`).join('&');
return `${this.apiUrl}/metrics/prometheus?${query}`;
}

status() {
return `${this.apiUrl}/status`;
}

statusUpdate(processingDisabled) {
return `${this.apiUrl}/status?processingDisabled=${processingDisabled}`;
}

recordSetsGlobal(query) {
if (!query) {
return `${this.apiUrl}/recordsets`;
}

let params = [];
if (query.recordTypeFilter) {
const recordTypes = Array.isArray(query.recordTypeFilter)
? query.recordTypeFilter
: [query.recordTypeFilter];
recordTypes.forEach(recordType => {
params.push(`recordTypeFilter[]=${recordType}`);
});
}

Object.keys(query).forEach(key => {
if (key === 'recordTypeFilter') {
return;
}
params.push(`${key}=${query[key]}`);
});

return `${this.apiUrl}/recordsets${params.length ? '?' + params.join('&') : ''}`;
}

queryString(obj) {
if (obj) {
return '?' + Object.keys(obj).map(key => `${key}=${obj[key]}`).join('&');
Expand Down
Loading
Loading