forked from sanyam803/SCC-Left-Shift-Security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (60 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const core = require('@actions/core');
const exec = require('@actions/exec');
const { Octokit } = require("@octokit/core");
const { Storage } = require('@google-cloud/storage');
const fetch = require('node-fetch');
/**
* Self Invoking function that runs core logic of the plugin.
*/
async function invokePlugin() {
try {
const gcs_credentials = core.getInput('gcs_credentials');
const owner = core.getInput('owner');
const repoName = core.getInput('repoName');
const fs = require('fs');
const path = require('path');
fs.writeFileSync('gcs-credentials.json', gcs_credentials);
fetchPlanFile(owner, repoName, path);
writeToGitHubRepo();
} catch (error) {
core.setFailed(error.message);
}
}
/**
* Fetch Terraform Plan File.
* @param {string} owner : repo owner.
* @param {string} repoName : name of repo.
* @return {!Object} sbom : SBOM of the repo generated using GitHub API.
*/
async function fetchPlanFile(owner, repoName, path) {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
request: {
fetch: fetch,
}
});
await exec.exec('terraform init');
const response = await octokit.rest.repos.getContent({
owner,
repoName,
path,
});
if(response == null) {
throw "Failed to Fetch SBOM";
}
console.log(response);
console.log(response.data);
return response.data;
}
/**
* Install OSV Scanner.
*/
async function writeToGitHubRepo() {
// Install go on the VM
await exec.exec('rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz');
await exec.exec('export PATH=$PATH:/usr/local/go/bin');
await exec.exec('go version');
// Install OSV Scanner on the VM
await exec.exec('sudo yum install -y yum-utils');
}
invokePlugin();