Skip to content

Commit c0d7c04

Browse files
committed
fix: initialize m2m immediately instead of on request
Do it the same way we are doing in the Project Service, as we know that such a way works good for us.
1 parent 7d98cca commit c0d7c04

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/common/helper.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const AWS = require('aws-sdk')
66
const config = require('config')
77
const elasticsearch = require('elasticsearch')
88
const _ = require('lodash')
9-
const tcCoreLibAuth = require('tc-core-library-js')
9+
const tcCoreLib = require('tc-core-library-js')
1010
const urlencode = require('urlencode')
1111

1212
const logger = require('./logger')
@@ -15,18 +15,14 @@ AWS.config.region = config.get('esConfig.AWS_REGION')
1515
// ES Client mapping
1616
const esClients = {}
1717

18-
const m2mAuth = tcCoreLibAuth.auth.m2m
19-
const util = tcCoreLibAuth.util(config)
20-
let m2m = null
18+
const m2m = tcCoreLib.auth.m2m(config)
19+
const tcCoreLibUtil = tcCoreLib.util(config)
2120

2221
/**
2322
* Get machine to machine token.
2423
* @returns {Promise} promise which resolves to the m2m token
2524
*/
2625
async function getM2MToken () {
27-
if (_.isNull(m2m)) {
28-
m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL']))
29-
}
3026
return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
3127
}
3228

@@ -153,7 +149,7 @@ async function updateMetadadaESPromise (updateDocHandler) {
153149
async function getMemberDetailsByUserIds (userIds) {
154150
try {
155151
const token = await getM2MToken()
156-
const httpClient = util.getHttpClient({ id: `projectMemberService_${userIds.join('_')}`, log: logger })
152+
const httpClient = tcCoreLibUtil.getHttpClient({ id: `projectMemberService_${userIds.join('_')}`, log: logger })
157153
return httpClient.get(`${config.MEMBER_SERVICE_ENDPOINT}/_search`, {
158154
params: {
159155
query: `${_.map(userIds, id => `userId:${id}`).join(urlencode(' OR ', 'utf8'))}`,

0 commit comments

Comments
 (0)