Skip to content

Commit

Permalink
fix: switch to github actions http-client
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkor committed Dec 17, 2024
1 parent c6d57cb commit a7aaf8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 44 deletions.
48 changes: 18 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"typed-rest-client": "^1.8.11"
"@actions/http-client": "^2.2.0"
},
"devDependencies": {
"@commitlint/cli": "^18.4.0",
Expand Down
25 changes: 12 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import * as core from '@actions/core';
import * as rm from 'typed-rest-client/RestClient';
import { HttpClient } from '@actions/http-client';

const apiToken = core.getInput('api_token');
const discoveryId = core.getInput('discovery_id');
const projectId = core.getInput('project_id');
const hostname = core.getInput('hostname');

const baseUrl = hostname ? `https://${hostname}` : 'https://app.brightsec.com';
const restc = new rm.RestClient('GitHub Actions', baseUrl);

const client = new HttpClient('GitHub Actions', [], {
allowRetries: true,
maxRetries: 5,
headers: { authorization: `Api-Key ${apiToken}` }
});

async function stopDiscovery(uuid: string) {
try {
const options = {
additionalHeaders: { Authorization: `Api-Key ${apiToken}` }
};
const payload = {
action: 'stop'
};
const restRes = await restc.update(
`api/v2/projects/${projectId}/discoveries/${uuid}/lifecycle`,
payload,
options
const response = await client.putJson(
`${baseUrl}/api/v2/projects/${projectId}/discoveries/${uuid}/lifecycle`,
{ action: 'stop' }
);
core.info(`Was succesfully stopped. Code ${restRes.statusCode}.`);

core.info(`Was successfully stopped. Code ${response.statusCode}.`);
} catch (err: any) {
core.setFailed(`Failed (${err.statusCode}) ${err.message}`);
}
Expand Down

0 comments on commit a7aaf8c

Please sign in to comment.