Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function deployProject(account, project, options, cb) {
var opts = buildApigeetoolOpts(account, {
api: project.api.name,
main: project.api.main,
directory: project.dirname,
'base-path': project.api.basePath,
'import-only': !!options.importOnly,
'resolve-modules': !options.upload,
virtualhosts: account.virtualhosts,
environments: account.environment
});
delete(opts.environment);
apigeetool.deployNodeApp(opts, function(err, results) {
if (err) {
if (err.code === 'ECONNRESET' && err.message === 'socket hang up') {
err.message = 'Deployment timeout. Please try again or use the --upload option.'
}
return cb(err);
}
emit('');
emit({ Deployed: results });
if (!results) { return cb(); } // todo: temp fix to avoid error in existing tests, remove when tests have been updated
async.each(results, function(result, cb) {
addResources(account, project, result, cb);
}, cb);
});
//writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'checking for previously deployed proxies')
const opts = {
organization: options.org,
api: 'edgemicro-internal',
baseuri: this.managementUri,
debug: options.debug
};
if (options.token) {
opts.token = options.token;
} else {
opts.username = options.username;
opts.password = options.password;
}
// const that = this;
apigeetool.listDeployments(opts, function(err /*, proxies */) {
if (err) {
if (err.message.includes("404")) {
return cb(null, options);
} else {
return cb(err, options);
}
}
else {
options.internaldeployed = true;
cb(null, options);
}
});
}
if (options.baseuri && options.organization &&
options.username && options.password &&
options.environments && options.virtualhosts) {
var deploymentOptions = {}
deploymentOptions.directory = destination + '/' + apiProxy
deploymentOptions.api = apiProxy
deploymentOptions.baseuri = options.baseuri
deploymentOptions.organization = options.organization
deploymentOptions.username = options.username
deploymentOptions.password = options.password
deploymentOptions.environments = options.environments
deploymentOptions.virtualhosts = options.virtualhosts
// deploymentOptions.verbose = true;
// deploymentOptions.debug = true;
// deploymentOptions['import-only'] = true;
apigeetool.deployProxy(deploymentOptions, function (err) {
if (err) {
return cb(err, {})
}
return cb(null, {})
})
} else {
inquirer.prompt(questions).then(function (answers) {
answers.directory = destination + '/' + apiProxy
answers.api = apiProxy
apigeetool.deployProxy(answers, function (err) {
if (err) {
return cb(err, {})
}
return cb(null, {})
})
})
virtualhosts: options.virtualHosts || DEFAULT_HOSTS
};
if (options.token) {
opts.token = options.token;
} else {
opts.username = options.username;
opts.password = options.password;
}
editVirtualHosts(dir + "/apiproxy/proxies/default.xml", opts.virtualhosts);
//set the edgemicro-internal endpoint in edgemicro-auth
if (options.runtimeUrl) {
setEdgeMicroInternalEndpoint(dir + "/apiproxy/policies/Authenticate-Call.xml", options.runtimeUrl);
}
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'Give me a minute or two... this can take a while...');
apigeetool.deployProxy(opts, function(err) {
if (err) {
if (err.code === 'ECONNRESET' && err.message === 'socket hang up') {
err.message = 'Deployment timeout. Please try again or use the --upload option.'
} else if (err.message === 'Get API info returned status 401') {
err.message = 'Invalid credentials or not sufficient permission. Please correct and try again.'
}
return callback(err);
} else {
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'App %s deployed.', options.proxyName);
callback(null, options.runtimeUrl ? authUri + '/publicKey' : util.format(authUri + '/publicKey', options.org, options.env));
}
//writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'App %s added to your org. Now adding resources.', options.proxyName);
/* opts.password = options.password; // override a apigeetool side-effect bug
installJavaCallout(managementUri, opts, function(err) {
function deleteCaches(c,cb){
var sdk = apigeetool.getPromiseSDK()
var opts = baseopts()
console.log('deleting cache ' + c.name)
opts.cache = c.name
console.log(opts)
cb(null,sdk.deletecache(opts))
}
function deleteApis(it,cb){
var sdk = apigeetool.getPromiseSDK()
var opts = baseopts()
opts.directory = it.dir
opts.api = it.proxy
console.log('undeploying ' + opts.api)
sdk.undeploy(opts)
.then(function(){
console.log('undeployed ' + opts.api)
return sdk.delete(opts)
},function(err){
console.log(err)
return sdk.delete(opts)
})
.then(function(){
console.log('deleted ' + opts.api)
cb(null, 'done')
},function(err){
gulp.task('clean',function(){
opts.api = PROXY_NAME
opts.proxies = PROXY_NAME
opts.environments = 'test'
var sdk = apigeetool.getPromiseSDK()
return sdk.undeploy(opts)
.then(function(){ return sdk.delete(opts)})
console.log(app)
})
gulp.task('deploy',function(){
opts.api = proxy_name
return apigeetool.getPromiseSDK()
.deployProxy(opts)
})
function createApp(app){
var defer = q.defer()
var sdk = apigeetool.getPromiseSDK()
var opts=baseopts()
opts.name = app.name
opts.apiProducts = app.apiProducts
opts.email = app.email
opts.callback = app.callback
sdk.createApp(opts)
.then(function(appresponse){
defer.resolve(appresponse)
},function(err){
defer.reject(err)
})
return defer.promise
}
gulp.task('deploy',function(){
opts.api = proxy_name
return apigeetool.getPromiseSDK()
.deployProxy(opts)
})