diff --git a/package.json b/package.json index 67382e5..e355302 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "topcoder-dev-api-projects": "^1.0.1", "topcoder-healthcheck-dropin": "^1.0.3", "util": "^0.11.0", + "validator": "^13.0.0", "winston": "^2.4.3" }, "devDependencies": { diff --git a/services/AzureService.js b/services/AzureService.js index df8c406..878c894 100644 --- a/services/AzureService.js +++ b/services/AzureService.js @@ -4,7 +4,7 @@ 'use strict'; /** - * This provides methods around gitlab api. + * This provides methods around azure api. * @author TCSCODER * @version 1.0 */ @@ -12,7 +12,6 @@ const config = require('config'); const _ = require('lodash'); const Joi = require('joi'); -const GitlabAPI = require('node-gitlab-api'); const superagent = require('superagent'); const superagentPromise = require('superagent-promise'); const logger = require('../utils/logger'); @@ -31,43 +30,7 @@ const copilotUserSchema = Joi.object().keys({ }).required(); /** - * authenticate the gitlab using access token - * @param {String} accessToken the access token of copilot - * @returns {Object} the gitlab instance - * @private - */ -async function _authenticate(accessToken) { - try { - const gitlab = GitlabAPI({ - url: config.GITLAB_API_BASE_URL, - oauthToken: accessToken - }); - return gitlab; - } catch (err) { - throw errors.convertGitLabError(err, 'Failed to during authenticate to Github using access token of copilot.'); - } -} - -/** - * Removes assignees from issue - * @param {Object} gitlab the gitlab instance - * @param {Number} projectId the project id - * @param {Number} issueId the issue number - * @param {Array} assignees the users to remove - * @private - */ -async function _removeAssignees(gitlab, projectId, issueId, assignees) { - try { - const issue = await gitlab.projects.issues.show(projectId, issueId); - const oldAssignees = _.difference(issue.assignee_ids, assignees); - await gitlab.projects.issues.edit(projectId, issueId, {assignee_ids: oldAssignees}); - } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during remove assignees from issue.'); - } -} - -/** - * creates the comments on gitlab issue + * creates the comments on azure issue * @param {Object} copilot the copilot * @param {String} repoFullName the organization/project-name * @param {Number} workItemId the issue number @@ -86,7 +49,7 @@ async function createComment(copilot, repoFullName, workItemId, body) { .set('Content-Type', 'application/json') .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during creating comment on issue.'); + throw errors.convertAzureError(err, 'Error occurred during creating comment on issue.'); } logger.debug(`Azure comment is added on issue with message: "${body}"`); } @@ -99,26 +62,34 @@ createComment.schema = { }; /** - * updates the title of gitlab issue + * updates the title of azure issue * @param {Object} copilot the copilot - * @param {Number} projectId the project id + * @param {Number} repoFullName the project id * @param {Number} issueId the issue number * @param {string} title new title */ -async function updateIssue(copilot, projectId, issueId, title) { - Joi.attempt({copilot, projectId, issueId, title}, updateIssue.schema); - const gitlab = await _authenticate(copilot.accessToken); +async function updateIssue(copilot, repoFullName, issueId, title) { + Joi.attempt({copilot, repoFullName, issueId, title}, updateIssue.schema); try { - await gitlab.projects.issues.edit(projectId, issueId, {title}); + await request + .patch(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}?api-version=5.1`) + .send([{ + op: 'add', + path: '/fields/System.Title', + value: title + }]) + .set('Authorization', `Bearer ${copilot.accessToken}`) + .set('Content-Type', 'application/json-patch+json') + .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during updating issue.'); + throw errors.convertAzureError(err, 'Error occurred during updating issue.'); } logger.debug(`Azure issue title is updated for issue number ${issueId}`); } updateIssue.schema = { copilot: copilotUserSchema, - projectId: Joi.number().positive().required(), + repoFullName: Joi.string().required(), issueId: Joi.number().positive().required(), title: Joi.string().required() }; @@ -126,45 +97,60 @@ updateIssue.schema = { /** * Assigns the issue to user login * @param {Object} copilot the copilot - * @param {Number} projectId the project id + * @param {Number} repoFullName the project id * @param {Number} issueId the issue number - * @param {Number} userId the user id of assignee + * @param {Number} user the user id of assignee */ -async function assignUser(copilot, projectId, issueId, userId) { - Joi.attempt({copilot, projectId, issueId, userId}, assignUser.schema); - const gitlab = await _authenticate(copilot.accessToken); +async function assignUser(copilot, repoFullName, issueId, user) { + Joi.attempt({copilot, repoFullName, issueId, user}, assignUser.schema); try { - const issue = await gitlab.projects.issues.show(projectId, issueId); - const oldAssignees = _.without(issue.assignee_ids, userId); - if (oldAssignees && oldAssignees.length > 0) { - await _removeAssignees(gitlab, projectId, issueId, oldAssignees); - } - await gitlab.projects.issues.edit(projectId, issueId, {assignee_ids: [userId]}); + await request + .patch(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}?api-version=5.1`) + .send([{ + op: 'add', + path: '/fields/System.AssignedTo', + value: user + }]) + .set('Authorization', `Bearer ${copilot.accessToken}`) + .set('Content-Type', 'application/json-patch+json') + .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during assigning issue user.'); + throw errors.convertAzureError(err, 'Error occurred during update assignee.'); } logger.debug(`Azure issue with number ${issueId} is assigned to ${issueId}`); } assignUser.schema = { copilot: copilotUserSchema, - projectId: Joi.number().positive().required(), + repoFullName: Joi.string().required(), issueId: Joi.number().positive().required(), - userId: Joi.number().required() + user: Joi.string() }; /** * Removes an assignee from the issue * @param {Object} copilot the copilot - * @param {Number} projectId the project id + * @param {Number} repoFullName the project id * @param {Number} issueId the issue number * @param {Number} userId the user id of assignee to remove */ -async function removeAssign(copilot, projectId, issueId, userId) { - Joi.attempt({copilot, projectId, issueId, userId}, removeAssign.schema); - const gitlab = await _authenticate(copilot.accessToken); - await _removeAssignees(gitlab, projectId, issueId, [userId]); - logger.debug(`Azure user ${userId} is unassigned from issue number ${issueId}`); +async function removeAssign(copilot, repoFullName, issueId) { + Joi.attempt({copilot, repoFullName, issueId}, removeAssign.schema); + try { + await request + .patch(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}?api-version=5.1`) + .send([{ + op: 'add', + path: '/fields/System.AssignedTo', + value: '' + }]) + .set('Authorization', `Bearer ${copilot.accessToken}`) + .set('Content-Type', 'application/json-patch+json') + .end(); + } catch (err) { + throw errors.convertAzureError(err, 'Error occurred during remove assignee.'); + } + logger.debug(`Azure user is unassigned from issue number ${issueId}`); } removeAssign.schema = assignUser.schema; @@ -191,25 +177,7 @@ getUsernameById.schema = { }; /** - * Gets the user id by username - * @param {Object} copilot the copilot - * @param {string} login the username - * @returns {Number} the user id if found else null - */ -async function getUserIdByLogin(copilot, login) { - Joi.attempt({copilot, login}, getUserIdByLogin.schema); - const gitlab = await _authenticate(copilot.accessToken); - const user = await gitlab.users.all({username: login}); - return user.length ? user[0].id : null; -} - -getUserIdByLogin.schema = { - copilot: copilotUserSchema, - login: Joi.string().required() -}; - -/** - * updates the gitlab issue as paid and fix accepted + * updates the azure issue as paid and fix accepted * @param {Object} copilot the copilot * @param {Number} repoFullName the project id * @param {Number} issueId the issue number @@ -241,7 +209,7 @@ async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, exis .set('Content-Type', 'application/json') .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during updating issue as paid.'); + throw errors.convertAzureError(err, 'Error occurred during updating issue as paid.'); } logger.debug(`Azure issue is updated for as paid and fix accepted for ${issueId}`); } @@ -254,36 +222,44 @@ markIssueAsPaid.schema = { }; /** - * change the state of gitlab issue + * change the state of azure issue * @param {Object} copilot the copilot - * @param {string} projectId the project id + * @param {string} repoFullName the project id * @param {Number} issueId the issue issue id * @param {string} state new state */ -async function changeState(copilot, projectId, issueId, state) { - Joi.attempt({copilot, projectId, issueId, state}, changeState.schema); - const gitlab = await _authenticate(copilot.accessToken); +async function changeState(copilot, repoFullName, issueId, state) { + Joi.attempt({copilot, repoFullName, issueId, state}, changeState.schema); try { - await gitlab.projects.issues.edit(projectId, issueId, {state_event: state}); + await request + .patch(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}?api-version=5.1`) + .send([{ + op: 'add', + path: '/fields/System.State', + value: state + }]) + .set('Authorization', `Bearer ${copilot.accessToken}`) + .set('Content-Type', 'application/json-patch+json') + .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during updating status of issue.'); + throw errors.convertAzureError(err, 'Error occurred during updating status of issue.'); } logger.debug(`Azure issue state is updated to '${state}' for issue number ${issueId}`); } changeState.schema = { copilot: copilotUserSchema, - projectId: Joi.number().positive().required(), + repoFullName: Joi.string().required(), issueId: Joi.number().positive().required(), state: Joi.string().required() }; /** - * updates the gitlab issue with new labels + * updates the azure issue with new labels * @param {Object} copilot the copilot * @param {string} repoFullName the project id * @param {Number} issueId the issue issue id - * @param {Number} labels the labels + * @param {Array} labels the labels */ async function addLabels(copilot, repoFullName, issueId, labels) { Joi.attempt({copilot, repoFullName, issueId, labels}, addLabels.schema); @@ -300,7 +276,7 @@ async function addLabels(copilot, repoFullName, issueId, labels) { .set('Content-Type', 'application/json-patch+json') .end(); } catch (err) { - throw errors.convertGitLabError(err, 'Error occurred during adding label in issue.'); + throw errors.convertAzureError(err, 'Error occurred during adding label in issue.'); } logger.debug(`Azure issue is updated with new labels for ${issueId}`); } @@ -357,7 +333,6 @@ module.exports = { assignUser, removeAssign, getUsernameById, - getUserIdByLogin, markIssueAsPaid, changeState, addLabels, diff --git a/services/EventService.js b/services/EventService.js index b02ca04..e681139 100644 --- a/services/EventService.js +++ b/services/EventService.js @@ -13,6 +13,7 @@ const _ = require('lodash'); const logger = require('../utils/logger'); const models = require('../models'); const dbHelper = require('../utils/db-helper'); +const azureService = require('./AzureService'); const gitHubService = require('./GithubService'); const gitlabService = require('./GitlabService'); @@ -26,8 +27,10 @@ const timeoutMapper = {}; async function reOpenIssue(event, issue) { if (event.provider === 'github') { await gitHubService.changeState(event.copilot, event.data.repository.full_name, issue.number, 'open'); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.changeState(event.copilot, event.data.repository.id, issue.number, 'reopen'); + } else if (event.provider === 'azure') { + await gitlabService.changeState(event.copilot, event.data.repository.full_name, issue.number, 'To Do'); } } @@ -91,8 +94,10 @@ async function handleEventGracefully(event, data, err) { // notify error in git host if (event.provider === 'github') { await gitHubService.createComment(event.copilot, event.data.repository.full_name, data.number, comment); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.createComment(event.copilot, event.data.repository.id, data.number, comment); + } else if (event.provider === 'azure') { + await azureService.createComment(event.copilot, event.data.repository.full_name, data.number, comment); } if (event.event === 'issue.closed') { @@ -102,8 +107,10 @@ async function handleEventGracefully(event, data, err) { const readyForReviewLabels = [config.READY_FOR_REVIEW_ISSUE_LABEL]; if (event.provider === 'github') { await gitHubService.addLabels(event.copilot, event.data.repository.full_name, data.number, readyForReviewLabels); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.addLabels(event.copilot, event.data.repository.id, data.number, readyForReviewLabels); + } else if (event.provider === 'azure') { + await azureService.addLabels(event.copilot, event.data.repository.full_name, data.number, readyForReviewLabels); } } } diff --git a/services/IssueService.js b/services/IssueService.js index 7b810dd..e293887 100755 --- a/services/IssueService.js +++ b/services/IssueService.js @@ -683,7 +683,8 @@ async function handleIssueUnAssignment(event, issue) { } if (dbIssue.assignee) { - const assigneeUserId = await gitHelper.getUserIdByLogin(event, dbIssue.assignee); + const assigneeUserId = event.provider === 'azure' ? dbIssue.assignee : + await gitHelper.getUserIdByLogin(event, dbIssue.assignee); if (!assigneeUserId) { // The assignement of this user was failed and broken. // We don't need to handle the unassignment. @@ -691,6 +692,7 @@ async function handleIssueUnAssignment(event, issue) { } logger.debug(`Looking up TC handle of git user: ${assigneeUserId}`); const userMapping = await userService.getTCUserName(event.provider, assigneeUserId); + logger.debug(userMapping); // We still have assignee(s) left on the ticket. if (event.data.issue.assignees && event.data.issue.assignees.length > 0) { @@ -905,7 +907,7 @@ process.schema = Joi.object().keys({ id: Joi.number().required(), body: Joi.string().allow(''), user: Joi.object().keys({ - id: Joi.number().required() + id: Joi.alternatives().try(Joi.string(), Joi.number()).required() }) }), assignee: Joi.object().keys({ diff --git a/services/UserService.js b/services/UserService.js index f659c66..b6bf357 100755 --- a/services/UserService.js +++ b/services/UserService.js @@ -11,6 +11,7 @@ const config = require('config'); const Joi = require('joi'); +const v = require('validator'); const _ = require('lodash'); const logger = require('../utils/logger'); const dbHelper = require('../utils/db-helper'); @@ -26,7 +27,7 @@ const azureService = require('./AzureService'); async function getTCUserName(provider, gitUser) { Joi.attempt({provider, gitUser}, getTCUserName.schema); const criteria = {}; - if (_.isNumber(gitUser)) { + if (_.isNumber(gitUser) || v.isUUID(gitUser)) { if (provider === 'github') { criteria.githubUserId = gitUser; } else if (provider === 'gitlab') { @@ -34,14 +35,13 @@ async function getTCUserName(provider, gitUser) { } else if (provider === 'azure') { criteria.azureUserId = gitUser; } - } - if (_.isString(gitUser)) { + } else if (_.isString(gitUser) || v.isEmail(gitUser)) { if (provider === 'github') { criteria.githubUsername = gitUser; } else if (provider === 'gitlab') { criteria.gitlabUsername = gitUser; } else if (provider === 'azure') { - criteria.azureUserId = gitUser; + criteria.azureEmail = gitUser; } } if (_.isEmpty(criteria)) { diff --git a/utils/errors.js b/utils/errors.js index a27193e..9064c7c 100644 --- a/utils/errors.js +++ b/utils/errors.js @@ -66,6 +66,26 @@ errors.convertGitLabError = function convertGitLabError(err, message) { return apiError; }; +/** + * Convert azure api error. + * @param {Error} err the azure api error + * @param {String} message the error message + * @returns {Error} converted error + */ +errors.convertAzureError = function convertAzureError(err, message) { + let resMsg = `${message}. ${err.message}.`; + const detail = _.get(err, 'response.body.message'); + if (detail) { + resMsg += ` Detail: ${detail}`; + } + const apiError = new ProcessorError( + err.status || _.get(err, 'response.status', constants.SERVICE_ERROR_STATUS), + resMsg, + 'azure' + ); + return apiError; +}; + /** * Convert topcoder api error. * @param {Error} err the topcoder api error diff --git a/utils/git-helper.js b/utils/git-helper.js index 1b572f0..686dae2 100644 --- a/utils/git-helper.js +++ b/utils/git-helper.js @@ -57,8 +57,10 @@ class GitHelper { async reOpenIssue(event, issue) { if (event.provider === 'github') { await gitHubService.changeState(event.copilot, event.data.repository.full_name, issue.number, 'open'); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.changeState(event.copilot, event.data.repository.id, issue.number, 'reopen'); + } else if (event.provider === 'azure') { + await azureService.changeState(event.copilot, event.data.repository.full_name, issue.number, 'To Do'); } } @@ -89,8 +91,10 @@ class GitHelper { async removeAssign(event, issueNumber, assigneeUserId, assigneeUsername) { if (event.provider === 'github') { await gitHubService.removeAssign(event.copilot, event.data.repository.full_name, issueNumber, assigneeUsername); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.removeAssign(event.copilot, event.data.repository.id, issueNumber, assigneeUserId); + } else if (event.provider === 'azure') { + await azureService.removeAssign(event.copilot, event.data.repository.full_name, issueNumber); } } @@ -103,8 +107,10 @@ class GitHelper { async updateIssue(event, issueNumber, newTitle) { if (event.provider === 'github') { await gitHubService.updateIssue(event.copilot, event.data.repository.full_name, issueNumber, newTitle); - } else { + } else if (event.provider === 'gitlab') { await gitlabService.updateIssue(event.copilot, event.data.repository.id, issueNumber, newTitle); + } else if (event.provider === 'azure') { + await azureService.updateIssue(event.copilot, event.data.repository.full_name, issueNumber, newTitle); } } @@ -117,9 +123,11 @@ class GitHelper { async assignUser(event, issueNumber, assignedUser) { if (event.provider === 'github') { await gitHubService.assignUser(event.copilot, event.data.repository.full_name, issueNumber, assignedUser); - } else { + } else if (event.provider === 'gitlab') { const userId = await gitlabService.getUserIdByLogin(event.copilot, assignedUser); await gitlabService.assignUser(event.copilot, event.data.repository.id, issueNumber, userId); + } else if (event.provider === 'azure') { + await azureService.assignUser(event.copilot, event.data.repository.full_name, issueNumber, assignedUser); } } @@ -165,7 +173,7 @@ class GitHelper { async getUserIdByLogin(event, assignee) { if (event.provider === 'github') { return await gitHubService.getUserIdByLogin(event.copilot, assignee); - } else if (event.provider === 'github') { + } else if (event.provider === 'gitlab') { return gitlabService.getUserIdByLogin(event.copilot, assignee); } else if (event.provider === 'azure') { return azureService.getUserIdByLogin(event.copilot, assignee); diff --git a/utils/topcoder-api-helper.js b/utils/topcoder-api-helper.js index 34eaa96..8c86227 100644 --- a/utils/topcoder-api-helper.js +++ b/utils/topcoder-api-helper.js @@ -115,7 +115,7 @@ async function getM2Mtoken() { * @returns {Number} the created project id */ async function createProject(projectName) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); // eslint-disable-next-line new-cap const projectBody = new topcoderApiProjects.ProjectRequestBody.constructFromObject({ projectName @@ -147,7 +147,7 @@ async function createProject(projectName) { * @returns {Number} the created challenge id */ async function createChallenge(challenge) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); const start = new Date(); const startTime = moment(start).toISOString(); const end = moment(start).add(config.NEW_CHALLENGE_DURATION_IN_DAYS, 'days').toISOString(); @@ -188,7 +188,7 @@ async function createChallenge(challenge) { * @param {Object} challenge the challenge to update */ async function updateChallenge(id, challenge) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`Updating challenge ${id} with ${circularJSON.stringify(challenge)}`); // eslint-disable-next-line new-cap const challengeBody = new topcoderApiChallenges.UpdateChallengeBodyParam.constructFromObject({ @@ -226,7 +226,7 @@ async function updateChallenge(id, challenge) { * @param {Number} id the challenge id */ async function activateChallenge(id) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`Activating challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -266,7 +266,7 @@ async function getChallengeById(id) { if (!_.isNumber(id)) { throw new Error('The challenge id must valid number'); } - const apiKey = await getM2Mtoken(); + const apiKey = await getAccessToken(); logger.debug('Getting topcoder challenge details'); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}`, { @@ -297,10 +297,10 @@ async function getChallengeById(id) { * @param {Number} winnerId the winner id */ async function closeChallenge(id, winnerId) { - const apiKey = await getM2Mtoken(); + const apiKey = await getAccessToken(); logger.debug(`Closing challenge ${id}`); try { - let basePath = challengesClient.basePath; + const basePath = challengesClient.basePath; const response = await axios.post(`${basePath}/challenges/${id}/close?winnerId=${winnerId}`, null, { headers: { authorization: `Bearer ${apiKey}`, @@ -328,7 +328,7 @@ async function closeChallenge(id, winnerId) { * @returns {Number} the billing account id */ async function getProjectBillingAccountId(id) { - const apiKey = await getM2Mtoken(); + const apiKey = await getAccessToken(); logger.debug(`Getting project billing detail ${id}`); try { const response = await axios.get(`${projectsClient.basePath}/direct/projects/${id}`, { @@ -360,7 +360,7 @@ async function getProjectBillingAccountId(id) { * @returns {Number} the user id */ async function getTopcoderMemberId(handle) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); try { const response = await axios.get(`${projectsClient.basePath}/members/${handle}`); const statusCode = response ? response.status : null; @@ -379,7 +379,7 @@ async function getTopcoderMemberId(handle) { * @param {Object} resource the resource resource to add */ async function addResourceToChallenge(id, resource) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`adding resource to challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -420,7 +420,7 @@ async function getResourcesFromChallenge(id) { if (!_.isNumber(id)) { throw new Error('The challenge id must valid number'); } - const apiKey = await getM2Mtoken(); + const apiKey = await getAccessToken(); logger.debug(`fetch resource from challenge ${id}`); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}/resources`, { @@ -465,7 +465,7 @@ async function roleAlreadySet(id, role) { * @param {Object} resource the resource resource to remove */ async function unregisterUserFromChallenge(id) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`removing resource from challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -502,7 +502,7 @@ async function unregisterUserFromChallenge(id) { * @param {Number} id the challenge id */ async function cancelPrivateContent(id) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`Cancelling challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -550,7 +550,7 @@ async function assignUserAsRegistrant(topcoderUserId, challengeId) { * @param {Object} resource the resource resource to remove */ async function removeResourceToChallenge(id, resource) { - bearer.apiKey = await getM2Mtoken(); + bearer.apiKey = await getAccessToken(); logger.debug(`removing resource from challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -580,7 +580,7 @@ async function removeResourceToChallenge(id, resource) { * @returns {Array} the resources of challenge */ async function getChallengeResources(id) { - const apiKey = await getM2Mtoken(); + const apiKey = await getAccessToken(); logger.debug(`getting resource from challenge ${id}`); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}/resources`, {