Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUBAPI-1146 Divorce wanted between *_KEY_ID env vars and keyId actually sent to server #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 2 additions & 5 deletions bin/sdc-chmod
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,10 @@ if (require.main === module) {

opts.log = log;

var identity = (opts.user) ?
util.format('%s/users/%s', opts.account, opts.user):
opts.account;

opts.sign = auth.cliSigner({
keyId: opts.keyId,
user: identity
user: opts.account,
subuser: opts.user
});

var resource = opts._args[1];
Expand Down
7 changes: 2 additions & 5 deletions bin/sdc-info
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,10 @@ if (require.main === module) {
process.exit(1);
}

var identity = (opts.user) ?
util.format('%s/users/%s', opts.account, opts.user):
opts.account;

opts.sign = auth.cliSigner({
keyId: opts.keyId,
user: identity
user: opts.account,
subuser: opts.user
});

var cloudapi = new CloudAPI(opts);
Expand Down
15 changes: 7 additions & 8 deletions lib/cli_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ url.name = 'url';
// --- Globals

var KV_RE = new RegExp('^([^=]+)=(.*)$');
var SSH_KEY_ID_RE = /^[0-9a-f]{2}(?:\:[0-9a-f]{2}){15}$/i;
var SSH_HEX_KEY_ID_RE = /^(MD5:)?[0-9a-f]{2}(?:\:[0-9a-f]{2}){15}$/i;
/*JSSTYLED*/
var SSH_BASE64_KEY_ID_RE = /^[A-Z0-9]+:[-A-Za-z0-9+\/=]+$/;
var URL_RE = '^https?\://.+';

var DeprecatedOptions = {
Expand Down Expand Up @@ -281,7 +283,8 @@ module.exports = {
'Either --keyId or (env) SDC_KEY_ID must be specified');
}

if (!parsed.keyId.match(SSH_KEY_ID_RE)) {
if (!parsed.keyId.match(SSH_HEX_KEY_ID_RE) &&
!parsed.keyId.match(SSH_BASE64_KEY_ID_RE)) {
usage(usageStr, 1,
'--keyId or (env) SDC_KEY_ID must be a valid SSH key ID');
}
Expand Down Expand Up @@ -327,14 +330,10 @@ module.exports = {
parsed.user = process.env.SDC_USER;
}

var identity = (parsed.user) ?
format('%s/users/%s', parsed.account, parsed.user):
parsed.account;


parsed.sign = smartdc.cliSigner({
keyId: parsed.keyId,
user: identity
user: parsed.account,
subuser: parsed.user
});

return callback(parsed);
Expand Down
6 changes: 5 additions & 1 deletion lib/cloudapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ function _signRequest(opts, cb) {
return (cb(null));
}

var ident = obj.user;
if (obj.subuser !== undefined)
ident = sprintf('%s/users/%s', obj.user, obj.subuser);

opts.headers.authorization = sprintf(SIGNATURE,
obj.user,
ident,
obj.keyId,
obj.algorithm,
obj.signature);
Expand Down
14 changes: 7 additions & 7 deletions lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var smartdc = require('../lib/cloudapi'),
CloudAPI = smartdc.CloudAPI;


var SSH_KEY_ID_RE = /^[0-9a-f]{2}(?:\:[0-9a-f]{2}){15}$/i;
var SSH_HEX_KEY_ID_RE = /^(MD5:)?[0-9a-f]{2}(?:\:[0-9a-f]{2}){15}$/i;
/*JSSTYLED*/
var SSH_BASE64_KEY_ID_RE = /^[A-Z0-9]+:[-A-Za-z0-9+\/=]+$/;
var URL_RE = '^https?\://.+';


Expand Down Expand Up @@ -109,7 +111,8 @@ function checkRequiredOptions(opts, args, callback) {
'Either --key or (env) SDC_KEY_ID must be specified'));
}

if (!opts.keyId.match(SSH_KEY_ID_RE)) {
if (!opts.keyId.match(SSH_HEX_KEY_ID_RE) &&
!opts.keyId.match(SSH_BASE64_KEY_ID_RE)) {
return callback(new Error(
'--keyId or (env) SDC_KEY_ID must be a valid SSH key ID'));
}
Expand Down Expand Up @@ -143,13 +146,10 @@ function checkRequiredOptions(opts, args, callback) {
'--url or (env) SDC_URL must be a valid URL'));
}

var identity = (opts.user) ?
util.format('%s/users/%s', opts.account, opts.user):
opts.account;

opts.sign = auth.cliSigner({
keyId: opts.keyId,
user: identity
user: opts.account,
subuser: opts.user
});

if (opts.role) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"restify": "2.8.5",
"bunyan": "1.3.4",
"clone": "0.1.6",
"smartdc-auth": "1.0.4",
"smartdc-auth": "2.0.1",
"cmdln": "3.2.1",
"dashdash": "1.7.3",
"vasync": "1.6.2"
Expand Down