Skip to content

Commit 54e9541

Browse files
committed
Added domain member functionality.
1 parent 1b894cf commit 54e9541

5 files changed

Lines changed: 241 additions & 99 deletions

File tree

README.md

Lines changed: 52 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,33 @@ This project provides a cross-platform command line interface for [DNSimple][0].
88

99
This project's command line interface is based on the [azure-cli](https://github.com/Azure/azure-sdk-tools-xplat), although its features and functionality are entirely different and not related to [azure](http://azure.microsoft.com/) whatsoever.
1010

11-
## Current Features
12-
13-
See the [command reference][3] for complete planned command structure.
14-
15-
--
16-
* Accounts: `(command: dnsimple account)`
17-
* Secure authentication for multiple DNSimple accounts/subscriptions
18-
* List authenticated accounts/subscriptions
19-
* Set current account/subscription
20-
2111
--
22-
* Domains: `(command: dnsimple domain)`
23-
* List domains in your account `(command: dnsimple domain list)`
24-
* List domains in your account that match a wildcard filter (e.g. *.com) `(command: dnsimple domain list *.com)`
25-
* Show details for a specific domain in your account `(command: dnsimple domain show)`
26-
* Add a domain to your account `(command: dnsimple domain add)`
27-
* Delete a domain from your account `(command: dnsimple domain delete)`
28-
* Reset a domain token for one or more domains`(command: dnsimple domain reset)`
29-
* Push one or more domains from the current account to another `(command: dnsimple domain push)`
30-
* Check availability of one or more domains `(command: dnsimple domain check)`
31-
* Register one or more domains `(command: dnsimple domain register)`
32-
* Enable/Disable Auto-Renewal for one or more domains `(command: dnsimple domain autorenew)`
33-
* Records: `(command: dnsimple domain record)`
34-
* Show DNS Records for a specific domain `(command: dnsimple domain record list)`
35-
* Show DNS Records of a specific type (A, CNAME, TXT, NS, etc.) for a specific domain `(command: dnsimple domain record list -t CNAME)`
36-
* Show DNS Records whose content matches a specific filter (e.g. \*spf\*) `(command: dnsimple domain record list -f *spf*)`
37-
* Add DNS Records to a domain `(command: dnsimple domain record add)`
38-
* Show details for a domain DNS Record `(command: dnsimple domain record show)`
39-
* Update DNS Records for a domain `(command: dnsimple domain record update)`
40-
* Delete DNS Records for a domain `(command: dnsimple domain record delete)`
12+
Installation
13+
------------
4114

42-
--
43-
* Contacts: `(command: dnsimple contact)`
44-
45-
--
46-
* Services: `(command: dnsimple service)`
15+
The release on npm is the latest stable version:
4716

48-
--
49-
* Templates: `(command: dnsimple template)`
50-
51-
--
52-
* Extended Attributes: `(command: dnsimple extattr)`
53-
54-
--
55-
* Users: `(command: dnsimple user)`
56-
57-
--
58-
* Subscriptions: `(command: dnsimple subscription)`
17+
```bash
18+
npm install -g dnsimple-cli
19+
```
5920

60-
--
61-
* Prices: `(command: dnsimple price)`
62-
* List all domain prices
21+
The code on Github is the most recent version, but can be unstable:
6322

64-
--
65-
## Installation
23+
```bash
24+
npm install anderly/dnsimple-cli
25+
```
6626

67-
### Install from npm (coming soon)
27+
### dnsimple cli on Ubuntu
28+
If you want to run dnsimple cli on Ubuntu, then you should install **nodejs-legacy** instead of **nodejs**. For more information please check the following links:
29+
- [why there is a problem with nodejs installation on ubuntu](http://stackoverflow.com/questions/14914715/express-js-no-such-file-or-directory/14914716#14914716)
30+
- [how to solve the nodejs installation problem on ubuntu](https://github.com/expressjs/keygrip/issues/7)
6831

69-
You can install the dnsimple-cli npm package directly.
32+
Please perform the installation steps in following order:
7033
```bash
34+
sudo apt-get install nodejs-legacy
35+
sudo apt-get install npm
7136
npm install -g dnsimple-cli
7237
```
73-
### Install from GitHub
74-
You can install the latest code (could be unstable) directly from GitHub.
75-
```bash
76-
npm install anderly/dnsimple-cli
77-
```
7838

7939
### Download Source Code
8040

@@ -86,26 +46,10 @@ cd ./dnsimple-cli
8646
npm install
8747
```
8848

89-
### Configure auto-complete
90-
91-
Auto-complete is supported for Mac and Linux.
92-
93-
To enable it in zsh, run:
94-
95-
```bash
96-
echo '. <(dnsimple --completion)' >> .zshrc
97-
```
98-
99-
To enable it in bash, run:
49+
Usage
50+
-----
10051

101-
```bash
102-
dnsimple --completion >> ~/dnsimple.completion.sh
103-
echo 'source ~/dnsimple.completion.sh' >> .bash_profile
104-
```
105-
106-
## Get Started
107-
108-
Just type `dnsimple` at a command prompt to get started and see available commands. For more details see the [command reference][3].
52+
Just type `dnsimple` or `dns` at a command prompt to get started and see available commands. Please see the [command reference][3] and [wiki](wiki) for more details.
10953

11054
```bash
11155
user@host:~$ dnsimple
@@ -120,7 +64,7 @@ info: |_|
12064
info:
12165
info: DNSimple: We make DNS simple.
12266
info:
123-
info: Tool version 0.0.1
67+
info: Tool version 0.3.0
12468
help:
12569
help: Display help for a given command
12670
help: help [options] [command]
@@ -150,35 +94,48 @@ help: -h, --help output usage information
15094
help: -v, --version output the application version
15195
```
15296
153-
In general, following are the steps:
97+
Authentication
98+
-----
15499
155-
* Login to your DNSimple account.
156-
* Use the commands
100+
Authentication by **email + password** and **email + token** are both supported. If you authenticate using **email + password**, your account api token is retrieved and used for all subsequent calls. All credentials are securely stored in OS-specific secure credential stores such as OS X Keychain or Windows Credential Manager.
157101
158-
The first step can be different for different environments you are targeting. The DNSimple [sandbox][1] is supported in addition to [production][0].
102+
The DNSimple [sandbox][1] environment is supported in addition to [production][0].
159103
160-
### Login directly from dnsimple-cli
104+
### Password Authentication
161105
162106
```bash
163107
# This will prompt for your password in the console
164108
dnsimple login -u <your dnsimple account email address>
165-
166-
# use the commands to manage your domains/dns/services/templates
167-
dnsimple domain list
109+
```
110+
or
111+
```bash
112+
# Specifying the -e --environment parameter allows you to login to the Sanbox enivonrment.
113+
# Production is the default.
114+
dnsimple login -u <your dnsimple account email address> -e Sandbox
168115
```
169116
170-
### dnsimple cli on Ubuntu
171-
If you want to run dnsimple cli on Ubuntu, then you should install **nodejs-legacy** instead of **nodejs**. For more information please check the following links:
172-
- [why there is a problem with nodejs installation on ubuntu](http://stackoverflow.com/questions/14914715/express-js-no-such-file-or-directory/14914716#14914716)
173-
- [how to solve the nodejs installation problem on ubuntu](https://github.com/expressjs/keygrip/issues/7)
117+
### Token Authentication
174118
175-
Please perform the installation steps in following order:
176119
```bash
177-
sudo apt-get install nodejs-legacy
178-
sudo apt-get install npm
179-
npm install -g dnsimple-cli
120+
dnsimple login -u <your dnsimple account email address> -t <your dnsimple account api token>
180121
```
181-
122+
123+
Commands
124+
--------
125+
Once authenticated, you can begin using the following top-level command categories:
126+
```
127+
# Command Categories:
128+
account Commands to manage your account information
129+
domain Commands to manage domains
130+
contact Commands to manage your account contacts
131+
service Commands to manage your domain services
132+
template Commands to manage dns record templates
133+
user Commands to manage your users
134+
subscription Commands to manage account subscriptions
135+
price Commands to view domain pricing
136+
```
137+
Please see the [command reference][3] and [wiki](wiki) for more details.
138+
182139
## Setting up Fiddler for CLI
183140
184141
You need to set the following environment variables to capture the HTTP traffic generated from the execution of dnsimple cli commands
@@ -189,7 +146,7 @@ set HTTPS_PROXY=http://127.0.0.1:8888
189146
```
190147
191148
## Learn More
192-
Please see the DNSimple CLI [command reference][3] for details on current and anticipated commands.
149+
Please see the [command reference][3] and [wiki](wiki) for details and examples of all commands.
193150
194151
For more information on the DNSimple REST API, please see the [DNSimple API Documentation][2].
195152

command-reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
|- autorenew [-e --enable] [-d --disable] [domain]
3434
--------------
3535
|- member
36-
|- list
37-
|- add
38-
|- delete
36+
|- list (Show domain members)
37+
|- add [member] (Grant a user access to a domain)
38+
|- delete [member] (Revoke a user\'s access for a domain)
3939
--------------
4040
|- record
4141
|- list [-t --type <type>] [-f --filter <filter>] [domain]
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//
2+
// Copyright (c) Adam Anderly. 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+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// NOTICE: Based on azure-cli (https://github.com/Azure/azure-sdk-tools-xplat/)
17+
//
18+
19+
var util = require('util');
20+
21+
var profile = require('../../util/profile');
22+
var utils = require('../../util/utils');
23+
var Wildcard = utils.Wildcard;
24+
25+
var $ = utils.getLocaleString;
26+
27+
exports.init = function (cli) {
28+
var log = cli.output;
29+
var domain = cli.category('domain');
30+
var domainMembers = domain.category('member')
31+
.description($('Commands to manage your domain members'));
32+
33+
domainMembers.listCommand = function (name, options, _) {
34+
var context = {
35+
subscription: profile.current.getSubscription(options.subscription).id,
36+
domain: {
37+
name: name
38+
}
39+
};
40+
41+
domain.lookupDomainName(context, _);
42+
43+
var members = domain.client(context).getMembers(context, _);
44+
45+
cli.interaction.formatOutput(members, function (data) {
46+
if (data.length > 0) {
47+
log.info($('Domain Members:'));
48+
log.table(members, function (row, item) {
49+
//if (options.details) {
50+
row.cell($('Membership Id'), item.id);
51+
//}
52+
row.cell($('User Id'), item.user_id);
53+
row.cell($('Created At'), item.created_at);
54+
row.cell($('Updated At'), item.updated_at);
55+
});
56+
} else {
57+
log.info($('No members defined yet'));
58+
}
59+
});
60+
};
61+
62+
domainMembers.addCommand = function (member, name, options, _) {
63+
member = cli.interaction.promptIfNotGiven($('Email address of the person to add: '), member, _);
64+
65+
var context = {
66+
subscription: profile.current.getSubscription(options.subscription).id,
67+
domain: {
68+
name: name
69+
},
70+
member: member
71+
};
72+
73+
domain.lookupDomainName(context, _);
74+
75+
var member = domain.client(context).addMember(context, _);
76+
77+
var format = [
78+
[$('Membership Id'), 'id'],
79+
[$('Domain Id'), 'domain_id'],
80+
[$('User Id'), 'user_id'],
81+
[$('Created At'), 'created_at'],
82+
];
83+
84+
log.info(util.format($('Successfully added member %s to domain %s:'), context.member, name));
85+
log.report(format, member);
86+
87+
},
88+
89+
domainMembers.deleteCommand = function (member, name, options, _) {
90+
member = cli.interaction.promptIfNotGiven($('Member email address or membership id: '), member, _);
91+
92+
var context = {
93+
subscription: profile.current.getSubscription(options.subscription).id,
94+
domain: {
95+
name: name
96+
},
97+
member: member
98+
};
99+
100+
domain.lookupDomainName(context, _);
101+
102+
var shouldContinue = options.quiet || cli.interaction.confirm(util.format($('This will permanently remove member %s from domain %s. Are you sure? '), context.member, context.domain.name), _);
103+
if (!shouldContinue) {
104+
log.warn('Domain member delete cancelled.');
105+
return;
106+
}
107+
108+
domain.client(context).deleteMember(context, _);
109+
110+
},
111+
112+
domainMembers.command('list [name]')
113+
.usage('[options] [name]')
114+
.description($('Show domain members'))
115+
.option('-t --type <type>', $('Only show records of this type'))
116+
.option('-f --filter <filter>', $('Only show records whose content matches this filter'))
117+
.option('-d --details', $('Show extra information about the records'))
118+
.execute(domainMembers.listCommand);
119+
120+
domainMembers.command('add [member] [name]')
121+
.usage('[options] <member> [name]')
122+
.description($('Grant a user access to a domain'))
123+
.option('-m --member <member>', $('Email address for the person to add.'))
124+
.execute(domainMembers.addCommand);
125+
126+
domainMembers.command('delete [member] [name]')
127+
.usage('[options] <member> [name]')
128+
.description($('Revoke a user\'s access for a domain'))
129+
.option('-m --member <member>', $('The member email or membership id. Use dnsimple domain member list [domain] to see existing members.'))
130+
.option('-q --quiet', $('quiet mode, do not ask for delete confirmation'))
131+
.execute(domainMembers.deleteCommand);
132+
133+
};

0 commit comments

Comments
 (0)