1
+ /*
2
+ * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3
+ *
4
+ * WSO2 Inc. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /* eslint-disable no-undef */
1
19
const { renderTemplate, renderGivenTemplate, loadLayoutFromAPI, invokeApiRequest } = require ( '../utils/util' ) ;
2
20
const config = require ( process . cwd ( ) + '/config' ) ;
3
21
const constants = require ( '../utils/constants' ) ;
@@ -33,7 +51,7 @@ const loadApplications = async (req, res) => {
33
51
else {
34
52
const orgName = req . params . orgName ;
35
53
const orgID = await orgIDValue ( orgName ) ;
36
- metaData = await getAPIMApplications ( ) ;
54
+ metaData = await getAPIMApplications ( req ) ;
37
55
templateContent = {
38
56
applicationsMetadata : metaData ,
39
57
baseUrl : '/' + orgName
@@ -51,8 +69,8 @@ async function getMockApplications() {
51
69
return mockApplicationsMetaData . list ;
52
70
}
53
71
54
- async function getAPIMApplications ( ) {
55
- const responseData = await invokeApiRequest ( 'GET' , controlPlaneUrl + '/applications' , null , null ) ;
72
+ async function getAPIMApplications ( req ) {
73
+ const responseData = await invokeApiRequest ( req , 'GET' , controlPlaneUrl + '/applications' , null , null ) ;
56
74
return responseData . list ;
57
75
}
58
76
@@ -71,7 +89,7 @@ const loadThrottlingPolicies = async (req, res) => {
71
89
else {
72
90
const orgName = req . params . orgName ;
73
91
const orgID = await orgIDValue ( orgName ) ;
74
- metaData = await getAPIMThrottlingPolicies ( ) ;
92
+ metaData = await getAPIMThrottlingPolicies ( req ) ;
75
93
templateContent = {
76
94
throttlingPoliciesMetadata : metaData ,
77
95
baseUrl : '/' + orgName
@@ -90,8 +108,8 @@ async function getMockThrottlingPolicies() {
90
108
return mockThrottlingPoliciesMetaData . list ;
91
109
}
92
110
93
- async function getAPIMThrottlingPolicies ( ) {
94
- const responseData = await invokeApiRequest ( 'GET' , controlPlaneUrl + '/throttling-policies/application' , null , null ) ;
111
+ async function getAPIMThrottlingPolicies ( req ) {
112
+ const responseData = await invokeApiRequest ( req , 'GET' , controlPlaneUrl + '/throttling-policies/application' , null , null ) ;
95
113
return responseData . list ;
96
114
}
97
115
@@ -113,9 +131,9 @@ const loadApplication = async (req, res) => {
113
131
} else {
114
132
const orgName = req . params . orgName ;
115
133
const orgID = await orgIDValue ( orgName ) ;
116
- metaData = await getAPIMApplication ( applicationId ) ;
117
- const allApis = await getAllAPIs ( ) ;
118
- const subApis = await getSubscribedApis ( applicationId ) ;
134
+ metaData = await getAPIMApplication ( req , applicationId ) ;
135
+ const allApis = await getAllAPIs ( req ) ;
136
+ const subApis = await getSubscribedApis ( req , applicationId ) ;
119
137
const subApiMap = new Map ( ) ;
120
138
subApis . list . forEach ( subApi => subApiMap . set ( subApi . apiId , { policy : subApi . throttlingPolicy , id : subApi . subscriptionId } ) ) ;
121
139
const apiList = [ ] ;
@@ -142,7 +160,7 @@ const loadApplication = async (req, res) => {
142
160
143
161
} ) ;
144
162
145
- kMmetaData = await getAPIMKeyManagers ( ) ;
163
+ kMmetaData = await getAPIMKeyManagers ( req ) ;
146
164
templateContent = {
147
165
applicationMetadata : metaData ,
148
166
keyManagersMetadata : kMmetaData ,
@@ -162,28 +180,28 @@ const loadApplication = async (req, res) => {
162
180
}
163
181
164
182
165
- async function getAllAPIs ( ) {
183
+ async function getAllAPIs ( req ) {
166
184
try {
167
- return await util . invokeApiRequest ( 'GET' , `${ controlPlaneUrl } /apis` ) ;
185
+ return await util . invokeApiRequest ( req , 'GET' , `${ controlPlaneUrl } /apis` ) ;
168
186
} catch ( error ) {
169
187
console . error ( "Error occurred while loading APIs" , error ) ;
170
188
throw error ;
171
189
}
172
190
}
173
191
174
- const getSubscribedApis = async ( appId ) => {
192
+ const getSubscribedApis = async ( req , appId ) => {
175
193
try {
176
- return await util . invokeApiRequest ( 'GET' , `${ controlPlaneUrl } /subscriptions?applicationId=${ appId } ` ) ;
194
+ return await util . invokeApiRequest ( req , 'GET' , `${ controlPlaneUrl } /subscriptions?applicationId=${ appId } ` ) ;
177
195
} catch ( error ) {
178
196
console . error ( "Error occurred while loading subscriptions" , error ) ;
179
197
throw error ;
180
198
}
181
199
}
182
200
183
201
const loadApplicationForEdit = async ( req , res ) => {
184
- const orgName = req . params . orgName ;
202
+
185
203
const applicationId = req . params . applicationid ;
186
- let html , templateContent , metaData ;
204
+ let html , templateContent , metaData , throttlingMetaData ;
187
205
if ( config . mode === constants . DEV_MODE ) {
188
206
metaData = await getMockApplication ( ) ;
189
207
throttlingMetaData = await getMockThrottlingPolicies ( ) ;
@@ -196,8 +214,8 @@ const loadApplicationForEdit = async (req, res) => {
196
214
} else {
197
215
const orgName = req . params . orgName ;
198
216
const orgID = await orgIDValue ( orgName ) ;
199
- metaData = await getAPIMApplication ( applicationId ) ;
200
- throttlingMetaData = await getAPIMThrottlingPolicies ( ) ;
217
+ metaData = await getAPIMApplication ( req , applicationId ) ;
218
+ throttlingMetaData = await getAPIMThrottlingPolicies ( req ) ;
201
219
templateContent = {
202
220
applicationMetadata : metaData ,
203
221
throttlingPoliciesMetadata : throttlingMetaData ,
@@ -223,13 +241,13 @@ async function getMockKeyManagers() {
223
241
return mockKeyManagersMetaData . list ;
224
242
}
225
243
226
- async function getAPIMApplication ( applicationId ) {
227
- const responseData = await invokeApiRequest ( 'GET' , controlPlaneUrl + '/applications/' + applicationId , null , null ) ;
244
+ async function getAPIMApplication ( req , applicationId ) {
245
+ const responseData = await invokeApiRequest ( req , 'GET' , controlPlaneUrl + '/applications/' + applicationId , null , null ) ;
228
246
return responseData ;
229
247
}
230
248
231
- async function getAPIMKeyManagers ( ) {
232
- const responseData = await invokeApiRequest ( 'GET' , controlPlaneUrl + '/key-managers' , null , null ) ;
249
+ async function getAPIMKeyManagers ( req ) {
250
+ const responseData = await invokeApiRequest ( req , 'GET' , controlPlaneUrl + '/key-managers' , null , null ) ;
233
251
return responseData . list ;
234
252
}
235
253
0 commit comments