Skip to content
This repository
Browse code

Lint!

  • Loading branch information...
commit c05fb47edcd96d1a918ee98dbbb25fc7bce22be1 1 parent 98eb550
Pedro Palazón Candel kusor authored
1  bin/sdc-addmachinetags
@@ -45,7 +45,6 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
45 45 if (parsed.argv.remain.length < 1)
46 46 common.usage(usageStr, 1, 'machine required');
47 47
48   - var opts = {};
49 48 if (!parsed.tag)
50 49 common.usage(usageStr, 1, '--tag required');
51 50
2  bin/sdc-createkey
@@ -44,7 +44,7 @@ function loadNewKey(key) {
44 44 try {
45 45 return fs.readFileSync(key, 'ascii');
46 46 } catch(e) {
47   - common.usage(usageStr, 2, 'Unable to load key ' + key + ': ' + e);
  47 + return common.usage(usageStr, 2, 'Unable to load key ' + key + ': ' + e);
48 48 }
49 49 }
50 50
14 bin/sdc-createmachine
@@ -49,7 +49,7 @@ var ShortOptions = {
49 49 ///--- Mainline
50 50
51 51 common.parseArguments(Options, ShortOptions, function(parsed) {
52   - var opts = {}
  52 + var opts = {};
53 53 if (parsed.dataset) opts.dataset = parsed.dataset;
54 54 if (parsed.name) opts.name = parsed.name;
55 55 if (parsed['package']) opts['package'] = parsed['package'];
@@ -64,17 +64,17 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
64 64 }
65 65 }
66 66 if (parsed.metadata) {
67   - for (var i = 0; i < parsed.metadata.length; i++) {
68   - var tmp = parsed.metadata[i].split('=');
69   - if (!tmp || tmp.length !== 2) {
70   - console.error(parsed.metadata[i] + ' is invalid metadata; try foo=bar');
  67 + for (var j = 0; j < parsed.metadata.length; j++) {
  68 + var tmp2 = parsed.metadata[j].split('=');
  69 + if (!tmp2 || tmp2.length !== 2) {
  70 + console.error(parsed.metadata[j] + ' is invalid metadata; try foo=bar');
71 71 process.exit(1);
72 72 }
73   - opts['metadata.' + tmp[0]] = tmp[1];
  73 + opts['metadata.' + tmp2[0]] = tmp2[1];
74 74 }
75 75 }
76 76 if (parsed.script) {
77   - us = fs.readFileSync(parsed.script, 'utf-8');
  77 + var us = fs.readFileSync(parsed.script, 'utf-8');
78 78 opts['metadata.user-script'] = us.toString();
79 79 }
80 80
1  bin/sdc-deletemachinemetadata
@@ -45,7 +45,6 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
45 45 if (parsed.argv.remain.length < 1)
46 46 common.usage(usageStr, 1, 'metadata key required');
47 47
48   - var opts = {};
49 48 if (!parsed.machine)
50 49 common.usage(usageStr, 1, '--machine required');
51 50
13 bin/sdc-deletemachinetag
@@ -47,10 +47,11 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
47 47
48 48 var client = common.newClient(parsed);
49 49
50   - if (parsed.argv.remain[0] === '*')
51   - return client.deleteMachineTags(parsed.machine, common.callback);
52   -
53   - parsed.argv.remain.forEach(function(tag) {
54   - client.deleteMachineTag(parsed.machine, tag, common.callback);
55   - });
  50 + if (parsed.argv.remain[0] === '*') {
  51 + return client.deleteMachineTags(parsed.machine, common.callback);
  52 + } else {
  53 + return parsed.argv.remain.forEach(function(tag) {
  54 + client.deleteMachineTag(parsed.machine, tag, common.callback);
  55 + });
  56 + }
56 57 }, usageStr);
91 bin/sdc-setup
@@ -7,7 +7,7 @@ var fs = require('fs');
7 7 var path = require('path');
8 8 var tty = require('tty');
9 9 var URL = require('url');
10   -var util = require('util')
  10 +var util = require('util');
11 11 var nopt = require('nopt');
12 12 var restify = require('restify');
13 13 var bunyan = require('bunyan');
@@ -42,15 +42,23 @@ usageStr += ' url';
42 42 // Totally ripped off from npm. Thanks isaacs@!
43 43
44 44 function prompt (p, def, silent, cb) {
45   - if (!cb) cb = silent, silent = false
46   - if (!cb) cb = def, def = null
47   - if (def) p += "("+(silent ? "<hidden>" : def)+") "
48   - var r = (silent ? silentRead : read).bind(null, def, cb)
  45 + if (!cb) {
  46 + cb = silent;
  47 + silent = false;
  48 + }
  49 + if (!cb) {
  50 + cb = def;
  51 + def = null;
  52 + }
  53 + if (def) {
  54 + p += "("+(silent ? "<hidden>" : def)+") ";
  55 + }
  56 + var r = (silent ? silentRead : read).bind(null, def, cb);
49 57 if (!process.stdout.write(p)) process.stdout.on("drain", function D () {
50   - process.stdout.removeListener("drain", D)
51   - r()
52   - })
53   - else r()
  58 + process.stdout.removeListener("drain", D);
  59 + r();
  60 + });
  61 + else r();
54 62 }
55 63
56 64 function read (def, cb) {
@@ -73,7 +81,7 @@ function read (def, cb) {
73 81 val = val.trim() || def;
74 82 cb(null, val);
75 83 }
76   - })
  84 + });
77 85 }
78 86
79 87 function silentRead (def, cb) {
@@ -87,7 +95,7 @@ function silentRead (def, cb) {
87 95 stdin.resume();
88 96 stdin.on("error", cb);
89 97 stdin.on("data", function D (c) {
90   - c = "" + c
  98 + c = "" + c;
91 99 switch (c) {
92 100 case "\n": case "\r": case "\r\n": case "\u0004":
93 101 if (process.stdin.setRawMode) {
@@ -103,25 +111,24 @@ function silentRead (def, cb) {
103 111 return cb(null, val);
104 112 case "\u0003": case "\0":
105 113 return cb("cancelled");
106   - break;
107 114 default:
108 115 val += buffer + c;
109 116 buffer = "";
110   - break;
  117 + return cb(null, val);
111 118 }
112 119 });
113 120 }
114 121
115 122
116   -function dumpEnvVars(url, account, keyId) {
  123 +function dumpEnvVars(sdc_url, account, keyId) {
117 124 console.log('\n\nIf you set these environment variables, your life will be ' +
118 125 'easier:');
119   - console.log('export SDC_CLI_URL=' + url);
  126 + console.log('export SDC_CLI_URL=' + sdc_url);
120 127 console.log('export SDC_CLI_ACCOUNT=' + account);
121 128 }
122 129
123 130
124   -function uploadKey(client, url, account) {
  131 +function uploadKey(client, sdc_url, account) {
125 132 return prompt('SSH public key: ', DEF_KEY, function(err, file) {
126 133 if (err) {
127 134 console.error('Unable to read key: ' + err.message);
@@ -136,25 +143,25 @@ function uploadKey(client, url, account) {
136 143 var opts = {
137 144 name: keyName[keyName.length - 1].split('.')[0],
138 145 key: key
139   - }
  146 + };
140 147
141   - client.createKey(opts, function(err, key) {
142   - if (err) {
143   - if (err.httpCode >= 500) {
144   - if (err.details && err.details.body) {
  148 + client.createKey(opts, function(err2, key2) {
  149 + if (err2) {
  150 + if (err2.httpCode >= 500) {
  151 + if (err2.details && err2.details.body) {
145 152 try {
146   - console.error(JSON.parse(err.details.body).message);
  153 + console.error(JSON.parse(err2.details.body).message);
147 154 } catch(e) {
148   - console.error(err.message);
  155 + console.error(err2.message);
149 156 }
150 157 }
151 158 } else {
152   - console.error(err.message);
  159 + console.error(err2.message);
153 160 }
154 161 process.exit(3);
155 162 }
156 163
157   - dumpEnvVars(url, account, key.name);
  164 + dumpEnvVars(sdc_url, account, key2.name);
158 165 console.log('export SDC_CLI_IDENTITY=' + file.replace(/\.pub$/, ''));
159 166 process.exit(0);
160 167 });
@@ -181,9 +188,9 @@ prompt('Username (login): ', process.env.USER, function(err, username) {
181 188 process.exit(5);
182 189 }
183 190
184   - return prompt('Password: ', null, true, function(err, password) {
185   - if (err) {
186   - console.error('Unable to read password: ' + err.message);
  191 + return prompt('Password: ', null, true, function(err2, password) {
  192 + if (err2) {
  193 + console.error('Unable to read password: ' + err2.message);
187 194 process.exit(5);
188 195 }
189 196
@@ -201,17 +208,17 @@ prompt('Username (login): ', process.env.USER, function(err, username) {
201 208 logLevel: 'fatal'
202 209 });
203 210
204   - return client.listKeys(function(err, keys) {
205   - if (err) {
206   - if (err.code) {
207   - if (err.code === 'InvalidCredentials') {
  211 + return client.listKeys(function(err3, keys) {
  212 + if (err3) {
  213 + if (err3.code) {
  214 + if (err3.code === 'InvalidCredentials') {
208 215 console.error('The username or password you entered is incorrect.');
209 216 } else {
210 217 console.error('Error communicating with SmartDataCenter: ' +
211   - err.message);
  218 + err3.message);
212 219 }
213   - } else if (err.details && err.details.statusCode) {
214   - var details = err.details;
  220 + } else if (err3.details && err3.details.statusCode) {
  221 + var details = err3.details;
215 222 if (details.statusCode === 301) {
216 223 if (details.headers && details.headers.location) {
217 224 var _url = URL.parse(details.headers.location);
@@ -229,9 +236,9 @@ prompt('Username (login): ', process.env.USER, function(err, username) {
229 236 console.log('\t[' + (i + 1) + '] ' + keys[i].name);
230 237 }
231 238
232   - function useExistingCb(err, choice) {
233   - if (err) {
234   - console.error('Unable to read choice: ' + err.message);
  239 + function useExistingCb(err4, choice) {
  240 + if (err4) {
  241 + console.error('Unable to read choice: ' + err4.message);
235 242 process.exit(8);
236 243 }
237 244 if (/^ye?s?/i.test(choice)) {
@@ -249,13 +256,13 @@ prompt('Username (login): ', process.env.USER, function(err, username) {
249 256 return done(keys[0].name);
250 257 }
251 258
252   - return prompt('Select a key:', 1, function(err, choice) {
253   - if (err) {
254   - console.error('Unable to read key number: ' + err.message);
  259 + return prompt('Select a key:', 1, function(err5, choice2) {
  260 + if (err5) {
  261 + console.error('Unable to read key number: ' + err5.message);
255 262 process.exit(8);
256 263 }
257 264
258   - var index = parseInt(choice, 10) - 1;
  265 + var index = parseInt(choice2, 10) - 1;
259 266 if (index < 0 || index >= keys.length) {
260 267 console.error(index + ' is an invalid selection.');
261 268 process.exit(8);
1  bin/sdc-updatemachinemetadata
@@ -45,7 +45,6 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
45 45 if (parsed.argv.remain.length < 1)
46 46 common.usage(usageStr, 1, 'machine required');
47 47
48   - var opts = {};
49 48 if (!parsed.metadata)
50 49 common.usage(usageStr, 1, '--metadata required');
51 50
26 lib/cli_common.js
@@ -58,7 +58,7 @@ function loadKeyFromAgent(parsed, callback) {
58 58
59 59 try {
60 60 var agent = new SSHAgentClient();
61   - agent.requestIdentities(function(err, keys) {
  61 + return agent.requestIdentities(function(err, keys) {
62 62 if (err || !keys || !keys.length) {
63 63 if (parsed.debug) {
64 64 console.log('No ssh-agent identities found');
@@ -66,13 +66,13 @@ function loadKeyFromAgent(parsed, callback) {
66 66 return callback(null);
67 67 }
68 68
69   - var path = parsed.identity.split('/');
  69 + var p = parsed.identity.split('/');
70 70 for (var i = 0; i < keys.length; i++) {
71 71 if (keys[i].type !== 'ssh-rsa')
72 72 continue;
73 73
74 74 var comment = keys[i].comment.split('/');
75   - if (path[path.length - 1] === comment[comment.length - 1]) {
  75 + if (p[p.length - 1] === comment[comment.length - 1]) {
76 76 if (parsed.debug) {
77 77 console.log('Using ssh-agent identity: ' + keys[i].comment);
78 78 }
@@ -99,7 +99,7 @@ function loadSigningKey(parsed, callback) {
99 99 assert.ok(parsed);
100 100 assert.ok(callback);
101 101
102   - fs.readFile(parsed.identity, 'ascii', function(err, file) {
  102 + return fs.readFile(parsed.identity, 'ascii', function(err, file) {
103 103 if (err) {
104 104 console.error(err.message);
105 105 process.exit(2);
@@ -109,13 +109,13 @@ function loadSigningKey(parsed, callback) {
109 109 if (parsed.keyId)
110 110 return callback(parsed);
111 111
112   - fs.readFile(parsed.identity + '.pub', 'ascii', function(err, file) {
113   - if (err) {
114   - console.error(err.message);
  112 + return fs.readFile(parsed.identity + '.pub', 'ascii', function(err2, f) {
  113 + if (err2) {
  114 + console.error(err2.message);
115 115 process.exit(2);
116 116 }
117 117 try {
118   - parsed.keyId = getFingerprint(file);
  118 + parsed.keyId = getFingerprint(f);
119 119 } catch (e) {
120 120 console.error('Unable to take fingerprint of public key: ' + e.stack);
121 121 process.exit(2);
@@ -207,8 +207,8 @@ module.exports = {
207 207 return callback(_parsed);
208 208 }
209 209
210   - return loadSigningKey(parsed, function(_parsed) {
211   - if (!_parsed) {
  210 + return loadSigningKey(parsed, function(_parsed2) {
  211 + if (!_parsed2) {
212 212 console.error('Unable to load a private key for signing (not found)');
213 213 process.exit(2);
214 214 }
@@ -216,7 +216,7 @@ module.exports = {
216 216 if (parsed.debug) {
217 217 console.log('Using private key from: %s', parsed.identity);
218 218 }
219   - return callback(_parsed);
  219 + return callback(_parsed2);
220 220 });
221 221 });
222 222 },
@@ -239,7 +239,7 @@ module.exports = {
239 239 });
240 240 } catch (e) {
241 241 console.error(e.message);
242   - process.exit(1);
  242 + return process.exit(1);
243 243 }
244 244 },
245 245
@@ -249,7 +249,7 @@ module.exports = {
249 249 return fs.readFileSync(key, 'ascii');
250 250 } catch (e) {
251 251 console.error('Unable to load key ' + key + ': ' + e);
252   - process.exit(2);
  252 + return process.exit(2);
253 253 }
254 254 }
255 255
11 lib/cloudapi.js
@@ -10,9 +10,6 @@ var createCache = require('lru-cache');
10 10 var restify = require('restify');
11 11 var bunyan = require('bunyan');
12 12
13   -var utils = require('./utils');
14   -
15   -
16 13 ///--- Globals
17 14
18 15 var log = bunyan.createLogger({
@@ -107,7 +104,7 @@ function _encodeURI(path) {
107 104 }
108 105
109 106 return append();
110   -};
  107 +}
111 108
112 109 ///--- Exported CloudAPI Client
113 110
@@ -2073,7 +2070,6 @@ CloudAPI.prototype._request = function(path, body, callback) {
2073 2070 if (body)
2074 2071 obj.body = body;
2075 2072
2076   - var authz;
2077 2073 if (this.basicAuth) {
2078 2074 self.client.basicAuth(self.options.username, self.options.password);
2079 2075 } else {
@@ -2086,13 +2082,12 @@ CloudAPI.prototype._request = function(path, body, callback) {
2086 2082 alg.toLowerCase(),
2087 2083 signer.sign(this.key, 'base64'));
2088 2084 } else {
2089   - var self = this;
2090 2085 return this.sshAgent.sign(this.key, new Buffer(now), function(err, sig) {
2091 2086 if (!err && sig) {
2092   - var alg = /DSA/i.test(self.key) ? 'dsa-sha1' : 'rsa-sha1';
  2087 + var algo = /DSA/i.test(self.key) ? 'dsa-sha1' : 'rsa-sha1';
2093 2088 obj.headers.Authorization = sprintf(SIGNATURE,
2094 2089 self.keyId,
2095   - alg,
  2090 + algo,
2096 2091 sig.signature);
2097 2092 }
2098 2093
6 lib/index.js
... ... @@ -1,11 +1,11 @@
1   -// Copyright 2011 Joyent, Inc. All rights reserved.
  1 +// Copyright 2012 Joyent, Inc. All rights reserved.
2 2
3 3 var cloudapi = require('./cloudapi');
4 4
5 5 module.exports = {
6 6
7   - CloudAPI: cloudapi.CloudAPI,
  7 + CloudAPI: cloudapi.CloudAPI,
8 8
9   - createClient: cloudapi.createClient
  9 + createClient: cloudapi.createClient
10 10
11 11 };

0 comments on commit c05fb47

Please sign in to comment.
Something went wrong with that request. Please try again.