Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async.series(tasks, function (err, results) {
if (err) {
return cb(err);
}
assert(targetFile, 'must have an assigned target file')
// writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP}, 'updating agent configuration');
if (err) {
return cb(err)
}
agentConfigPath = configLocations.getSourcePath(options.org, options.env, options.configDir);
const agentConfig = edgeconfig.load({ source: agentConfigPath });
addEnvVars(agentConfig);
if (options.deployed === false) {
agentConfig['edge_config']['jwt_public_key'] = (options.url ? options.url+"/edgemicro-auth/publicKey" : results[0]); // get deploy results
agentConfig['edge_config'].bootstrap = results[2].bootstrap; // get genkeys results
} else {
agentConfig['edge_config']['jwt_public_key'] = authUri + '/publicKey';
agentConfig['edge_config'].bootstrap = results[1].bootstrap;
}
var publicKeyUri = agentConfig['edge_config']['jwt_public_key'];
if (publicKeyUri) {
agentConfig['edge_config']['products'] = publicKeyUri.replace('publicKey', 'products');
if (!agentConfig.hasOwnProperty('oauth') || agentConfig['oauth'] === null) {
function(err, results) {
if (err) {
return cb(err);
}
const agentConfigPath = sourcePath;
const agentConfig = that.config = edgeconfig.load({
source: agentConfigPath
});
if (options.internaldeployed === false && options.deployed === false) {
agentConfig['edge_config']['jwt_public_key'] = results[2]; // get deploy results
agentConfig['edge_config'].bootstrap = results[4]; // get genkeys results
} else if (options.internaldeployed === true && options.internaldeployed === false) {
agentConfig['edge_config']['jwt_public_key'] = results[0];
agentConfig['edge_config'].bootstrap = results[2];
} else {
agentConfig['edge_config']['jwt_public_key'] = that.authUri + '/publicKey';
agentConfig['edge_config'].bootstrap = results[1];
}
var publicKeyUri = agentConfig['edge_config']['jwt_public_key'];
if (publicKeyUri) {
}
const targetPath = configLocations.getSourcePath(options.org, options.env);
if (fs.existsSync(targetPath)) {
fs.unlinkSync(targetPath);
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'deleted ' + targetPath);
}
options.proxyName = this.name = 'edgemicro-auth';
this.basePath = '/edgemicro-auth';
this.managementUri = options.mgmtUrl;
this.runtimeUrl = options.runtimeUrl;
this.virtualHosts = options.virtualHosts || 'default';
const config = edgeconfig.load({
source: configLocations.getDefaultPath(options.configDir)
});
this.config = config;
this.authUri = config.edge_config.authUri = this.runtimeUrl + this.basePath;
this.config.edge_config.managementUri = this.managementUri;
this.baseUri = this.runtimeUrl + '/edgemicro/%s/organization/%s/environment/%s';
this.vaultName = config.edge_config.vaultName;
this.config.edge_config.baseUri = this.baseUri;
this.deployment = deploymentFx(config.edge_config, this.virtualHosts);
// first: runtimeUri, second: credential, third: org, fourth: env
this.credentialUrl = util.format(this.baseUri, 'credential', options.org, options.env);
this.regionUrl = util.format(this.baseUri, 'region', options.org, options.env);
this.bootstrapUrl = util.format(this.baseUri, 'bootstrap', options.org, options.env);
this.cert = cert(this.config);
this.sourcePath = configLocations.getSourcePath(options.org, options.env);
Cert.prototype.deleteCert = function(options,cb) {
assert(options.org,"org is required");
assert(options.env,"env is required")
assert(options.username || options.token,"username is required");
assert(options.password || options.token,"password is required")
const config = edgeconfig.load({ source: configLocations.getSourcePath(options.org, options.env) });
cert(config).deleteCertWithPassword(options, function(err, msg) {
if ( err ) writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP}, err);
if ( msg ) writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},msg);
if ( cb ) cb(err,msg);
if ( !cb ) process.exit(0);
})
};
Cert.prototype.retrievePublicKeyPrivate = function(options) {
if (!options.org) { return optionError.bind(options)('org is required'); }
if (!options.env) { return optionError.bind(options)('env is required'); }
const config = edgeconfig.load({source:configLocations.getSourcePath(options.org,options.env)});
cert(config).retrievePublicKeyPrivate((err,certificate)=>{
if(err){
return console.error(err,'failed to retrieve public key')
}
console.log('succeeded');
console.log(certificate);
})
}
Token.prototype.getToken = function(options, cb) {
assert(options.org);
assert(options.env);
assert(options.id);
assert(options.secret);
const targetPath = configLocations.getSourcePath(options.org, options.env);
const key = options.key;
const secret = options.secret;
const keys = { key: key, secret: secret };
const config = edgeconfig.load({ source: targetPath, keys: keys });
const authUri = config.edge_config['authUri'];
this.isPublicCloud = config.edge_config['managementUri'] === 'https://api.enterprise.apigee.com' ||
config.edge_config['managementUri'] === 'https://api.e2e.apigee.net';
const uri = this.isPublicCloud ? util.format(authUri + '/token', options.org, options.env) : authUri + '/token';
const body = {
client_id: options.id,
client_secret: options.secret,
grant_type: 'client_credentials'
};
request({
uri: uri,
method: 'POST',
json: body
}, function(err, res) {
if (err) {
if ( cb ) cb(err)
fs.exists(options.target, (exists) => {
if (exists) {
const config = edgeConfig.load({ source: options.target });
const keys = {key: config.analytics.key, secret: config.analytics.secret};
startServer(keys, options.pluginDir, config, cb);
} else {
return cb(options.target+" must exist")
}
});
};
Configure.prototype.configure = function configure(options, cb) {
if (!fs.existsSync(configLocations.getDefaultPath(options.configDir))) {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},"Missing %s, Please run 'edgemicro init'",configLocations.getDefaultPath())
return cb("Please call edgemicro init first")
}
defaultConfig = edgeconfig.load({ source: configLocations.getDefaultPath(options.configDir) });
addEnvVars(defaultConfig);
deployAuth = deployAuthLib(defaultConfig.edge_config, null)
managementUri = defaultConfig.edge_config.managementUri;
keySecretMessage = defaultConfig.edge_config.keySecretMessage;
if(!options.token) {
assert(options.username, 'username is required');
assert(options.password, 'password is required');
}
assert(options.org, 'org is required');
assert(options.env, 'env is required');
if(!options.proxyName) {
options.proxyName = 'edgemicro-auth';
}
KeyGen.prototype.revoke = function(options, cb) {
const config = edgeconfig.load({
source: configLocations.getSourcePath(options.org, options.env)
});
const baseUri = config.edge_config.baseUri;
const regionUrl = util.format(baseUri, 'region', options.org, options.env);
const keys = {
key: options.key
};
debug('getting region from', regionUrl);
request({
uri: regionUrl,
auth: generateCredentialsObject(options),
json: true
}, function(err, res) {
KeyGen.prototype.generate = function generate(options, cb) {
const config = edgeconfig.load({ source: configLocations.getSourcePath(options.org,options.env) });
this.baseUri = config.edge_config.baseUri;
this._generate(options, (err, result) => {
if(err){
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},"failed")
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},err)
cb(err);
}
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP},config.edge_config.bootstrapMessage);
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP},' bootstrap:', result.bootstrap);
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP});
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP},config.edge_config.keySecretMessage);
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP},' key:', result.key);
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP},' secret:', result.secret);
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP});
writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'finished');