Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Remove azure. #336

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const USER_ROLES = {
// The user types
const USER_TYPES = {
GITHUB: 'github',
GITLAB: 'gitlab',
AZURE: 'azure'
GITLAB: 'gitlab'
};

// The default page size for Gitlab API
Expand All @@ -50,15 +49,8 @@ const GITLAB_ACCESS_TOKEN_DEFAULT_EXPIRATION = 3600 * 24 * 14;
// The Gitlab refresh token time in seconds before expiration
const GITLAB_REFRESH_TOKEN_BEFORE_EXPIRATION = 300;

// The Azure access token default expiration in seconds
const AZURE_ACCESS_TOKEN_DEFAULT_EXPIRATION = 3600 * 24 * 14;

// The Azure refresh token time in seconds before expiration
const AZURE_REFRESH_TOKEN_BEFORE_EXPIRATION = 300;

const GITHUB_OWNER_CALLBACK_URL = '/api/v1/github/owneruser/callback';
const GITLAB_OWNER_CALLBACK_URL = '/api/v1/gitlab/owneruser/callback';
const AZURE_OWNER_CALLBACK_URL = '/api/v1/azure/owneruser/callback';

const OWNER_USER_LOGIN_SUCCESS_URL = '/#!/app/settings';
const USER_ADDED_TO_TEAM_SUCCESS_URL = '/#!/members';
Expand All @@ -78,11 +70,8 @@ module.exports = {
GITLAB_DEFAULT_GROUP_ACCESS_LEVEL,
GITLAB_ACCESS_TOKEN_DEFAULT_EXPIRATION,
GITLAB_REFRESH_TOKEN_BEFORE_EXPIRATION,
AZURE_ACCESS_TOKEN_DEFAULT_EXPIRATION,
AZURE_REFRESH_TOKEN_BEFORE_EXPIRATION,
GITHUB_OWNER_CALLBACK_URL,
GITLAB_OWNER_CALLBACK_URL,
AZURE_OWNER_CALLBACK_URL,
OWNER_USER_LOGIN_SUCCESS_URL,
USER_ADDED_TO_TEAM_SUCCESS_URL,
TC_LOGIN_CALLBACK_URL,
Expand Down
33 changes: 3 additions & 30 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,6 @@ 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
*/
function convertAzureError(err, message) {
let resMsg = `${message}. ${err.message}.\n`;
const detail = _.get(err, 'response.body.message');
if (detail) {
resMsg += ` Detail: ${detail}`;
}
const apiError = new errors.ApiError(
err.status || _.get(err, 'response.status', constants.SERVICE_ERROR_STATUS),
_.get(err, 'response.body.message', constants.SERVICE_ERROR),
resMsg
);
return apiError;
}

/**
* Ensure entity exists for given criteria. Return error if no result.
* @param {Object} Model the mongoose model to query
Expand Down Expand Up @@ -216,7 +196,7 @@ async function ensureExists(Model, criteria, modelName) {
async function getProviderType(repoUrl) {
const parsedDomain = await parseDomain(repoUrl);
if (!parsedDomain || !parsedDomain.domain ||
(parsedDomain.domain !== 'github' && parsedDomain.domain !== 'gitlab' && parsedDomain.domain !== 'azure')) {
(parsedDomain.domain !== 'github' && parsedDomain.domain !== 'gitlab')) {
throw new ValidationError('Invalid git repo url');
}
return parsedDomain.domain;
Expand All @@ -237,21 +217,15 @@ async function getProjectCopilotOrOwner(models, project, provider, isCopilot) {

if (!userMapping ||
(provider === 'github' && !userMapping.githubUserId)
|| (provider === 'gitlab' && !userMapping.gitlabUserId)
|| (provider === 'azure' && !userMapping.azureUserId)) {
|| (provider === 'gitlab' && !userMapping.gitlabUserId)) {
throw new Error(`Couldn't find ${isCopilot ? 'copilot' : 'owner'} username for '${provider}' for this repository.`);
}

let user = await dbHelper.scanOne(models.User, {
username: provider === 'github' ? userMapping.githubUsername : // eslint-disable-line no-nested-ternary
provider === 'gitlab' ? userMapping.gitlabUsername : userMapping.azureEmail,
userMapping.gitlabUsername,
type: provider,
});

if (provider === 'azure') {
const azureService = require('../services/AzureService'); // eslint-disable-line global-require
user = azureService.refreshAzureUserAccessToken(user);
}

return user;
}
Expand Down Expand Up @@ -283,7 +257,6 @@ module.exports = {
buildController,
convertGitHubError,
convertGitLabError,
convertAzureError,
ensureExists,
generateIdentifier,
getProviderType,
Expand Down
31 changes: 6 additions & 25 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ module.exports = {
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
GITLAB_CLIENT_ID: process.env.GITLAB_CLIENT_ID,
GITLAB_CLIENT_SECRET: process.env.GITLAB_CLIENT_SECRET,
AZURE_APP_ID: process.env.AZURE_APP_ID,
AZURE_CLIENT_SECRET: process.env.AZURE_CLIENT_SECRET,
AZURE_USER_APP_ID: process.env.AZURE_APP_ID,
AZURE_USER_CLIENT_SECRET: process.env.AZURE_USER_CLIENT_SECRET,

// used as base to construct various URLs
WEBSITE: process.env.WEBSITE || 'http://topcoderx.topcoder-dev.com',
WEBSITE_SECURE: process.env.WEBSITE_SECURE || 'https://topcoderx.topcoder-dev.com',
GITLAB_API_BASE_URL: process.env.GITLAB_API_BASE_URL || 'https://gitlab.com',
AZURE_API_BASE_URL: process.env.AZURE_API_BASE_URL || 'https://app.vssps.visualstudio.com',
AZURE_DEVOPS_API_BASE_URL: process.env.AZURE_DEVOPS_API_BASE_URL || 'https://dev.azure.com',

// kafka configuration
TOPIC: process.env.TOPIC || 'tc-x-events',
Expand Down Expand Up @@ -90,12 +84,9 @@ const frontendConfigs = {
"DIRECT_URL_BASE": "https://www.topcoder-dev/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"OWNER_LOGIN_AZURE_URL":"/api/v1/azure/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/",
"AZURE_TEAM_URL": "https://dev.azure.com/"

"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"heroku":{
"JWT_V3_NAME":"v3jwt",
Expand All @@ -109,11 +100,9 @@ const frontendConfigs = {
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"OWNER_LOGIN_AZURE_URL":"/api/v1/azure/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/",
"AZURE_TEAM_URL": "https://dev.azure.com/"
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"dev":{
"JWT_V3_NAME":"v3jwt",
Expand All @@ -127,11 +116,9 @@ const frontendConfigs = {
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"OWNER_LOGIN_AZURE_URL":"/api/v1/azure/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/",
"AZURE_TEAM_URL": "https://dev.azure.com/"
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"qa":{
"JWT_V3_NAME":"v3jwt",
Expand All @@ -145,11 +132,9 @@ const frontendConfigs = {
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"OWNER_LOGIN_AZURE_URL":"/api/v1/azure/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/",
"AZURE_TEAM_URL": "https://dev.azure.com/"
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"prod":{
"JWT_V3_NAME":"v3jwt",
Expand All @@ -163,11 +148,9 @@ const frontendConfigs = {
"DIRECT_URL_BASE": "https://www.topcoder.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"OWNER_LOGIN_AZURE_URL":"/api/v1/azure/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/",
"AZURE_TEAM_URL": "https://dev.azure.com/"
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
}
};

Expand All @@ -187,9 +170,7 @@ module.exports.frontendConfigs = {
DIRECT_URL_BASE: process.env.DIRECT_URL_BASE || frontendConfigs[activeEnv].DIRECT_URL_BASE,
OWNER_LOGIN_GITHUB_URL: process.env.OWNER_LOGIN_GITHUB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITHUB_URL,
OWNER_LOGIN_GITLAB_URL: process.env.OWNER_LOGIN_GITLAB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITLAB_URL,
OWNER_LOGIN_AZURE_URL: process.env.OWNER_LOGIN_AZURE_URL || frontendConfigs[activeEnv].OWNER_LOGIN_AZURE_URL,
TOPCODER_URL: process.env.TOPCODER_URL || frontendConfigs[activeEnv].TOPCODER_URL,
GITHUB_TEAM_URL: process.env.GITHUB_TEAM_URL || frontendConfigs[activeEnv].GITHUB_TEAM_URL,
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || frontendConfigs[activeEnv].GITLAB_GROUP_URL,
AZURE_TEAM_URL: process.env.AZURE_TEAM_URL || frontendConfigs[activeEnv].AZURE_TEAM_URL
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || frontendConfigs[activeEnv].GITLAB_GROUP_URL
};
Loading