Skip to content

Commit

Permalink
Allow ssh-key args in digitalocean create command. Fixes #19. Prepare…
Browse files Browse the repository at this point in the history
… v0.5.4
  • Loading branch information
andrewchilds committed Jul 7, 2014
1 parent f998adb commit 694a81b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 62 deletions.
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,20 @@ I wanted something that had little to no learning curve, that did only what you
You can specify region, image, and size of the droplet using -id or -slug.
You can also specify an image or snapshot using --image-name.
Option | Default
--cluster CLUSTER | default
--ssh-port PORT | 22
--region-slug NAME | nyc2
--region-id ID |
--image-slug NAME | ubuntu-14-04-x64
--image-id ID |
--image-name NAME |
--size-slug NAME | 512mb
--size-id ID |
--backups-enabled | false
--private-networking | false
Option | Default
--cluster CLUSTER | default
--ssh-port PORT | 22
--ssh-key KEY_PATH | overcast.key
--ssh-pub-key KEY_PATH | overcast.key.pub
--region-slug NAME | nyc2
--region-id ID |
--image-slug NAME | ubuntu-14-04-x64
--image-id ID |
--image-name NAME |
--size-slug NAME | 512mb
--size-id ID |
--backups-enabled | false
--private-networking | false
Example:
$ overcast digitalocean create db.01 --cluster db --size-slug 1gb --region-slug sfo1
Expand All @@ -291,8 +293,8 @@ I wanted something that had little to no learning curve, that did only what you
Destroys a DigitalOcean droplet and removes it from your account.
Using --force overrides the confirm dialog. This is irreversible.
Option | Default
--force | false
Option | Default
--force | false
overcast digitalocean droplets
List all DigitalOcean droplets in your account.
Expand All @@ -312,10 +314,10 @@ I wanted something that had little to no learning curve, that did only what you
According to the API docs, "This is useful if you want to start again but
retain the same IP address for your droplet."
Option | Default
--image-slug SLUG | ubuntu-12-04-x64
--image-name NAME |
--image-id ID |
Option | Default
--image-slug SLUG | ubuntu-12-04-x64
--image-name NAME |
--image-id ID |
Example:
$ overcast digitalocean rebuild app.01 --name my.app.snapshot
Expand All @@ -327,10 +329,10 @@ I wanted something that had little to no learning curve, that did only what you
Shutdown, resize, and reboot a DigitalOcean droplet.
If --skipboot flag is used, the droplet will stay in a powered-off state.
Option | Default
--size-slug NAME |
--size-id ID |
--skipBoot | false
Option | Default
--size-slug NAME |
--size-id ID |
--skipBoot | false
Example:
$ overcast digitalocean resize db.01 --size-slug 2gb
Expand Down Expand Up @@ -433,7 +435,7 @@ I wanted something that had little to no learning curve, that did only what you
### overcast help
```
Overcast v0.5.3
Overcast v0.5.4

Source code, issues, pull requests:
https://github.com/andrewchilds/overcast
Expand Down
46 changes: 24 additions & 22 deletions modules/commands/digitalocean.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ subcommands.create.help = function () {
' You can specify region, image, and size of the droplet using -id or -slug.'.grey,
' You can also specify an image or snapshot using --image-name.'.grey,
'',
' Option | Default'.grey,
' --cluster CLUSTER | default'.grey,
' --ssh-port PORT | 22'.grey,
' --region-slug NAME | nyc2'.grey,
' --region-id ID |'.grey,
' --image-slug NAME | ubuntu-14-04-x64'.grey,
' --image-id ID |'.grey,
' --image-name NAME |'.grey,
' --size-slug NAME | 512mb'.grey,
' --size-id ID |'.grey,
' --backups-enabled | false'.grey,
' --private-networking | false'.grey,
' Option | Default'.grey,
' --cluster CLUSTER | default'.grey,
' --ssh-port PORT | 22'.grey,
(' --ssh-key KEY_PATH | overcast.key').grey,
(' --ssh-pub-key KEY_PATH | overcast.key.pub').grey,
' --region-slug NAME | nyc2'.grey,
' --region-id ID |'.grey,
' --image-slug NAME | ubuntu-14-04-x64'.grey,
' --image-id ID |'.grey,
' --image-name NAME |'.grey,
' --size-slug NAME | 512mb'.grey,
' --size-id ID |'.grey,
' --backups-enabled | false'.grey,
' --private-networking | false'.grey,
'',
' Example:'.grey,
' $ overcast digitalocean create db.01 --cluster db --size-slug 1gb --region-slug sfo1'.grey
Expand Down Expand Up @@ -115,8 +117,8 @@ subcommands.destroy.help = function () {
' Destroys a DigitalOcean droplet and removes it from your account.'.grey,
' Using --force overrides the confirm dialog. This is irreversible.'.grey,
'',
' Option | Default'.grey,
' --force | false'.grey
' Option | Default'.grey,
' --force | false'.grey
]);
};

Expand Down Expand Up @@ -184,10 +186,10 @@ subcommands.rebuild.help = function () {
' According to the API docs, "This is useful if you want to start again but'.grey,
' retain the same IP address for your droplet."'.grey,
'',
' Option | Default'.grey,
' --image-slug SLUG | ubuntu-12-04-x64'.grey,
' --image-name NAME |'.grey,
' --image-id ID |'.grey,
' Option | Default'.grey,
' --image-slug SLUG | ubuntu-12-04-x64'.grey,
' --image-name NAME |'.grey,
' --image-id ID |'.grey,
'',
' Example:'.grey,
' $ overcast digitalocean rebuild app.01 --name my.app.snapshot'.grey
Expand Down Expand Up @@ -217,10 +219,10 @@ subcommands.resize.help = function () {
' Shutdown, resize, and reboot a DigitalOcean droplet.'.grey,
' If --skipboot flag is used, the droplet will stay in a powered-off state.'.grey,
'',
' Option | Default'.grey,
' --size-slug NAME |'.grey,
' --size-id ID |'.grey,
' --skipBoot | false'.grey,
' Option | Default'.grey,
' --size-slug NAME |'.grey,
' --size-id ID |'.grey,
' --skipBoot | false'.grey,
'',
' Example:'.grey,
' $ overcast digitalocean resize db.01 --size-slug 2gb'.grey
Expand Down
25 changes: 11 additions & 14 deletions modules/providers/digitalocean.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,15 @@ exports.getKeys = function (callback) {
});
};

exports.getHashedKeyName = function (keyData) {
keyData = (keyData || fs.readFileSync(utils.CONFIG_DIR + '/keys/overcast.key.pub', 'utf8')) + '';
return utils.createHashedKeyName(keyData);
};

exports.createKey = function (callback) {
exports.createKey = function (keyData, callback) {
// GET https://api.digitalocean.com/ssh_keys/new
// name=[ssh_key_name]
// ssh_pub_key=[ssh_public_key]

var keyData = fs.readFileSync(utils.CONFIG_DIR + '/keys/overcast.key.pub', 'utf8');

exports.request({
endpoint: 'ssh_keys/new',
query: {
name: exports.getHashedKeyName(keyData),
name: utils.createHashedKeyName(keyData),
ssh_pub_key: keyData + ''
},
callback: function (result) {
Expand Down Expand Up @@ -142,7 +135,9 @@ exports.create = function (options) {
});
}

exports.getOrCreateOvercastKeyID(function (keyID) {
options['ssh-pub-key'] = utils.normalizeKeyPath(options['ssh-pub-key'], 'overcast.key.pub');

exports.getOrCreateOvercastKeyID(options['ssh-pub-key'], function (keyID) {
var query = {
backups_enabled: utils.argIsTruthy(options['backups-enabled']),
name: options.name,
Expand Down Expand Up @@ -178,17 +173,19 @@ exports.create = function (options) {
});
};

exports.getOrCreateOvercastKeyID = function (callback) {
var variables = utils.getVariables();
exports.getOrCreateOvercastKeyID = function (pubKeyPath, callback) {
var keyData = fs.readFileSync(pubKeyPath, 'utf8') + '';

exports.getKeys(function (keys) {
var key = _.find(keys, {
name: exports.getHashedKeyName()
name: utils.createHashedKeyName(keyData)
});
if (key) {
utils.grey('Using SSH key: ' + pubKeyPath);
callback(key.id);
} else {
exports.createKey(function (key) {
utils.grey('Uploading new SSH key: ' + pubKeyPath);
exports.createKey(keyData, function (key) {
callback(key.id);
});
}
Expand Down
2 changes: 1 addition & 1 deletion modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var colors = require('colors');
var Promise = require('bluebird');
var listCommand = require('./commands/list');

exports.VERSION = '0.5.3';
exports.VERSION = '0.5.4';

exports.clustersCache = null;
exports.variablesCache = null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "overcast",
"description": "A simple, SSH-based cloud management CLI.",
"version": "0.5.3",
"version": "0.5.4",
"repository": "https://github.com/andrewchilds/overcast.git",
"author": {
"name": "Andrew Childs",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/digitalocean.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe 'digitalocean', ->
options =
name: 'name'
cluster: 'test-cluster'
spyOn(API, 'getOrCreateOvercastKeyID').andCallFake (cb) -> cb '123'
spyOn(API, 'getOrCreateOvercastKeyID').andCallFake (keyPath, cb) -> cb '123'
spyOn(API, 'request')
spyOn(utils, 'saveClusters')

Expand Down

0 comments on commit 694a81b

Please sign in to comment.