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

Commit 05f6aba

Browse files
author
Chris Wiechmann
committed
Don't include serviceId filter for getInfo & Circuit-Path if EMT is enabled
1 parent 1761299 commit 05f6aba

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-traffic-monitor-api-utils/src/actions.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function handleFilterFields(parameters, options) {
135135

136136

137137
async function createCircuitPathQuery(parameters, options) {
138-
const { params, user, authzConfig } = parameters;
138+
const { params, user, authzConfig, gatewayTopology } = parameters;
139139
const { logger } = options;
140140
if (!params) {
141141
throw new Error('Missing required parameter: params');
@@ -149,14 +149,21 @@ async function createCircuitPathQuery(parameters, options) {
149149
if (!params.correlationID) {
150150
throw new Error('Missing required parameter: params.correlationID');
151151
}
152-
if (!params.serviceID) {
153-
throw new Error('Missing required parameter: params.serviceID');
152+
if (!gatewayTopology) {
153+
throw new Error('Missing required parameter: gatewayTopology');
154+
}
155+
if (!gatewayTopology.emtEnabled && !params.serviceID) {
156+
throw new Error('Missing required parameter: params.serviceID when not using EMT.');
154157
}
155158
var elasticQuery = { bool: { must: [
156159
{ term: { correlationId: params.correlationID } },
157-
{ term: { 'processInfo.serviceId': params.serviceID } }
158160
] }
159161
};
162+
if(!gatewayTopology.emtEnabled) { // Don't include serviceId filter, if EMT is enabled
163+
elasticQuery.bool.must.push(
164+
{ term: { 'processInfo.serviceId': params.serviceID } }
165+
);
166+
}
160167
// If user is an Admin or AuthZ is disabled, return the base query
161168
if (user.gatewayManager.isAdmin || authzConfig.enableUserAuthorization == false) {
162169
return elasticQuery;

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-traffic-monitor-api-utils/src/flow-nodes.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ flow-nodes:
131131
required: true
132132
schema:
133133
type: object
134-
134+
gatewayTopology:
135+
name: API-Gateway Topology
136+
description: "The API-Gateway topology as read by flow-node: axway-api-management->lookupTopology"
137+
required: true
138+
schema:
139+
type: object
135140
returns:
136141
name: Next
137142
description: Returns the created search query for the circuit path

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-traffic-monitor-api-utils/test/testCreateCircuitPathQuery.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { expect } = require('chai');
22
const { MockRuntime } = require('@axway/api-builder-test-utils');
33
const getPlugin = require('../src');
4+
const fs = require('fs');
45

56
describe('Flow node CreateCircuitPath query', () => {
67
let plugin;
@@ -44,15 +45,15 @@ describe('Flow node CreateCircuitPath query', () => {
4445
});
4546

4647
it('should error when required parameter params.serviceId is missing', async () => {
47-
const { value, output } = await flowNode.createCircuitPathQuery({ params: { correlationID: 123 }, user: {}, authzConfig: {} } );
48+
const { value, output } = await flowNode.createCircuitPathQuery({ params: { correlationID: 123 }, user: {}, authzConfig: {}, gatewayTopology: {} } );
4849

4950
expect(value).to.be.instanceOf(Error)
50-
.and.to.have.property('message', 'Missing required parameter: params.serviceID');
51+
.and.to.have.property('message', 'Missing required parameter: params.serviceID when not using EMT.');
5152
expect(output).to.equal('error');
5253
});
5354

5455
it('should succeed with valid parameters as an API-Manager User', async () => {
55-
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, user: {
56+
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, gatewayTopology: {}, user: {
5657
apiManager: { role: "user", organizationName: "Test-Org" },
5758
gatewayManager: {}
5859
}, authzConfig: {
@@ -73,7 +74,7 @@ describe('Flow node CreateCircuitPath query', () => {
7374
});
7475

7576
it('should succeed with valid parameters having API-Manager Org-AuthZ disabled', async () => {
76-
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, user: {
77+
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, gatewayTopology: {}, user: {
7778
apiManager: { role: "user", organizationName: "Test-Org" },
7879
gatewayManager: {}
7980
}, authzConfig: {
@@ -93,7 +94,7 @@ describe('Flow node CreateCircuitPath query', () => {
9394
});
9495

9596
it('should succeed with valid parameters with API-Manager Admin-Role', async () => {
96-
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, user: {
97+
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, gatewayTopology: {}, user: {
9798
apiManager: { role: "admin", organizationName: "Test-Org" },
9899
gatewayManager: {}
99100
}, authzConfig: {
@@ -112,5 +113,26 @@ describe('Flow node CreateCircuitPath query', () => {
112113
}
113114
});
114115
});
116+
117+
it('should succeed when EMT is enabled', async () => {
118+
var topology = JSON.parse(fs.readFileSync('./test/mockedReplies/emtTopology.json'), null);
119+
const { value, output } = await flowNode.createCircuitPathQuery( { params: { correlationID: "MyCorrelationId", serviceID: "TestServiceId" }, gatewayTopology: topology, user: {
120+
apiManager: { role: "admin", organizationName: "Test-Org" },
121+
gatewayManager: {}
122+
}, authzConfig: {
123+
apimanagerOrganization: { enabled: true }
124+
} } );
125+
126+
expect(output).to.equal('next');
127+
expect(value).to.be.a('object');
128+
expect(value).to.deep.equal({
129+
bool: {
130+
must: [
131+
{ term: { correlationId: "MyCorrelationId" } },
132+
{ exists: { field: "transactionSummary.serviceContext" } }
133+
]
134+
}
135+
});
136+
});
115137
});
116138
});

0 commit comments

Comments
 (0)