@@ -23,13 +23,13 @@ AWS.config.region = config.esConfig.AWS_REGION
23
23
24
24
const m2mAuth = require ( 'tc-core-library-js' ) . auth . m2m
25
25
26
- // const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL']))
27
26
const m2m = m2mAuth ( _ . pick ( config , [ 'AUTH0_URL' , 'AUTH0_AUDIENCE' , 'AUTH0_CLIENT_ID' , 'AUTH0_CLIENT_SECRET' , 'AUTH0_PROXY_SERVER_URL' ] ) )
28
27
29
- const topcoderM2M = m2mAuth ( {
30
- AUTH0_AUDIENCE : config . AUTH0_AUDIENCE_FOR_BUS_API ,
28
+ const m2mForUbahn = m2mAuth ( {
29
+ AUTH0_AUDIENCE : config . AUTH0_AUDIENCE_UBAHN ,
31
30
..._ . pick ( config , [ 'AUTH0_URL' , 'TOKEN_CACHE_TIME' , 'AUTH0_CLIENT_ID' , 'AUTH0_CLIENT_SECRET' , 'AUTH0_PROXY_SERVER_URL' ] )
32
- } )
31
+ }
32
+ )
33
33
34
34
let busApiClient
35
35
@@ -42,10 +42,8 @@ function getBusApiClient () {
42
42
if ( busApiClient ) {
43
43
return busApiClient
44
44
}
45
- busApiClient = busApi ( {
46
- AUTH0_AUDIENCE : config . AUTH0_AUDIENCE_FOR_BUS_API ,
47
- ..._ . pick ( config , [ 'AUTH0_URL' , 'TOKEN_CACHE_TIME' , 'AUTH0_CLIENT_ID' , 'AUTH0_CLIENT_SECRET' , 'BUSAPI_URL' , 'KAFKA_ERROR_TOPIC' , 'AUTH0_PROXY_SERVER_URL' ] )
48
- } )
45
+ busApiClient = busApi ( _ . pick ( config , [ 'AUTH0_URL' , 'AUTH0_AUDIENCE' , 'TOKEN_CACHE_TIME' , 'AUTH0_CLIENT_ID' , 'AUTH0_CLIENT_SECRET' , 'BUSAPI_URL' , 'KAFKA_ERROR_TOPIC' , 'AUTH0_PROXY_SERVER_URL' ] )
46
+ )
49
47
return busApiClient
50
48
}
51
49
@@ -210,16 +208,16 @@ function getESClient () {
210
208
* Function to get M2M token
211
209
* @returns {Promise }
212
210
*/
213
- const getM2Mtoken = async ( ) => {
211
+ const getM2MToken = async ( ) => {
214
212
return await m2m . getMachineToken ( config . AUTH0_CLIENT_ID , config . AUTH0_CLIENT_SECRET )
215
213
}
216
214
217
215
/*
218
- * Function to get M2M token to access topcoder resources(e.g. /v3/users)
216
+ * Function to get M2M token for U-Bahn
219
217
* @returns {Promise }
220
218
*/
221
- const getTopcoderM2MToken = async ( ) => {
222
- return await topcoderM2M . getMachineToken ( config . AUTH0_CLIENT_ID , config . AUTH0_CLIENT_SECRET )
219
+ const getM2MUbahnToken = async ( ) => {
220
+ return await m2mForUbahn . getMachineToken ( config . AUTH0_CLIENT_ID , config . AUTH0_CLIENT_SECRET )
223
221
}
224
222
225
223
/**
@@ -247,7 +245,7 @@ function encodeQueryString (queryObj, nesting = '') {
247
245
* @returns {String } user id.
248
246
*/
249
247
async function getUserIds ( userId ) {
250
- const token = await getM2Mtoken ( )
248
+ const token = await getM2MToken ( )
251
249
const q = {
252
250
enrich : true ,
253
251
externalProfile : {
@@ -320,7 +318,7 @@ function isDocumentMissingException (err) {
320
318
async function getProjects ( currentUser , criteria = { } ) {
321
319
let token
322
320
if ( currentUser . hasManagePermission || currentUser . isMachine ) {
323
- const m2mToken = await getM2Mtoken ( )
321
+ const m2mToken = await getM2MToken ( )
324
322
token = `Bearer ${ m2mToken } `
325
323
} else {
326
324
token = currentUser . jwtToken
@@ -351,7 +349,7 @@ async function getProjects (currentUser, criteria = {}) {
351
349
* @returns {Object } the user
352
350
*/
353
351
async function getTopcoderUserById ( userId ) {
354
- const token = await getTopcoderM2MToken ( )
352
+ const token = await getM2MToken ( )
355
353
const res = await request
356
354
. get ( config . TOPCODER_USERS_API )
357
355
. query ( { filter : `id=${ userId } ` } )
@@ -371,7 +369,7 @@ async function getTopcoderUserById (userId) {
371
369
* @returns the request result
372
370
*/
373
371
async function getUserById ( userId , enrich ) {
374
- const token = await getM2Mtoken ( )
372
+ const token = await getM2MToken ( )
375
373
const res = await request
376
374
. get ( `${ config . TC_API } /users/${ userId } ` + ( enrich ? '?enrich=true' : '' ) )
377
375
. set ( 'Authorization' , `Bearer ${ token } ` )
@@ -389,29 +387,29 @@ async function getUserById (userId, enrich) {
389
387
}
390
388
391
389
/**
392
- * Function to create user in ubhan
390
+ * Function to create user in ubahn
393
391
* @param {Object } data the user data
394
392
* @returns the request result
395
393
*/
396
- async function createUbhanUser ( { handle, firstName, lastName } ) {
397
- const token = await getM2Mtoken ( )
394
+ async function createUbahnUser ( { handle, firstName, lastName } ) {
395
+ const token = await getM2MUbahnToken ( )
398
396
const res = await request
399
397
. post ( `${ config . TC_API } /users` )
400
398
. set ( 'Authorization' , `Bearer ${ token } ` )
401
399
. set ( 'Content-Type' , 'application/json' )
402
400
. set ( 'Accept' , 'application/json' )
403
401
. send ( { handle, firstName, lastName } )
404
- localLogger . debug ( { context : 'createUbhanUser ' , message : `response body: ${ JSON . stringify ( res . body ) } ` } )
402
+ localLogger . debug ( { context : 'createUbahnUser ' , message : `response body: ${ JSON . stringify ( res . body ) } ` } )
405
403
return _ . pick ( res . body , [ 'id' ] )
406
404
}
407
405
408
406
/**
409
- * Function to create external profile for a ubhan user
407
+ * Function to create external profile for a ubahn user
410
408
* @param {String } userId the user id(with uuid format)
411
409
* @param {Object } data the profile data
412
410
*/
413
411
async function createUserExternalProfile ( userId , { organizationId, externalId } ) {
414
- const token = await getM2Mtoken ( )
412
+ const token = await getM2MUbahnToken ( )
415
413
const res = await request
416
414
. post ( `${ config . TC_API } /users/${ userId } /externalProfiles` )
417
415
. set ( 'Authorization' , `Bearer ${ token } ` )
@@ -427,7 +425,7 @@ async function createUserExternalProfile (userId, { organizationId, externalId }
427
425
* @returns the request result
428
426
*/
429
427
async function getMembers ( handles ) {
430
- const token = await getM2Mtoken ( )
428
+ const token = await getM2MToken ( )
431
429
const handlesStr = _ . map ( handles , handle => {
432
430
return '%22' + handle . toLowerCase ( ) + '%22'
433
431
} ) . join ( ',' )
@@ -451,7 +449,7 @@ async function getMembers (handles) {
451
449
async function getProjectById ( currentUser , id ) {
452
450
let token
453
451
if ( currentUser . hasManagePermission || currentUser . isMachine ) {
454
- const m2mToken = await getM2Mtoken ( )
452
+ const m2mToken = await getM2MToken ( )
455
453
token = `Bearer ${ m2mToken } `
456
454
} else {
457
455
token = currentUser . jwtToken
@@ -484,7 +482,7 @@ async function getProjectById (currentUser, id) {
484
482
* @returns the request result
485
483
*/
486
484
async function getTopcoderSkills ( criteria ) {
487
- const token = await getM2Mtoken ( )
485
+ const token = await getM2MToken ( )
488
486
try {
489
487
const res = await request
490
488
. get ( `${ config . TC_API } /skills` )
@@ -516,7 +514,7 @@ async function getTopcoderSkills (criteria) {
516
514
* @returns the request result
517
515
*/
518
516
async function getSkillById ( skillId ) {
519
- const token = await getM2Mtoken ( )
517
+ const token = await getM2MToken ( )
520
518
const res = await request
521
519
. get ( `${ config . TC_API } /skills/${ skillId } ` )
522
520
. set ( 'Authorization' , `Bearer ${ token } ` )
@@ -556,17 +554,17 @@ async function getUserSkill (token, userId) {
556
554
* Fetch the user info from /v3/users and create a new user in /v5/users.
557
555
*
558
556
* @params {Object} currentUser the user who perform this operation
559
- * @returns {String } the ubhan user id
557
+ * @returns {String } the ubahn user id
560
558
*/
561
- async function ensureUbhanUserId ( currentUser ) {
559
+ async function ensureUbahnUserId ( currentUser ) {
562
560
try {
563
561
return await getUserId ( currentUser . userId )
564
562
} catch ( err ) {
565
563
if ( ! ( err instanceof errors . NotFoundError ) ) {
566
564
throw err
567
565
}
568
566
const topcoderUser = await getTopcoderUserById ( currentUser . userId )
569
- const user = await createUbhanUser ( _ . pick ( topcoderUser , [ 'handle' , 'firstName' , 'lastName' ] ) )
567
+ const user = await createUbahnUser ( _ . pick ( topcoderUser , [ 'handle' , 'firstName' , 'lastName' ] ) )
570
568
await createUserExternalProfile ( user . id , { organizationId : config . ORG_ID , externalId : currentUser . userId } )
571
569
return user . id
572
570
}
@@ -589,7 +587,7 @@ async function ensureJobById (jobId) {
589
587
* @returns {Object } the user data
590
588
*/
591
589
async function ensureUserById ( userId ) {
592
- const token = await getM2Mtoken ( )
590
+ const token = await getM2MToken ( )
593
591
try {
594
592
const res = await request
595
593
. get ( `${ config . TC_API } /users/${ userId } ` )
@@ -625,7 +623,7 @@ function getAuditM2Muser () {
625
623
* @returns the result
626
624
*/
627
625
async function checkIsMemberOfProject ( userId , projectId ) {
628
- const m2mToken = await getM2Mtoken ( )
626
+ const m2mToken = await getM2MToken ( )
629
627
const res = await request
630
628
. get ( `${ config . TC_API } /projects/${ projectId } ` )
631
629
. set ( 'Authorization' , `Bearer ${ m2mToken } ` )
@@ -649,10 +647,10 @@ module.exports = {
649
647
if ( userId === config . m2m . M2M_AUDIT_USER_ID ) {
650
648
return config . m2m . M2M_AUDIT_USER_ID
651
649
}
652
- return ensureUbhanUserId ( { userId } )
650
+ return ensureUbahnUserId ( { userId } )
653
651
} ,
654
- getM2Mtoken ,
655
- getTopcoderM2MToken ,
652
+ getM2MToken ,
653
+ getM2MUbahnToken ,
656
654
postEvent,
657
655
getBusApiClient,
658
656
isDocumentMissingException,
0 commit comments