joyent/node-triton#19 stricter checking of profile files when loading them
This commit is contained in:
parent
5e75bff3fe
commit
7aa59f148f
@ -53,19 +53,39 @@ var CONFIG_VAR_NAMES = [
|
||||
'cacheDir'
|
||||
];
|
||||
|
||||
// TODO: use this to create a profile doc table?
|
||||
var PROFILE_FIELDS = {
|
||||
name: true,
|
||||
url: true,
|
||||
account: true,
|
||||
keyId: true,
|
||||
insecure: true
|
||||
};
|
||||
|
||||
|
||||
// --- internal support stuff
|
||||
|
||||
// TODO: improve this validation
|
||||
function _validateProfile(profile) {
|
||||
// TODO: improve this validation: use ConfigError's instead of asserts
|
||||
function _validateProfile(profile, profilePath) {
|
||||
assert.object(profile, 'profile');
|
||||
assert.string(profile.name, 'profile.name');
|
||||
assert.string(profile.url, 'profile.url');
|
||||
assert.string(profile.account, 'profile.account');
|
||||
assert.string(profile.keyId, 'profile.keyId');
|
||||
assert.optionalBool(profile.insecure, 'profile.insecure');
|
||||
// TODO: error on extraneous params
|
||||
assert.optionalString(profilePath, 'profilePath');
|
||||
|
||||
var bogusFields = [];
|
||||
Object.keys(profile).forEach(function (field) {
|
||||
if (!PROFILE_FIELDS[field]) {
|
||||
bogusFields.push(field);
|
||||
}
|
||||
});
|
||||
if (bogusFields.length) {
|
||||
throw new errors.ConfigError(format(
|
||||
'extraneous fields in "%s" profile: %s%s', profile.name,
|
||||
(profilePath ? profilePath + ': ' : ''), bogusFields.join(', ')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -228,9 +248,14 @@ function _profileFromPath(profilePath, name) {
|
||||
'error in "%s" profile: %s: %s', name,
|
||||
profilePath, e.message));
|
||||
}
|
||||
if (profile.name) {
|
||||
throw new errors.ConfigError(format(
|
||||
'error in "%s" profile: %s: file must not include "name" field',
|
||||
name, profilePath));
|
||||
}
|
||||
profile.name = name;
|
||||
|
||||
_validateProfile(profile);
|
||||
_validateProfile(profile, profilePath);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
Reference in New Issue
Block a user