diff --git a/README.md b/README.md index 8b6f889..0d705b2 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ jobs: - uses: AzBuilder/terrakube-action-github@1.0.0 with: TERRAKUBE_TOKEN: "xxxxxx" # Terrakube Personal Access Token - TERRAKUBE_TEMPLATE: "vulnerability-snyk" + TERRAKUBE_TEMPLATE: "Terraform-Plan" TERRAKUBE_REPOSITORY: "https://github.com/AzBuilder/terraform-sample-repository.git" TERRAKUBE_ENDPOINT: "https://terrakube.interal/service" - TERRAKUBE_BRANCH: ${{ github.event.pull_request.base.ref }} + TERRAKUBE_BRANCH: ${{ github.head_ref }} GITHUB_TOKEN: "xxxx" ``` diff --git a/action.yml b/action.yml index 3daf05a..a8e5368 100644 --- a/action.yml +++ b/action.yml @@ -27,4 +27,4 @@ outputs: description: 'Terrakube Job Execution Id' runs: using: 'node16' - main: 'dist/index.js' \ No newline at end of file + main: 'src/index.ts' \ No newline at end of file diff --git a/dist/authentication.js b/dist/authentication.js deleted file mode 100644 index 7bf09cc..0000000 --- a/dist/authentication.js +++ /dev/null @@ -1,63 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getAuthenticationToken = void 0; -const core = __importStar(require("@actions/core")); -const httpm = __importStar(require("@actions/http-client")); -const qs = __importStar(require("query-string")); -function getAuthenticationToken(loginEndpoint, terrakubeTenantId, terrakubeApplicationId, terrakubeApplicationSecret, terrakubeScope) { - return __awaiter(this, void 0, void 0, function* () { - const httpClient = new httpm.HttpClient(); - core.info('Generating Azure Ad Body'); - core.info(`grant_type=client_credentials&client_id=${terrakubeApplicationId}&client_secret=${terrakubeApplicationSecret.substring(0, 3)}XXXXXXXX&scope=${encodeURIComponent(terrakubeScope)}`); - const postData = qs.stringify({ - 'grant_type': 'client_credentials', - 'client_id': terrakubeApplicationId, - 'scope': terrakubeScope, - 'client_secret': terrakubeApplicationSecret - }); - const res = yield httpClient.post(`${loginEndpoint}/${terrakubeTenantId}/oauth2/v2.0/token`, postData, { 'content-type': 'application/x-www-form-urlencoded' }); - core.debug('Azure Ad Response received'); - const body = yield res.readBody(); - const azureAdToken = JSON.parse(body); - if (typeof azureAdToken.error === "undefined") { - core.debug(`Returning new Token ${azureAdToken.access_token.substring(0, 25)}XXXXXX`); - return azureAdToken.access_token; - } - else { - core.debug(azureAdToken.error); - } - }); -} -exports.getAuthenticationToken = getAuthenticationToken; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 258733b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,244 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __asyncValues = (this && this.__asyncValues) || function (o) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var m = o[Symbol.asyncIterator], i; - return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); - function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } - function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(require("@actions/core")); -const glob = __importStar(require("@actions/glob")); -const exec = __importStar(require("@actions/exec")); -const httpm = __importStar(require("@actions/http-client")); -const github = __importStar(require("@actions/github")); -const ansi_to_html_1 = __importDefault(require("ansi-to-html")); -const userInput_1 = require("./userInput"); -const terrakube_1 = require("./terrakube"); -const promises_1 = require("fs/promises"); -function run() { - var e_1, _a; - return __awaiter(this, void 0, void 0, function* () { - try { - const githubActionInput = yield (0, userInput_1.getActionInput)(); - const terrakubeClient = new terrakube_1.TerrakubeClient(githubActionInput); - const patterns = ['**/terrakube.json']; - const globber = yield glob.create(patterns.join('\n')); - const currentDirectory = yield getCurrentDirectory(); - console.debug(`Processing: ${currentDirectory}`); - try { - for (var _b = __asyncValues(globber.globGenerator()), _c; _c = yield _b.next(), !_c.done;) { - const file = _c.value; - const terrakubeData = JSON.parse(yield (0, promises_1.readFile)(`${file}`, "utf8")); - core.startGroup(`Execute Workspace ${terrakubeData.workspace}`); - console.debug(`Processing: ${file}`); - //terrakubeData.respository = await getRepository() - //terrakubeData.folder = file.replace(currentDirectory,'') - core.debug(`Loaded JSON: ${JSON.stringify(terrakubeData)}`); - core.info(`Organization: ${terrakubeData.organization}`); - core.info(`Workspace: ${terrakubeData.workspace}`); - core.info(`Folder: ${terrakubeData.folder}`); - core.info(`Action branch: ${process.env.GITHUB_REF}`); - core.info(`Branch: ${githubActionInput.branch}`); - terrakubeData.branch = githubActionInput.branch; - //Object.keys(terrakubeData.variables).forEach(key => { - // console.log('Key : ' + key + ', Value : ' + terrakubeData.variables[key]) - //}) - core.info(`Running Workspace ${terrakubeData.workspace} with Template ${githubActionInput.terrakubeTemplate}`); - core.info(`Checking if workspace ${terrakubeData.workspace}`); - const organizationId = yield terrakubeClient.getOrganizationId(terrakubeData.organization); - if (organizationId !== "") { - //let updateJob = false - let workspaceId = yield terrakubeClient.getWorkspaceId(organizationId, terrakubeData.workspace); - if (workspaceId === "") { - core.info(`Creating new workspace ${terrakubeData.workspace}`); - workspaceId = yield terrakubeClient.createWorkspace(organizationId, terrakubeData.workspace, terrakubeData.terraform, terrakubeData.folder, terrakubeData.workspaceSrc, terrakubeData.branch); - //updateJob = true - } - core.info(`Searching template ${githubActionInput.terrakubeTemplate}`); - const templateId = yield terrakubeClient.getTemplateId(organizationId, githubActionInput.terrakubeTemplate); - if (templateId !== "") { - core.info(`Using template id ${templateId}`); - /* - for await (const key of Object.keys(terrakubeData.variables)) { - const updateVar = await setupVariable( - terrakubeClient, - organizationId, - workspaceId, - key, - terrakubeData.variables[key] - ) - - if (updateVar && !updateJob) { - updateJob = true; - } - }*/ - //core.info(`Update Job: ${updateJob}`) - //if (updateJob) { - core.info(`Creating new job: `); - const jobId = yield terrakubeClient.createJobId(organizationId, workspaceId, templateId); - core.debug(`JobId: ${jobId}`); - yield checkTerrakubeLogs(terrakubeClient, githubActionInput.githubToken, organizationId, jobId); - //core.setOutput(`Organization: ${terrakubeData.organization} Workspace: ${terrakubeData.workspace} Job`, jobId); - //} - } - else { - core.error(`Template not found: ${githubActionInput.terrakubeTemplate} in Organization: ${terrakubeData.organization}`); - } - } - else { - core.error(`Organization not found: ${terrakubeData.organization} in Endpoint: ${githubActionInput.terrakubeEndpoint}`); - } - core.endGroup(); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b); - } - finally { if (e_1) throw e_1.error; } - } - } - catch (error) { - if (error instanceof Error) - core.setFailed(error.message); - } - }); -} -function sleep(ms) { - return __awaiter(this, void 0, void 0, function* () { - return new Promise(resolve => setTimeout(resolve, ms)); - }); -} -function checkTerrakubeLogs(terrakubeClient, githubToken, organizationId, jobId) { - return __awaiter(this, void 0, void 0, function* () { - let jobRunning = true; - let jobResponse = yield terrakubeClient.getJobData(organizationId, jobId); - let jobResponseJson = JSON.parse(jobResponse); - while (jobResponseJson.data.attributes.status !== "completed" && jobResponseJson.data.attributes.status !== "failed") { - yield sleep(5000); - jobResponse = yield terrakubeClient.getJobData(organizationId, jobId); - jobResponseJson = JSON.parse(jobResponse); - core.debug("Waiting for job information..."); - } - core.info(`${jobResponse}`); - core.info(`${JSON.stringify(jobResponseJson.included)}`); - const httpClient = new httpm.HttpClient(); - const jobSteps = jobResponseJson.included; - core.info(`${Object.keys(jobSteps).length}`); - let finalComment = ""; - const convert = new ansi_to_html_1.default(); - for (let index = 0; index < Object.keys(jobSteps).length; index++) { - core.startGroup(`Running ${jobSteps[index].attributes.name}`); - const response = yield httpClient.get(`${jobSteps[index].attributes.output}`); - const body = yield response.readBody(); - core.info(body); - core.endGroup(); - const convert = new ansi_to_html_1.default(); - const commentBody = `Running ${jobSteps[index].attributes.name} \n${convert.toHtml(body)}\n `; - finalComment = finalComment.concat(commentBody); - } - core.info("Setup client"); - const octokit = github.getOctokit(githubToken); - core.info("Getting payload"); - const pull_request = github.context.payload; - core.info("Send message"); - yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, github.context.repo), { issue_number: pull_request.number, body: `${finalComment}` })); - if (jobResponseJson.data.attributes.status === "completed") { - return true; - } - else { - return false; - } - }); -} -function setupVariable(terrakubeClient, organizationId, workspaceId, key, value) { - return __awaiter(this, void 0, void 0, function* () { - const variableId = yield terrakubeClient.getVariableId(organizationId, workspaceId, key); - if (variableId === "") { - yield terrakubeClient.createVariable(organizationId, workspaceId, key, value); - return true; - } - else { - const variableData = yield terrakubeClient.getVariableById(organizationId, workspaceId, variableId); - if (variableData.data.attributes.value === value) { - return false; - } - else { - yield terrakubeClient.updateVariableById(organizationId, workspaceId, variableId, value); - return true; - } - } - }); -} -function getRepository() { - return __awaiter(this, void 0, void 0, function* () { - let repository = ''; - let errorGitCommand = ''; - let options = {}; - options.listeners = { - stdout: (data) => { - repository += data.toString(); - }, - stderr: (data) => { - errorGitCommand += data.toString(); - } - }; - yield exec.exec('git', ['config', '--get', 'remote.origin.url'], options); - return repository; - }); -} -function getCurrentDirectory() { - return __awaiter(this, void 0, void 0, function* () { - let repository = ''; - let errorGitCommand = ''; - let options = {}; - options.listeners = { - stdout: (data) => { - repository += data.toString(); - }, - stderr: (data) => { - errorGitCommand += data.toString(); - } - }; - yield exec.exec('pwd', [], options); - return repository; - }); -} -run(); diff --git a/dist/terrakube.js b/dist/terrakube.js deleted file mode 100644 index 550df23..0000000 --- a/dist/terrakube.js +++ /dev/null @@ -1,297 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TerrakubeClient = void 0; -const core = __importStar(require("@actions/core")); -const httpm = __importStar(require("@actions/http-client")); -class TerrakubeClient { - constructor(gitHubActionInput) { - this.httpClient = new httpm.HttpClient(); - this.gitHubActionInput = gitHubActionInput; - this.authenticationToken = 'empty'; - core.info(`Creating Terrakube CLient....`); - core.info(`Endpoint: ${gitHubActionInput.terrakubeEndpoint}`); - core.info(`Repository: ${gitHubActionInput.terrakubeRepository}`); - core.info(`Template: ${gitHubActionInput.terrakubeTemplate}`); - } - getOrganizationId(organizationName) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization?filter[organization]=name==${organizationName}`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization?filter[organization]=name==${organizationName}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response size: ${terrakubeResponse.data.length}`); - if (terrakubeResponse.data.length === 0) { - return ""; - } - else { - core.debug(`Organization Id: ${terrakubeResponse.data[0].id}`); - return terrakubeResponse.data[0].id; - } - }); - } - getWorkspaceId(organizationId, workspaceName) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace?filter[workspace]=name==${workspaceName}"`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace?filter[workspace]=name==${workspaceName}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response size: ${terrakubeResponse.data.length}`); - if (terrakubeResponse.data.length === 0) { - return ""; - } - else { - core.info(`Workspace Id: ${terrakubeResponse.data[0].id}`); - return terrakubeResponse.data[0].id; - } - }); - } - createWorkspace(organizationId, name, terraformVersion, folder, repository, branch) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`POST ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace`); - const response = yield this.httpClient.post(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace`, `{ - "data": { - "type": "workspace", - "attributes": { - "name": "${name}", - "source": "${repository}", - "branch": "${branch}", - "folder": "${folder}", - "terraformVersion": "${terraformVersion}" - } - } - }`, { - 'Authorization': `Bearer ${this.authenticationToken}`, - 'Content-Type': 'application/vnd.api+json' - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response: ${JSON.stringify(terrakubeResponse)}`); - core.info(`Variable Id: ${terrakubeResponse.data.id}`); - return terrakubeResponse.data.id; - }); - } - getTemplateId(organizationId, templateName) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/template?filter[template]=name==${templateName}`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/template?filter[template]=name==${templateName}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response size: ${terrakubeResponse.data.length}`); - if (terrakubeResponse.data.length === 0) { - return ""; - } - else { - core.info(`Template Id: ${terrakubeResponse.data[0].id}`); - return terrakubeResponse.data[0].id; - } - }); - } - getVariableId(organizationId, workspaceId, variableName) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable?filter[variable]=key==${variableName}`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable?filter[variable]=key==${variableName}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response size: ${terrakubeResponse.data.length === 0}`); - if (terrakubeResponse.data.length === 0) { - return ""; - } - else { - core.info(`Variable Id: ${terrakubeResponse.data[0].id}`); - return terrakubeResponse.data[0].id; - } - }); - } - getVariableById(organizationId, workspaceId, variableId) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable/${variableId}`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable/${variableId}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response: ${terrakubeResponse}`); - return terrakubeResponse; - }); - } - updateVariableById(organizationId, workspaceId, variableId, variableValue) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`PATCH ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable/${variableId}`); - const response = yield this.httpClient.patch(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable/${variableId}`, `{ - "data": { - "type": "variable", - "id": "${variableId}", - "attributes": { - "value": "${variableValue}" - } - } - }`, { - 'Authorization': `Bearer ${this.authenticationToken}`, - 'Content-Type': 'application/vnd.api+json' - }); - const body = yield response.readBody(); - core.debug(`Updated Variable: ${variableId}`); - return true; - }); - } - createVariable(organizationId, workspaceId, variableName, varaibleValue) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`POST ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable`); - const response = yield this.httpClient.post(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable`, `{ - "data": { - "type": "variable", - "attributes": { - "key": "${variableName}", - "value": "${varaibleValue}", - "sensitive": false, - "hcl": false, - "category": "TERRAFORM", - "description": "" - } - } - }`, { - 'Authorization': `Bearer ${this.authenticationToken}`, - 'Content-Type': 'application/vnd.api+json' - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response: ${JSON.stringify(terrakubeResponse)}`); - core.info(`Variable Id: ${terrakubeResponse.data.id}`); - return terrakubeResponse.data.id; - }); - } - getVariableValue(organizationId, workspaceId, variableName) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable?filter[variable]=key==${variableName}`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/workspace/${workspaceId}/variable?filter[variable]=key==${variableName}`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(`Response size: ${terrakubeResponse.data.length}`); - if (terrakubeResponse.data.length === 0) { - return ""; - } - else { - core.info(`Variable Id: ${terrakubeResponse.data[0].id}`); - return terrakubeResponse.data[0].attributes.value; - } - }); - } - createJobId(organizationId, workspaceId, templateId) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - const requestBody = { - "data": { - "type": "job", - "attributes": { - "templateReference": templateId - }, - "relationships": { - "workspace": { - "data": { - "type": "workspace", - "id": workspaceId - } - } - } - } - }; - core.debug(`POST ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/job`); - core.debug(`${JSON.stringify(requestBody)}`); - const response = yield this.httpClient.post(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/job`, JSON.stringify(requestBody), { - 'Authorization': `Bearer ${this.authenticationToken}`, - 'Content-Type': 'application/vnd.api+json' - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(JSON.stringify(terrakubeResponse)); - return terrakubeResponse.data.id; - }); - } - getJobData(organizationId, jobId) { - return __awaiter(this, void 0, void 0, function* () { - if (this.authenticationToken === 'empty') { - this.authenticationToken = this.gitHubActionInput.token; - } - core.debug(`GET ${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/job/${jobId}?include=step`); - const response = yield this.httpClient.get(`${this.gitHubActionInput.terrakubeEndpoint}/api/v1/organization/${organizationId}/job/${jobId}?include=step`, { - 'Authorization': `Bearer ${this.authenticationToken}` - }); - const body = yield response.readBody(); - const terrakubeResponse = JSON.parse(body); - core.debug(JSON.stringify(terrakubeResponse)); - return body; - }); - } -} -exports.TerrakubeClient = TerrakubeClient; diff --git a/dist/userInput.js b/dist/userInput.js deleted file mode 100644 index 2b04e21..0000000 --- a/dist/userInput.js +++ /dev/null @@ -1,61 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getActionInput = void 0; -const core = __importStar(require("@actions/core")); -function getActionInput() { - return __awaiter(this, void 0, void 0, function* () { - const terrakubeToken = core.getInput('terrakube_token', { required: true }); - core.debug(`Terrakube Token: ${terrakubeToken.substring(0, 10)}****`); - const terrakubeEndpoint = core.getInput('terrakube_endpoint', { required: true }); - core.debug(`Terrakube Endpoint: ${terrakubeEndpoint}`); - const terrakubeRepository = core.getInput('terrakube_repository', { required: true }); - core.debug(`Terrakube Repository: ${terrakubeRepository}`); - const terrakubeTemplate = core.getInput('terrakube_template', { required: true }); - core.debug(`Terrakube Template: ${terrakubeTemplate}`); - const terrakubeBranch = core.getInput('terrakube_branch', { required: true }); - core.debug(`Terrakube Branch: ${terrakubeTemplate}`); - const githubToken = core.getInput('token', { required: true }); - const terrakubeActionInput = { - token: terrakubeToken, - terrakubeEndpoint: terrakubeEndpoint, - terrakubeRepository: terrakubeRepository, - terrakubeTemplate: terrakubeTemplate, - githubToken: githubToken, - branch: terrakubeBranch - }; - return terrakubeActionInput; - }); -} -exports.getActionInput = getActionInput; diff --git a/dist/wait.js b/dist/wait.js deleted file mode 100644 index 7079c93..0000000 --- a/dist/wait.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.wait = void 0; -function wait(milliseconds) { - return __awaiter(this, void 0, void 0, function* () { - return new Promise(resolve => { - if (isNaN(milliseconds)) { - throw new Error('milliseconds not a number'); - } - setTimeout(() => resolve('done!'), milliseconds); - }); - }); -} -exports.wait = wait;