Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TES-5093] Use apikey of job, config organizationId instead of teamId #150

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ program
.option('-s, --server-url <value>', 'Katalon Analytics URL')
.option('-u, --username <value>', 'Email')
.option('-p, --apikey <value>', 'API key')
.option('-t, --teamid <value>', 'Team ID')
.option('-t, --organizationid <value>', 'Organization ID')
.option('-a, --agent-name <value>', 'Agent name')
.option('-c, --config <value>', 'Configuration file path')
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
Expand All @@ -40,7 +40,7 @@ program
serverUrl: command.serverUrl,
email: command.username,
apikey: command.apikey,
teamId: command.teamid,
organizationId: command.organizationid,
agentName: command.agentName,
configPath: command.config,
proxy: command.proxy,
Expand All @@ -58,7 +58,7 @@ program
.option('-s, --server-url <value>', 'Katalon Analytics URL')
.option('-u, --username <value>', 'Email')
.option('-p, --apikey <value>', 'API key')
.option('-t, --teamid <value>', 'Team ID')
.option('-t, --organizationid <value>', 'Organization ID')
.option('-a, --agent-name <value>', 'Agent name')
.option('-c, --config <value>', 'Configuration file path')
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
Expand All @@ -68,7 +68,7 @@ program
serverUrl: command.serverUrl,
email: command.username,
apikey: command.apikey,
teamId: command.teamid,
teamId: command.organizationid,
agentName: command.agentName,
configPath: command.config,
proxy: command.proxy,
Expand Down
42 changes: 26 additions & 16 deletions src/core/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const http = require('./http');
const httpInternal = require('./http-testops');
const urlParam = require('./url-param');
const { getBasicAuthHeader } = require('./utils');
const { getAuth } = require('../auth');

function withAuthorization(apiKey) {
return {
Authorization: getBasicAuthHeader(getAuth(apiKey)),
};
}

module.exports = {
requestToken(email, password) {
Expand All @@ -29,8 +36,8 @@ module.exports = {
return httpInternal.post(urlParam.accessToken(), data);
},

getUploadInfo(projectId) {
return httpInternal.get(urlParam.getUploadInfo(projectId));
getUploadInfo(projectId, apiKey) {
return httpInternal.get(urlParam.getUploadInfo(projectId), withAuthorization(apiKey));
},

uploadFile(uploadUrl, filePath) {
Expand All @@ -45,6 +52,7 @@ module.exports = {
uploadedPath,
isEnd,
reportType,
apiKey,
extraParams = {},
) {
return httpInternal.post(
Expand All @@ -58,43 +66,45 @@ module.exports = {
reportType,
extraParams,
),
null,
this.withAuthorization(apiKey),
);
},

pingAgent(body) {
return httpInternal.post(urlParam.pingAgent(), body);
},

pingJob(jobId) {
return httpInternal.patch(urlParam.pingJob(jobId));
pingJob(jobId, apiKey) {
return httpInternal.patch(urlParam.pingJob(jobId), null, withAuthorization(apiKey));
},

requestJob(uuid, teamId) {
return httpInternal.get(urlParam.requestJob(uuid, teamId));
requestJob(uuid, organizationId) {
return httpInternal.get(urlParam.requestJob(uuid, organizationId));
},

updateJob(body) {
return httpInternal.post(urlParam.updateJob(), body);
updateJob(body, apiKey) {
return httpInternal.post(urlParam.updateJob(), body, withAuthorization(apiKey));
},

saveJobLog(jobInfo, batch, fileName) {
return httpInternal.post(urlParam.saveJobLog(jobInfo, batch, fileName));
saveJobLog(jobInfo, batch, fileName, apiKey) {
return httpInternal.post(urlParam.saveJobLog(jobInfo, batch, fileName), null, withAuthorization(apiKey));
},

notifyJob(jobId, projectId) {
return httpInternal.post(urlParam.notifyJob(jobId, projectId));
notifyJob(jobId, projectId, apiKey) {
return httpInternal.post(urlParam.notifyJob(jobId, projectId), null, withAuthorization(apiKey));
},

getBuildInfo() {
return httpInternal.get(urlParam.getBuildInfo());
},

updateNodeStatus(jobId, nodeStatus) {
updateNodeStatus(jobId, nodeStatus, apiKey) {
const data = {
id: jobId,
nodeStatus,
};
return httpInternal.put(urlParam.updateNodeStatus(), data);
return httpInternal.put(urlParam.updateNodeStatus(), data, withAuthorization(apiKey));
},

getKSReleases() {
Expand All @@ -105,7 +115,7 @@ module.exports = {
return http.stream(urlParam.download(url), filePath);
},

downloadFromTestOps(url, filePath) {
return httpInternal.stream(urlParam.download(url), filePath);
downloadFromTestOps(url, filePath, apiKey) {
return httpInternal.stream(urlParam.download(url), filePath, withAuthorization(apiKey));
},
};
2 changes: 1 addition & 1 deletion src/core/api/http-testops.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getBasicAuthHeader } = require('./utils');

function withAuthorization(current = {}) {
return {
Authorization: getBasicAuthHeader(getAuth()),
Authorization: current?.Authorization || getBasicAuthHeader(getAuth()),
...current,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/api/url-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ module.exports = {
return buildUrl({}, PATHS.JOB, jobId);
},

requestJob(uuid, teamId) {
requestJob(uuid, organizationId) {
const params = {
uuid,
teamId,
organizationId,
};
return buildUrl({ params }, PATHS.JOB, 'get-job');
},
Expand Down
4 changes: 2 additions & 2 deletions src/core/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const config = require('./config');

function getAuth() {
function getAuth(apikey) {
return {
username: '',
password: config.apikey,
password: apikey || config.apikey,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fs = require('fs-extra');
const api = require('./api');
const defaultLogger = require('../config/logger');

function download(downloadMethod, url, logger = defaultLogger) {
function download(downloadMethod, url, logger = defaultLogger, apiKey) {
logger.info(`Downloading from ${url}. It may take a few minutes.`);
const file = tmp.fileSync();
const filePath = file.name;
Expand All @@ -19,7 +19,7 @@ function download(downloadMethod, url, logger = defaultLogger) {
}
return Promise.reject(new Error(`Unable to download from ${url} to ${filePath}`));
};
return downloadMethod(url, filePath)
return downloadMethod(url, filePath, apiKey)
.then(verifyDownloadedFile);
}

Expand Down Expand Up @@ -57,8 +57,8 @@ module.exports = {
);
},

downloadFromTestOps(url, targetPath, logger = defaultLogger) {
return download(api.downloadFromTestOps, url, logger).then((filePath) =>
downloadFromTestOps(url, targetPath, apiKey, logger = defaultLogger) {
return download(api.downloadFromTestOps, url, logger, apiKey).then((filePath) =>
this.move(filePath, targetPath, logger),
);
},
Expand Down
3 changes: 1 addition & 2 deletions src/helper/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function buildUpdateJobBody(jobId, jobStatus, processId) {

function createCommandExecutor(
projectId,
teamId,
ksArgs,
x11Display,
xvfbConfiguration,
Expand All @@ -42,7 +41,7 @@ function createCommandExecutor(
}

const info = {
teamId,
teamId: parameter.teamId,
projectId,
ksVersionNumber: parameter.ksVersion,
ksLocation: parameter.ksLocation,
Expand Down
Loading
Loading