@vroomlabs/gsdk-deploy
Version:
Google Cloud deployment script for kubernetes clusters using Global Load Balancer
74 lines (46 loc) • 2.77 kB
JavaScript
;
/******************************************************************************
* MIT License
* Copyright (c) 2017 https://github.com/vroomlabs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Created by rogerk on 7/2/17.
******************************************************************************/
/**
* Replace any environment variable in supplied text
* @param {string} input
* @param {object=} values
*/Object.defineProperty(exports,'__esModule',{value:true});var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};exports.
replaceInText=replaceInText;exports.
replaceInObject=replaceInObject;function replaceInText(input,values){if(typeof input!=='string'){return input}if(!values){values=process.env}return input.replace(/\$(([a-z0-9]+(_[a-z0-9]+)*)|(\(([\w\-_]+)\))|({([\w\-_]+)}))/gi,function(text,g1,m1,g3,g4,m2,g6,m3){var name=(m1||m2||m3).toUpperCase();if(!name||!values.hasOwnProperty(name)){throw new Error('The variable "'+name+'" is not defined.')}return values[name]})}/**
* @param obj
* @param {object=} values
* @param {filter=} filter
*/function replaceInObject(obj,values,filter){filter=filter||{};if(typeof obj==='string'){obj=replaceInText(obj,values)}else
if(Array.isArray(obj)){
obj=obj.map(function(item){return replaceInObject(item,values,filter)});
}else
if((typeof obj==='undefined'?'undefined':_typeof(obj))==='object'){
var keys=Object.keys(obj);
for(var ix=0;ix<keys.length;ix++){
if(!filter[keys[ix]])
obj[keys[ix]]=replaceInObject(obj[keys[ix]],values,filter);
}
}
return obj;
}