Skip to content

Commit

Permalink
Merge pull request #154 from katalon-studio/master
Browse files Browse the repository at this point in the history
Release 20/12
  • Loading branch information
quidl authored Dec 5, 2023
2 parents 4343af7 + 17d863e commit 03e9241
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 91 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ ENV DISPLAY_CONFIGURATION='1024x768x24'
# Agent Environment
ENV AGENT_NAME='Katalon Agent'
ENV SERVER_URL='https://testops.katalon.io'
ENV KATALON_USERNAME=''
ENV KATALON_API_KEY=''
ENV TEAM_ID=''
ENV ORGANIZATION_ID=''
ENV PROXY=''
ENV LOG_LEVEL='INFO'
ENV XVFB_RUN=''
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ agentName=My Agent
email=<email>
apikey=<api_key>
serverUrl=https://analytics.katalon.com/
teamId=<team_id>
organizationId=<organization_id>
```

- Supported options:
Expand All @@ -30,7 +30,7 @@ teamId=<team_id>
| email | The email of the Katalon account used to log into the Katalon TestOps. |
| apikey | The API Key used to log into the Katalon TestOps. The API key can be generated and retrieved from [here](https://analytics.katalon.com/user/apikey). For more info read the [docs](https://docs.katalon.com/katalon-analytics/docs/ka-api-key.html#katalon-api-keys-usage). |
| serverUrl | The Katalon TestOps' URL. |
| teamId | The ID of the Katalon TestOps team to integrate the Katalon Agent into. The agent is shared among members and projects within a team. |
| organizationId | The ID of the Katalon TestOps organization to integrate the Katalon Agent into. The agent is shared among members and projects within an organization that the agent linked to. |
| uuid | The ID used to identify the agent. It is generated by the Katalon Agent on the first run and should not be specified manually or modified for any reason. |

| Optional Option | Description |
Expand Down Expand Up @@ -67,7 +67,7 @@ Note: On Linux and MacOS, you might need to add execute permission (`chmode u+x

## Generate the configuration file
- The `agentconfig` file can be generated or updated by running `config` command with additional arguments.
- E.g. `node cli.js config --server-url https://analytics.katalon.com --username <email> --apikey <api_key> --teamid <team_id> --agent-name my-agent`
- E.g. `node cli.js config --server-url https://analytics.katalon.com --username <email> --apikey <api_key> --organizationid <organization_id> --agent-name my-agent`
- If an `agentconfig` has been created, the existing configuration will be overridden with the new value.
- Show the usage of the `config` command with `-h` option. E.g. `node cli.js config -h`.

Expand Down
2 changes: 1 addition & 1 deletion agentconfig_template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ agentName=
email=
apikey=
serverUrl=
teamId=
organizationId=
keepFiles=false
logLevel=INFO
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,
organizationId: command.organizationid,
agentName: command.agentName,
configPath: command.config,
proxy: command.proxy,
Expand Down
3 changes: 1 addition & 2 deletions docker/scripts/agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ cd $KATALON_AGENT_DIR

./cli-linux-x64 config \
--server-url "$SERVER_URL" \
--username "$KATALON_USERNAME" \
--apikey "$KATALON_API_KEY" \
--teamid "$TEAM_ID" \
--organizationid "$ORGANIZATION_ID" \
--agent-name "$AGENT_NAME" \
--proxy "$PROXY" \
--log-level "$LOG_LEVEL" \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "katalon-agent",
"version": "v1.7.8",
"version": "v2.0.0",
"description": "",
"main": "cli.js",
"scripts": {
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 && current.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

0 comments on commit 03e9241

Please sign in to comment.