Skip to content

Commit 52b0271

Browse files
committed
Added domain reset and domain push functionality.
Cleaned up domain and domain record methods. Updated .npmignore. Updated readme and command reference.
1 parent 165450b commit 52b0271

7 files changed

Lines changed: 189 additions & 108 deletions

File tree

.npmignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ node_modules/
88
test/
99

1010
# Tools #
11-
tools/
11+
tools/
12+
13+
# Ignore azure stuff #
14+
features
15+
lib/commands_azure
16+
scripts_azure
17+
test_azure

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ See the [command reference][3] for complete planned command structure.
2323
* Show details for a specific domain in your account `(command: dnsimple domain show)`
2424
* Add a domain to your account `(command: dnsimple domain add)`
2525
* Delete a domain from your account `(command: dnsimple domain delete)`
26+
* Reset a domain token `(command: dnsimple domain reset)`
27+
* Push one or more domains from the current account to another `(command: dnsimple domain push)`
2628
* Check availability of one more domains `(command: dnsimple domain check)`
2729
* Records: `(command: dnsimple domain record)`
2830
* Show DNS Records for a specific domain `(command: dnsimple domain record list)`

command-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
|- delete [domain]
2424
--------------
2525
|- reset [domain]
26-
|- push [domain] -email -contact (Move the domain to another account)
26+
|- push [-u --useremail <useremail>] [-c --contactid <contactid>] [domain] (Move a domain to another account)
2727
--------------
2828
|- check [domains] (Check availability of one or more domains)
2929
|- register [domain]

lib/commands/domain/domain._js

Lines changed: 127 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ exports.init = function (cli) {
6262
};
6363

6464
context.skipCache = true;
65-
var domains = domain.doDomainsGet(context, _);
65+
var domains = domain.client(context).getDomains(context, _);
6666

6767
if (name) {
6868

@@ -86,7 +86,6 @@ exports.init = function (cli) {
8686
cli.interaction.formatOutput(domains, function (data) {
8787
if (data.length > 0) {
8888
log.table(data, function (row, item) {
89-
//var parsedName = WebsitesClient.parseSiteName(item.name);
9089
row.cell($('Name'), item.name);
9190
row.cell($('Records'), item.record_count);
9291
row.cell($('Expires'), item.expires_on);
@@ -112,7 +111,7 @@ exports.init = function (cli) {
112111
self.lookupDomainName(context, _);
113112

114113
context.skipCache = true;
115-
var d = domain.doDomainGet(context, _);
114+
var d = domain.client(context).getDomain(context, _);
116115

117116
var format = [
118117
[$('Id'), 'id'],
@@ -159,7 +158,7 @@ exports.init = function (cli) {
159158
throw new Error(util.format($('Can\'t add domain %s because it already exists.'), context.domain.name));
160159
}
161160

162-
var d = domain.doDomainAdd(context, _);
161+
var d = domain.client(context).addDomain(context, _);
163162

164163
var format = [
165164
[$('Id'), 'id'],
@@ -221,83 +220,143 @@ exports.init = function (cli) {
221220
var self = this;
222221
self.lookupDomainName(context, _);
223222

224-
var shouldDelete = options.quiet || cli.interaction.confirm($('This will permanently remove the domain from your account and cannot be undone. Are you sure? '), _);
225-
if (!shouldDelete) {
223+
var shouldContinue = options.quiet || cli.interaction.confirm($('This will permanently remove the domain from your account and cannot be undone. Are you sure? '), _);
224+
if (!shouldContinue) {
225+
log.warn('Domain delete cancelled.');
226226
return;
227227
}
228228

229-
return domain.doDomainDelete(context, _);
229+
return domain.client(context).deleteDomain(context, _);
230230
},
231231

232-
domain.checkCommand = function (name, options, _) {
232+
domain.resetCommand = function (name, options, _) {
233233
var context = {
234234
subscription: profile.current.getSubscription(options.subscription).id,
235235
domain: {
236236
name: name
237237
}
238238
};
239239

240-
promptForDomainName(_);
240+
var self = this;
241+
self.promptForDomainName(context, _);
241242

242243
var domains = context.domain.name.split(',');
243244
var results = [];
245+
var domainClient = domain.client(context);
246+
var shouldContinue = options.quiet || cli.interaction.confirm($('This will reset the domain token and prevent api access with the current token.\nYou will need to access the api using the new domain token.\nAre you sure? '), _);
247+
if (!shouldContinue) {
248+
log.warn('Domain token reset cancelled.');
249+
return;
250+
}
244251
if (domains.length > 1) {
245-
// var checks = [];
246-
// var contexts = [];
247-
// __.each(domains, function(d) {
248-
// contexts.push({
249-
// subscription: context.subscription,
250-
// domain: {
251-
// name: d
252-
// }
253-
// });
254-
// });
255-
256-
// __.each(contexts, function(c) {
257-
// checks.push(function(_) {
258-
// return domain.doDomainCheck(c, _);
259-
// });
260-
// });
261252

262253
results = async.map(domains, function(d, _) {
263-
domain.doDomainCheck({
254+
domainClient.resetToken({
264255
subscription: context.subscription,
265256
domain: {
266257
name: d
267258
}
268259
}, _);
269260
}, _);
270261
results = results.sort(sortByName);
271-
//results = async.parallel(checks, _);
272262
} else {
273-
results = [domain.doDomainCheck(context, _)];
263+
results = [domainClient.resetToken(context, _)];
274264
}
265+
log.info('Successfully reset domain token:');
266+
log.table(results, function (row, item) {
267+
row.cell($('Id'), item.id);
268+
row.cell($('Name'), item.name);
269+
row.cell($('Token'), item.token);
270+
});
275271

276-
var format = [
277-
[$('Name'), 'name'],
278-
[$('Status'), 'status'],
279-
[$('Price'), null, function (value) {
280-
return accounting.formatMoney(value.price, value.currency_symbol);
281-
}]
282-
];
272+
},
273+
274+
domain.pushCommand = function (useremail, contactid, name, options, _) {
275+
useremail = cli.interaction.promptIfNotGiven($('The new account\'s email address: '), useremail, _);
276+
contactid = cli.interaction.promptIfNotGiven($('The new account\'s registrant ID: '), contactid, _);
283277

284-
//log.report(format, d);
278+
var context = {
279+
subscription: profile.current.getSubscription(options.subscription).id,
280+
domain: {
281+
name: name
282+
},
283+
push: {
284+
new_user_email: useremail,
285+
contact_id: contactid
286+
}
287+
};
288+
289+
var self = this;
290+
self.promptForDomainName(context, _);
291+
292+
var domains = context.domain.name.split(',');
293+
var results = [];
294+
var domainClient = domain.client(context);
295+
var shouldContinue = options.quiet || cli.interaction.confirm($('Once a domain is pushed you will no longer be able to access it through your account.\nYou will need to access it using the new account\'s credentials.\nAre you sure? '), _);
296+
if (!shouldContinue) {
297+
log.warn('Domain push cancelled.');
298+
return;
299+
}
285300

301+
if (domains.length > 1) {
302+
303+
results = async.map(domains, function(d, _) {
304+
domainClient.pushDomain({
305+
subscription: context.subscription,
306+
domain: {
307+
name: d
308+
},
309+
push: context.push
310+
}, _);
311+
}, _);
312+
results = results.sort(sortByName);
313+
} else {
314+
results = [domainClient.pushDomain(context, _)];
315+
}
316+
log.info('Successfully pushed the following domains:');
286317
log.table(results, function (row, item) {
287-
//var parsedName = WebsitesClient.parseSiteName(item.name);
318+
row.cell($('Id'), item.id);
288319
row.cell($('Name'), item.name);
289-
row.cell($('Status'), item.status);
290-
row.cell($('Price'), accounting.formatMoney(item.price, item.currency_symbol));
320+
row.cell($('New Account'), useremail);
291321
});
292322

293-
function promptForDomainName(_) {
294-
log.silly('promptForDomainName');
295-
if (context.domain.name === undefined) {
296-
log.help($('Need a domain name'));
297-
context.domain.name = cli.interaction.prompt($('Domain: '), _);
323+
},
324+
325+
domain.checkCommand = function (name, options, _) {
326+
var context = {
327+
subscription: profile.current.getSubscription(options.subscription).id,
328+
domain: {
329+
name: name
298330
}
331+
};
332+
333+
var self = this;
334+
self.promptForDomainName(context, _);
335+
336+
var domains = context.domain.name.split(',');
337+
var results = [];
338+
var domainClient = domain.client(context);
339+
if (domains.length > 1) {
340+
341+
results = async.map(domains, function(d, _) {
342+
domainClient.checkDomain({
343+
subscription: context.subscription,
344+
domain: {
345+
name: d
346+
}
347+
}, _);
348+
}, _);
349+
results = results.sort(sortByName);
350+
} else {
351+
results = [domainClient.checkDomain(context, _)];
299352
}
300353

354+
log.table(results, function (row, item) {
355+
row.cell($('Name'), item.name);
356+
row.cell($('Status'), item.status);
357+
row.cell($('Price'), accounting.formatMoney(item.price, item.currency_symbol));
358+
});
359+
301360
},
302361

303362
domain.command('list [name]')
@@ -319,61 +378,36 @@ exports.init = function (cli) {
319378
.option('-q --quiet', $('quiet mode, do not ask for delete confirmation'))
320379
.execute(domain.deleteCommand);
321380

322-
domain.command('check [name]')
323-
.description($('Check if a domain is available for registration..'))
324-
.execute(domain.checkCommand);
325-
326-
domain.doDomainsGet = function (options, callback) {
327-
var domainClient = new DomainClient(cli, options.subscription);
328-
return domainClient.getDomains(options, callback);
329-
};
330-
331-
domain.doDomainGet = function (options, callback) {
332-
var domainClient = new DomainClient(cli, options.subscription);
333-
return domainClient.getDomain(options, callback);
334-
};
335-
336-
domain.doDomainAdd = function (options, callback) {
337-
var domainClient = new DomainClient(cli, options.subscription);
338-
return domainClient.addDomain(options, callback);
339-
};
340-
341-
domain.doDomainDelete = function (options, callback) {
342-
var domainClient = new DomainClient(cli, options.subscription);
343-
return domainClient.deleteDomain(options, callback);
344-
};
345-
346-
domain.doDomainCheck = function (options, callback) {
347-
var domainClient = new DomainClient(cli, options.subscription);
348-
return domainClient.checkDomain(options, callback);
349-
};
350-
351-
domain.doRecordsGet = function (options, callback) {
352-
var domainClient = new DomainClient(cli, options.subscription);
353-
return domainClient.getRecords(options, callback);
354-
};
381+
domain.command('reset [name]')
382+
.description($('Reset a domain token'))
383+
.option('-q --quiet', $('quiet mode, do not ask for confirmation'))
384+
.execute(domain.resetCommand);
355385

356-
domain.doRecordGet = function (options, callback) {
357-
var domainClient = new DomainClient(cli, options.subscription);
358-
return domainClient.getRecord(options, callback);
359-
};
386+
domain.command('push [useremail] [contactid] [name]')
387+
.usage('[options] <useremail> <contactid> [name]')
388+
.description($('Move a domain from the current account to another'))
389+
.option('-u --useremail <useremail>', $('The new account\'s email address.'))
390+
.option('-c --contactid <contactid>', $('The new account\'s registrant ID.'))
391+
.option('-q --quiet', $('quiet mode, do not ask for confirmation'))
392+
.execute(domain.pushCommand);
360393

361-
domain.doRecordAdd = function (options, callback) {
362-
var domainClient = new DomainClient(cli, options.subscription);
363-
return domainClient.addRecord(options, callback);
364-
};
394+
domain.command('check [name]')
395+
.description($('Check if a domain is available for registration'))
396+
.execute(domain.checkCommand);
365397

366-
domain.doRecordUpdate = function (options, callback) {
367-
var domainClient = new DomainClient(cli, options.subscription);
368-
return domainClient.updateRecord(options, callback);
398+
domain.client = function(options) {
399+
return new DomainClient(cli, options.subscription);
369400
};
370401

371-
domain.doRecordDelete = function (options, callback) {
372-
var domainClient = new DomainClient(cli, options.subscription);
373-
return domainClient.deleteRecord(options, callback);
374-
};
402+
domain.promptForDomainName = function (context, _) {
403+
log.silly('promptForDomainName');
404+
if (context.domain.name === undefined) {
405+
log.help($('Need a domain name'));
406+
context.domain.name = cli.interaction.prompt($('Domain: '), _);
407+
}
408+
}
375409

376-
// TODO: remove all these "site."" function and just call websiteClient directly.
410+
// TODO: remove all these "domain."" function and just call domainClient directly.
377411
domain.lookupDomainName = function (options, callback) {
378412
var domainClient = new DomainClient(cli, options.subscription);
379413
return domainClient.lookupDomainName(options, callback);

lib/commands/domain/domain.record._js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ exports.init = function (cli) {
8282

8383
domain.lookupDomainName(context, _);
8484

85-
var records = domain.doRecordsGet(context, _);
85+
var records = domain.client(context).getRecords(context, _);
8686

8787
if (options.type) {
8888
console.log(options.type);
@@ -170,7 +170,7 @@ exports.init = function (cli) {
170170
context.record = r;
171171
domain.lookupDomainName(context, _);
172172

173-
var record = domain.doRecordAdd(context, _);
173+
var record = domain.client(context).addRecord(context, _);
174174

175175
var format = [
176176
[$('Id'), 'id'],
@@ -253,7 +253,7 @@ exports.init = function (cli) {
253253
context.record = r;
254254
domain.lookupDomainName(context, _);
255255

256-
var record = domain.doRecordUpdate(context, _);
256+
var record = domain.client(context).updateRecord(context, _);
257257

258258
var format = [
259259
[$('Id'), 'id'],
@@ -283,12 +283,13 @@ exports.init = function (cli) {
283283

284284
domain.lookupDomainName(context, _);
285285

286-
var shouldDelete = options.quiet || cli.interaction.confirm($('This will permanently remove the dns record and cannot be undone. Are you sure? '), _);
287-
if (!shouldDelete) {
286+
var shouldContinue = options.quiet || cli.interaction.confirm($('This will permanently remove the dns record and cannot be undone. Are you sure? '), _);
287+
if (!shouldContinue) {
288+
log.warn('Domain dns record delete cancelled.');
288289
return;
289290
}
290291

291-
domain.doRecordDelete(context, _);
292+
domain.client(context).deleteRecord(context, _);
292293

293294
},
294295

0 commit comments

Comments
 (0)