Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit b64e448

Browse files
author
Chris Wiechmann
committed
logger variable is no longer global
Fixes #62
1 parent f082cd1 commit b64e448

File tree

1 file changed

+25
-22
lines changed
  • apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/src

1 file changed

+25
-22
lines changed

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/src/actions.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const path = require('path');
55

66
var pluginConfig = {};
77
var cache = {};
8-
var logger;
98

109
const securityDeviceTypes = {
1110
apiKey: "API-Key",
@@ -41,7 +40,7 @@ const securityDeviceTypes = {
4140
*/
4241
async function lookupCurrentUser(params, options) {
4342
const { requestHeaders, apiManagerUserRequired } = params;
44-
logger = options.logger;
43+
const logger = options.logger;
4544
cache = options.pluginContext.cache;
4645
pluginConfig = options.pluginConfig;
4746
var user = {};
@@ -92,7 +91,7 @@ async function lookupCurrentUser(params, options) {
9291
throw new Error(`User: '${user.loginName}' not found in API-Manager.`);
9392
}
9493
user.apiManager = users[0];
95-
var org = await _getOrganization(user.apiManager);
94+
var org = await _getOrganization(user.apiManager, null, null, options);
9695
user.apiManager.organizationName = org.name;
9796
logger.debug(`User: '${user.loginName}' (Role: ${user.apiManager.role}) found in API-Manager. Organization: '${user.apiManager.organizationName}'`);
9897
if(VIDUSR) {
@@ -103,7 +102,7 @@ async function lookupCurrentUser(params, options) {
103102

104103
async function lookupAPIDetails(params, options) {
105104
var { apiName, apiPath, operationId, groupId, region, mapCustomProperties } = params;
106-
logger = options.logger;
105+
const { logger } = options;
107106
cache = options.pluginContext.cache;
108107
pluginConfig = options.pluginConfig;
109108
if (!apiPath) {
@@ -151,7 +150,7 @@ async function lookupAPIDetails(params, options) {
151150
}
152151
// Skip the lookups if the API is locally configured and just take it as it is
153152
if(!apiProxy.locallyConfigured) {
154-
var org = await _getOrganization(apiProxy, groupId, region);
153+
var org = await _getOrganization(apiProxy, groupId, region, options);
155154
apiProxy.organizationName = org.name;
156155
apiProxy.apiSecurity = await _getAPISecurity(apiProxy, operationId);
157156
apiProxy.requestPolicy = await _getRequestPolicy(apiProxy, operationId);
@@ -170,7 +169,7 @@ async function lookupAPIDetails(params, options) {
170169
delete apiProxy.serviceProfiles;
171170
delete apiProxy.caCerts;
172171
if(mapCustomProperties) {
173-
apiProxy = await _addCustomProperties(apiProxy, groupId, region);
172+
apiProxy = await _addCustomProperties(apiProxy, groupId, region, options);
174173
}
175174
}
176175
logger.info(`Return looked up API details based on API-Name: '${apiName}' and apiPath: '${apiPath}': ${JSON.stringify(apiProxy)}`);
@@ -180,7 +179,7 @@ async function lookupAPIDetails(params, options) {
180179

181180
async function isIgnoreAPI(params, options) {
182181
var { apiPath, policyName, region, groupId } = params;
183-
logger = options.logger;
182+
const { logger } = options;
184183
cache = options.pluginContext.cache;
185184
pluginConfig = options.pluginConfig;
186185
if (!apiPath && !policyName) {
@@ -218,13 +217,14 @@ async function isIgnoreAPI(params, options) {
218217
async function getCustomPropertiesConfig(params, options) {
219218
const { groupId, region } = params;
220219
pluginConfig = options.pluginConfig;
221-
logger = options.logger;
220+
const { logger } = options;
222221
cache = options.pluginContext.cache;
223-
return await _getConfiguredCustomProperties(groupId, region);
222+
return await _getConfiguredCustomProperties(groupId, region, options);
224223
}
225224

226225
async function _getAPILocalProxies(params, options) {
227226
var { apiPath, groupId, region, policyName } = params;
227+
const { logger } = options;
228228
const lookupFile = options.pluginConfig.localLookupFile;
229229
if(lookupFile != undefined && lookupFile != "") {
230230
var localAPIConfig = {};
@@ -235,11 +235,11 @@ async function _getAPILocalProxies(params, options) {
235235
logger.error(`Error reading API-Lookup file: '${lookupFile}'. Error: ${ex}`);
236236
return;
237237
}
238-
options.logger.info(`Reading API-Details from local file: ${lookupFile}`);
238+
logger.info(`Reading API-Details from local file: ${lookupFile}`);
239239
localAPIConfig = { ...localProxies };
240240
var filenames = await _getGroupRegionFilename(lookupFile, groupId, region);
241241
if(filenames.groupFilename) {
242-
options.logger.info(`Reading API-Details from local file: ${lookupFile}`);
242+
logger.info(`Reading API-Details from local file: ${lookupFile}`);
243243
var groupProxies = JSON.parse(fs.readFileSync(filenames.groupFilename), null);
244244
localAPIConfig[groupId] = groupProxies;
245245
}
@@ -258,20 +258,21 @@ async function _getAPILocalProxies(params, options) {
258258
return proxy;
259259
}
260260
} else {
261-
options.logger.debug(`No local API-Lookup file configured.`);
261+
logger.debug(`No local API-Lookup file configured.`);
262262
return;
263263
}
264264
}
265265

266266
async function _getLocalProxy(localProxies, apiPath, policyName, scope, options) {
267+
const { logger } = options;
267268
if(localProxies == undefined) {
268-
options.logger.warn(`No configuration found in file (${scope}).`);
269+
logger.warn(`No configuration found in file (${scope}).`);
269270
return;
270271
}
271272
var foundProxy;
272273
// If a policy is given, it is used separately for the lookup
273274
if(policyName != undefined && policyName != "") {
274-
options.logger.info(`Looking up information based on policy name: ${policyName}`);
275+
logger.info(`Looking up information based on policy name: ${policyName}`);
275276
if(localProxies[`Policy: ${policyName}`]) {
276277
foundProxy = localProxies[`Policy: ${policyName}`];
277278
}
@@ -290,10 +291,10 @@ async function _getLocalProxy(localProxies, apiPath, policyName, scope, options)
290291
};
291292
// Perhaps, we have direct hit with the API-Path
292293
if(localProxies[apiPath]) {
293-
options.logger.info(`API-Details found based on API-Path: ${apiPath}`);
294+
logger.info(`API-Details found based on API-Path: ${apiPath}`);
294295
foundProxy = localProxies[apiPath];
295296
} else {
296-
options.logger.info(`Try to find API-Details starting with: ${apiPath}`);
297+
logger.info(`Try to find API-Details starting with: ${apiPath}`);
297298
// Iterate over all configured API-Proxies
298299
for (const [key, val] of Object.entries(localProxies)) {
299300
if(apiPath.startsWith(key)) {
@@ -304,12 +305,12 @@ async function _getLocalProxy(localProxies, apiPath, policyName, scope, options)
304305
}
305306
// If we don't have a match return nothing
306307
if(foundProxy==undefined) {
307-
options.logger.warn(`No API-Details found for API-Path: ${apiPath}`);
308+
logger.warn(`No API-Details found for API-Path: ${apiPath}`);
308309
return;
309310
}
310311
// Take over the configuration, preserve the default values
311312
proxy = {...proxy, ...foundProxy};
312-
options.logger.warn(`Found API-Details for API-Path: ${JSON.stringify(apiPath)}`);
313+
logger.warn(`Found API-Details for API-Path: ${JSON.stringify(apiPath)}`);
313314
var proxies = [];
314315
proxy.path = apiPath; // Copy the path, as it's normally returned by the API-Manager and used for caching
315316
proxies.push(proxy);
@@ -347,8 +348,8 @@ async function _getCurrentGWUser(requestHeaders) {
347348
return loginName;
348349
}
349350

350-
async function _addCustomProperties(apiProxy, groupId) {
351-
var apiCustomProperties = await _getConfiguredCustomProperties(groupId);
351+
async function _addCustomProperties(apiProxy, groupId, region, options) {
352+
var apiCustomProperties = await _getConfiguredCustomProperties(groupId, region, options);
352353
apiProxy.customProperties = {};
353354
for (var prop in apiCustomProperties) {
354355
if (Object.prototype.hasOwnProperty.call(apiCustomProperties, prop)) {
@@ -495,7 +496,8 @@ async function _getAPIProxy(apiName, groupId, region) {
495496
return apiProxy;
496497
}
497498

498-
async function _getOrganization(apiProxy, groupId, region) {
499+
async function _getOrganization(apiProxy, groupId, region, options) {
500+
const { logger } = options;
499501
if(apiProxy.locallyConfigured) {
500502
if(apiProxy.organizationName == undefined) apiProxy.organizationName = "N/A";
501503
return apiProxy;
@@ -535,7 +537,8 @@ async function _getOrganization(apiProxy, groupId, region) {
535537
return org;
536538
}
537539

538-
async function _getConfiguredCustomProperties(groupId, region) {
540+
async function _getConfiguredCustomProperties(groupId, region, options) {
541+
const { logger } = options;
539542
const apiManagerConfig = getManagerConfig(pluginConfig.apimanager, groupId, region);
540543
const customPropCacheKey = `CUSTOM_PROPERTIES###${groupId}###${region}`
541544
if(cache.has(customPropCacheKey)) {

0 commit comments

Comments
 (0)