apiconnect-cli-publish-bluemix
Version:
Plugin for IBM API Connect Developer Toolkit
54 lines (47 loc) • 1.7 kB
JavaScript
/********************************************************* {COPYRIGHT-TOP} ***
* Licensed Materials - Property of IBM
* 5725-Z22, 5725-Z63, 5725-U33, 5725-Z63
*
* (C) Copyright IBM Corporation 2016, 2017
*
* All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
********************************************************** {COPYRIGHT-END} **/
// Node module: apiconnect-cli-publish-bluemix
var HEX_4 = '([0-9a-f]{4})'; // 4 lowercase hex digits
var HEX_8 = '([0-9a-f]{8})'; // 8 lowercase hex digits
var HEX_12 = '([0-9a-f]{12})'; // 12 lowercase hex digits
var BLUEMIX_GUID = new RegExp('^' + HEX_8 + '-' + HEX_4 + '-' + HEX_4 + '-' + HEX_4 + '-' + HEX_12 + '$');
module.exports = {
validateBluemixGuid: validateBluemixGuid,
};
/**
* Throw an exception if id is not a valid APIm id.
* Valid APImIds are 24 lower-case hex digit strings like "bc1980f9-b7ea-462e-b44a-42c562a05b79"
* @param {String} name Name of the parameter being validated
* @param {String} guid Bluemix guid to be validated
* @return {String} (valid) guid
* @throws {Error} if guid not valid
*/
function validateBluemixGuid(guid, name) {
var emsg = null;
if (typeof guid !== 'string') {
emsg = 'Bluemix ' + name + ' guid must be type string, not type ' + typeof value;
} else if (!BLUEMIX_GUID.test(guid)) {
emsg = 'Invalid Bluemix ' + name + ' guid pattern for ' + guid;
}
var response = {};
if (emsg) {
response = {
isGuid: false,
message: emsg,
};
return response;
//throw new Error(emsg);
}
response = {
isGuid: true,
};
return response;
}