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

Commit 34c691a

Browse files
author
Chris Wiechmann
committed
pluginConfig is a const - Parsed config must be merged #76
1 parent 2cfabdb commit 34c691a

File tree

5 files changed

+48
-46
lines changed

5 files changed

+48
-46
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ async function getPlugin(pluginConfig, options) {
3232
if(!pluginConfig.apigateway.url) {
3333
throw new Error(`Required parameter: apigateway.url is not set.`);
3434
}
35-
pluginConfig.apimanager = await parseAPIManagerConfig(pluginConfig, options);
35+
await parseAPIManagerConfig(pluginConfig, options);
3636
if(pluginConfig.validateConfig==true) {
37-
var isValid = await checkAPIManagers(pluginConfig.apimanager, options);
38-
if(!isValid) {
39-
throw new Error(`Error checking configured API-Manager(s). ${JSON.stringify(pluginConfig.apimanager)}`);
37+
var result = await checkAPIManagers(pluginConfig.apimanager, options);
38+
if(!result.isValid) {
39+
throw new Error(`Error checking configured API-Manager(s). ${JSON.stringify(result)}`);
4040
} else {
4141
options.logger.info("Connection to API-Manager successfully validated.");
4242
}

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ function isDeveloperMode() {
8686
}
8787

8888
async function parseAPIManagerConfig(pluginConfig, options) {
89-
var configuredManagers = {};
9089
if(!pluginConfig.apimanager.username) {
9190
throw new Error(`Required parameter: apimanager.username is not set.`)
9291
}
@@ -98,49 +97,44 @@ async function parseAPIManagerConfig(pluginConfig, options) {
9897
const managerURL = new URL(pluginConfig.apigateway.url);
9998
managerURL.port = 8075;
10099
options.logger.info(`Parameter API_MANAGER not set. Expect API-Manager on URL: ${managerURL.toString()}`);
101-
configuredManagers = {
102-
default: {
100+
pluginConfig.apimanager.default = {
103101
url: managerURL.toString(),
104102
username: pluginConfig.apimanager.username,
105103
password: pluginConfig.apimanager.password
106-
}
107104
}
108105
} else {
109106
// Check, if multiple API-Manager URLs based on the groupId and regions are given (Format: groupId|managerUrl or groupId|region|managerUrl)
110107
if(pluginConfig.apimanager.url.indexOf('|')!=-1) {
111-
configuredManagers.perGroupAndRegion = true;
108+
pluginConfig.apimanager.perGroupAndRegion = true;
112109
options.logger.info(`Parse group/region based API_MANAGER: ${pluginConfig.apimanager.url}.`);
113110
// Looks like manager URLs are given based on groupIds and regions
114111
pluginConfig.apimanager.url.split(',').forEach(groupRegionAndURL => {
115112
groupRegionAndURL = groupRegionAndURL.trim().toLowerCase().split('|');
116113
if(groupRegionAndURL.length == 1) {
117114
// The default API-Manager
118115
options.logger.debug(`Found default API-Manager URL: ${groupRegionAndURL[0]}`);
119-
configuredManagers.default = { url: groupRegionAndURL[0], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password }
116+
pluginConfig.apimanager.default = { url: groupRegionAndURL[0], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password }
120117
} else if(groupRegionAndURL.length == 2) {
121118
// Only the Group-ID is given
122119
options.logger.debug(`Found API-Manager URL: ${groupRegionAndURL[1]} for group: ${groupRegionAndURL[0]}`);
123-
configuredManagers[groupRegionAndURL[0]] = { url: groupRegionAndURL[1], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password }
120+
pluginConfig.apimanager[groupRegionAndURL[0]] = { url: groupRegionAndURL[1], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password }
124121
} else if(groupRegionAndURL.length == 3) {
125122
// Group-ID and region is given (Just create a map with a special key)
126123
options.logger.debug(`Found API-Manager URL: ${groupRegionAndURL[2]} for group: ${groupRegionAndURL[1]} and region: ${groupRegionAndURL[1]}`);
127-
configuredManagers[`${groupRegionAndURL[0]}###${groupRegionAndURL[1]}`] = { url: groupRegionAndURL[2], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password}
124+
pluginConfig.apimanager[`${groupRegionAndURL[0]}###${groupRegionAndURL[1]}`] = { url: groupRegionAndURL[2], username: pluginConfig.apimanager.username, password: pluginConfig.apimanager.password}
128125
} else {
129126
return Promise.reject(`Unexpected API-Manager format: ${groupRegionAndURL}`);
130127
}
131128
});
132129
} else { // If not, create a default API-Manager
133130
options.logger.info(`Using only default API_MANAGER: ${pluginConfig.apimanager.url}.`);
134-
configuredManagers = {
135-
default: {
136-
url: pluginConfig.apimanager.url,
137-
username: pluginConfig.apimanager.username,
138-
password: pluginConfig.apimanager.password
139-
}
131+
pluginConfig.apimanager.default = {
132+
url: pluginConfig.apimanager.url,
133+
username: pluginConfig.apimanager.username,
134+
password: pluginConfig.apimanager.password
140135
}
141136
}
142137
}
143-
return configuredManagers;
144138
}
145139

146140
function getManagerConfig(apiManagerConfig, groupId, region) {
@@ -168,9 +162,10 @@ function getManagerConfig(apiManagerConfig, groupId, region) {
168162
}
169163

170164
async function checkAPIManagers(apiManagerConfig, options) {
171-
var finalResult = true;
165+
var finalResult = { isValid: true };
172166
for (const [key, config] of Object.entries(apiManagerConfig)) {
173-
if(key == "perGroupAndRegion") continue;
167+
if(typeof config != 'object') continue;
168+
finalResult[key] = config;
174169
try {
175170
var data = `username=${config.username}&password=${config.password}`;
176171
var reqOptions = {
@@ -206,10 +201,10 @@ async function checkAPIManagers(apiManagerConfig, options) {
206201
});
207202
if(currentUser.body.role!='admin') {
208203
options.logger.error(`User: ${currentUser.body.loginName} has no admin role on API-Manager: ${config.url}.`);
209-
config.isValid = false;
210-
finalResult = false;
204+
finalResult.isValid = false;
205+
finalResult[key].isValid = false;
211206
} else {
212-
config.isValid = true;
207+
finalResult[key].isValid = true;
213208
}
214209
} catch (ex) {
215210
options.logger.error(ex);

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/test/test-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('Configuration parameter tests', () => {
9292
expect(output).to.equal('error');
9393
} catch(e) {
9494
expect(e).to.be.an('Error')
95-
.and.to.have.property('message', 'Error checking configured API-Manager(s). {"default":{"url":"https://mocked-api-gateway:8175","username":"user","password":"invalid","isValid":false}}');
95+
.and.to.have.property('message', 'Error checking configured API-Manager(s). {"isValid":false,"default":{"url":"https://mocked-api-gateway:8175","username":"user","password":"invalid","isValid":false}}');
9696
}
9797
nock.cleanAll();
9898
});

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/test/testManagerConfigs.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,51 @@ describe('Test API-Manager configuration variations', () => {
1313

1414
describe('Test API-Manager parsing', () => {
1515
it('should succeed with a single API-Manager configured', async () => {
16-
debugger;
17-
var pluginConfig = {
16+
const pluginConfig = {
1817
apimanager: {
1918
url: "http://my.api-manager.com:8075",
2019
username: "user", password: "password"
2120
}
2221
};
2322
var expectedManagers = {
23+
url: "http://my.api-manager.com:8075", username: "user", password: "password",
2424
"default": {
2525
url: "http://my.api-manager.com:8075",
2626
username: "user", password: "password"
2727
}
2828
}
29-
var configuredManagers = await parseAPIManagerConfig(pluginConfig, options);
30-
expect(configuredManagers).to.deep.equal(expectedManagers);
29+
await parseAPIManagerConfig(pluginConfig, options);
30+
expect(pluginConfig.apimanager).to.deep.equal(expectedManagers);
3131
});
3232

3333
it('should succeed without giving an API-Manager', async () => {
34-
var pluginConfig = {
34+
const pluginConfig = {
3535
apigateway: { url: "http://my.api-gateway.com:8090" },
3636
apimanager: {
3737
username: "user", password: "password"
3838
}
3939
};
4040
var expectedManagers = {
41+
username: "user", password: "password",
4142
"default": {
4243
url: "http://my.api-gateway.com:8075/",
4344
username: "user", password: "password"
4445
}
4546
}
46-
var configuredManagers = await parseAPIManagerConfig(pluginConfig, options);
47-
expect(configuredManagers).to.deep.equal(expectedManagers);
47+
await parseAPIManagerConfig(pluginConfig, options);
48+
expect(pluginConfig.apimanager).to.deep.equal(expectedManagers);
4849
});
4950

5051
it('should succeed with a default plus group based API-Manager', async () => {
51-
var pluginConfig = {
52+
const pluginConfig = {
5253
apimanager: {
5354
url: "http://my.api-manager.com:8075, group-a|http://my.group-a-api-manager.com:8075",
5455
username: "user", password: "password"
5556
}
5657
};
5758
var expectedManagers = {
59+
url: "http://my.api-manager.com:8075, group-a|http://my.group-a-api-manager.com:8075",
60+
username: "user", password: "password",
5861
"perGroupAndRegion": true,
5962
"default": {
6063
url: "http://my.api-manager.com:8075",
@@ -65,18 +68,20 @@ describe('Test API-Manager configuration variations', () => {
6568
username: "user", password: "password"
6669
}
6770
}
68-
var configuredManagers = await parseAPIManagerConfig(pluginConfig, options);
69-
expect(configuredManagers).to.deep.equal(expectedManagers);
71+
await parseAPIManagerConfig(pluginConfig, options);
72+
expect(pluginConfig.apimanager).to.deep.equal(expectedManagers);
7073
});
7174

7275
it('should succeed with a default plus group plus region based API-Manager', async () => {
73-
var pluginConfig = {
76+
const pluginConfig = {
7477
apimanager: {
7578
url: "http://my.api-manager.com:8075, group-a|http://my.group-a-api-manager.com:8075, group-b|US|http://my.group-b-us-api-manager.com:8075",
7679
username: "user", password: "password"
7780
}
7881
};
7982
var expectedManagers = {
83+
url: "http://my.api-manager.com:8075, group-a|http://my.group-a-api-manager.com:8075, group-b|US|http://my.group-b-us-api-manager.com:8075",
84+
username: "user", password: "password",
8085
"perGroupAndRegion": true,
8186
"default": {
8287
url: "http://my.api-manager.com:8075",
@@ -91,18 +96,20 @@ describe('Test API-Manager configuration variations', () => {
9196
username: "user", password: "password"
9297
}
9398
}
94-
var configuredManagers = await parseAPIManagerConfig(pluginConfig, options);
95-
expect(configuredManagers).to.deep.equal(expectedManagers);
99+
await parseAPIManagerConfig(pluginConfig, options);
100+
expect(pluginConfig.apimanager).to.deep.equal(expectedManagers);
96101
});
97102

98103
it('should succeed without a default API-Manager only group based', async () => {
99-
var pluginConfig = {
104+
const pluginConfig = {
100105
apimanager: {
101106
url: "group-a|http://my.group-a-api-manager.com:8075, group-b|US|http://my.group-b-us-api-manager.com:8075",
102107
username: "user", password: "password"
103108
}
104109
};
105110
var expectedManagers = {
111+
url: "group-a|http://my.group-a-api-manager.com:8075, group-b|US|http://my.group-b-us-api-manager.com:8075",
112+
username: "user", password: "password",
106113
"perGroupAndRegion": true,
107114
"group-a": {
108115
url: "http://my.group-a-api-manager.com:8075",
@@ -113,8 +120,8 @@ describe('Test API-Manager configuration variations', () => {
113120
username: "user", password: "password"
114121
}
115122
}
116-
var configuredManagers = await parseAPIManagerConfig(pluginConfig, options);
117-
expect(configuredManagers).to.deep.equal(expectedManagers);
123+
await parseAPIManagerConfig(pluginConfig, options);
124+
expect(pluginConfig.apimanager).to.deep.equal(expectedManagers);
118125
});
119126
});
120127

@@ -134,7 +141,7 @@ describe('Test API-Manager configuration variations', () => {
134141
}
135142
}
136143
var result = await checkAPIManagers(configuredManagers, options);
137-
expect(result).to.equal(true);
144+
expect(result.isValid).to.equal(true);
138145
expect(configuredManagers.default.isValid).to.equal(true);
139146
});
140147

@@ -152,7 +159,7 @@ describe('Test API-Manager configuration variations', () => {
152159
}
153160
}
154161
var result = await checkAPIManagers(configuredManagers, options);
155-
expect(result).to.equal(false);
162+
expect(result.isValid).to.equal(false);
156163
expect(configuredManagers.default.isValid).to.equal(false);
157164
});
158165

@@ -178,7 +185,7 @@ describe('Test API-Manager configuration variations', () => {
178185
},
179186
}
180187
var result = await checkAPIManagers(configuredManagers, options);
181-
expect(result).to.equal(true);
188+
expect(result.isValid).to.equal(true);
182189
expect(configuredManagers.default.isValid).to.equal(true);
183190
expect(configuredManagers.default.isValid).to.equal(true);
184191
});
@@ -205,7 +212,7 @@ describe('Test API-Manager configuration variations', () => {
205212
},
206213
}
207214
var result = await checkAPIManagers(configuredManagers, options);
208-
expect(result).to.equal(false);
215+
expect(result.isValid).to.equal(false);
209216
expect(configuredManagers.default.isValid).to.equal(true);
210217
expect(configuredManagers['group-a'].isValid).to.equal(false);
211218
});

apibuilder4elastic/test/trafficMonitorAPI/restricted/http/test_search_restricted.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Endpoints', function () {
4444
});
4545

4646
describe('Search', () => {
47-
it('[Restricted-Search-0001] Execute a search as Org-Admin without any filter - Only two of them belong to Chris-Org', () => {
47+
it.only('[Restricted-Search-0001] Execute a search as Org-Admin without any filter - Only two of them belong to Chris-Org', () => {
4848
nock('https://mocked-api-gateway:8090').get('/api/rbac/currentuser').reply(200, { "result": "chris" });
4949
nock('https://mocked-api-gateway:8090').get('/api/rbac/permissions/currentuser').replyWithFile(200, './test/mockedReplies/apigateway/operatorChris.json');
5050
nock('https://mocked-api-gateway:8075').get(`/api/portal/v1.3/users?field=loginName&op=eq&value=chris&field=enabled&op=eq&value=enabled`).replyWithFile(200, './test/mockedReplies/apimanager/apiManagerUserChris.json');

0 commit comments

Comments
 (0)