Skip to content

Commit 1dc55ec

Browse files
Merge pull request #1 from tanaysingh3484/Tanay-242-CodeEngineSampleFix
Fix ibm-messaging#242
2 parents 2ae5693 + 6d87ed8 commit 1dc55ec

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

serverless/codeengine/clientapp/mqclient/mqclient.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
**/
1616

17+
18+
const fs = require('fs');
1719
// Import the MQ package
1820
const mq = require('ibmmq');
1921

@@ -35,6 +37,8 @@ const _HOBJKEY = Symbol('hObj');
3537

3638
const BROWSEWAITINTERVAL = 10 * 1000; // 10 seconds
3739

40+
const CCDT = "MQCCDTURL";
41+
const FILEPREFIX = "file://";
3842

3943
// Load the MQ Endpoint details either from the envrionment or from the
4044
// env.json file. The envrionment takes precedence.
@@ -232,6 +236,18 @@ class MQClient {
232236
return connectionPromise;
233237
}
234238

239+
ccdtCheck() {
240+
if (CCDT in process.env) {
241+
let ccdtFile = process.env[CCDT].replace(FILEPREFIX, '');
242+
debug_info(ccdtFile);
243+
if (fs.existsSync(ccdtFile)) {
244+
debug_info("CCDT File found at ", ccdtFile);
245+
return true;
246+
}
247+
}
248+
return false;
249+
}
250+
235251

236252
buildCNO() {
237253
return new Promise((resolve, reject) => {
@@ -264,16 +280,40 @@ class MQClient {
264280
// The location of the KeyRepository is not specified in the CCDT, so regardless
265281
// of whether a CCDT is being used, need to specify the KeyRepository location
266282
// if it has been provided in the environment json settings.
283+
var sco = null;
267284
if (MQDetails.KEY_REPOSITORY) {
268285
debug_info('Key Repository has been specified');
269286
// *** For TLS ***
270-
var sco = new mq.MQSCO();
287+
sco = new mq.MQSCO();
271288

272289
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
273290
// And make the CNO refer to the SSL Connection Options
274291
cno.SSLConfig = sco;
275292
}
276293

294+
if (!this.ccdtCheck()) {
295+
debug_info('CCDT URL export is not set, will be using json environment client connections settings');
296+
let cd = new mq.MQCD();
297+
cd.ChannelName = MQDetails.CHANNEL;
298+
299+
cd.ConnectionName = this.getConnection();
300+
301+
debug_info('Connections string is ', cd.ConnectionName);
302+
303+
if (MQDetails.KEY_REPOSITORY) {
304+
debug_info("Will be running in TLS Mode");
305+
306+
cd.SSLCipherSpec = MQDetails.CIPHER;
307+
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
308+
309+
cno.SSLConfig = sco;
310+
}
311+
312+
cno.ClientConn = cd;
313+
} else {
314+
cno.ClientConn = cd;
315+
}
316+
277317
resolve(cno);
278318
});
279319
}

0 commit comments

Comments
 (0)