mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2026-11-30 03:44:21 +01:00
feat: added support for providing optional checksums for ZIP validation (#107)
Signed-off-by: Kim <kim.peter.wagner@gmail.com>
This commit is contained in:
1 parent
03a9076efe
commit
4bcfe8cded
6 files changed
+153
-7
No files matched your search
Vendored
+39
-3
@@ -34621,6 +34621,26 @@ async function getRelease (
|
||||
|
||||
|
||||
|
||||
;// CONCATENATED MODULE: external "stream/promises"
|
||||
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("stream/promises");
|
||||
;// CONCATENATED MODULE: ./lib/util.js
|
||||
/**
|
||||
* Copyright (c) OpenTofu
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function fileSHA256 (filePath) {
|
||||
const hash = (0,external_crypto_namespaceObject.createHash)('sha256');
|
||||
const fileStream = (0,external_fs_namespaceObject.createReadStream)(filePath);
|
||||
|
||||
await (0,promises_namespaceObject.pipeline)(fileStream, hash);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./lib/setup-tofu.js
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
@@ -34641,6 +34661,7 @@ async function getRelease (
|
||||
|
||||
|
||||
|
||||
|
||||
// __dirname is not available in ES modules, so we need to construct it ourselves
|
||||
const setup_tofu_dirname = (0,external_path_namespaceObject.dirname)((0,external_url_namespaceObject.fileURLToPath)(import.meta.url));
|
||||
|
||||
@@ -34663,7 +34684,7 @@ function mapOS (os) {
|
||||
return os;
|
||||
}
|
||||
|
||||
async function downloadAndExtractCLI (url) {
|
||||
async function downloadAndExtractCLI (url, checksums) {
|
||||
core_debug(`Downloading OpenTofu CLI from ${url}`);
|
||||
let pathToCLIZip;
|
||||
try {
|
||||
@@ -34673,6 +34694,20 @@ async function downloadAndExtractCLI (url) {
|
||||
throw new Error(`Failed to download OpenTofu from ${url}: ${cause}`);
|
||||
}
|
||||
|
||||
if (checksums.length > 0) {
|
||||
let checksum;
|
||||
try {
|
||||
checksum = await fileSHA256(pathToCLIZip);
|
||||
} catch (error) {
|
||||
const cause = getErrorMessage(error);
|
||||
throw new Error(`Failed to calculate the checksum for the OpenTofu CLI zip: ${cause}`);
|
||||
}
|
||||
|
||||
if (!checksums.includes(checksum)) {
|
||||
throw new Error(`Failed to validate OpenTofu CLI zip checksum. Received: ${checksum}. Valid checksums: ${checksums.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pathToCLIZip) {
|
||||
throw new Error(`Unable to download OpenTofu from ${url}`);
|
||||
}
|
||||
@@ -34777,6 +34812,7 @@ async function run () {
|
||||
const credentialsToken = getInput('cli_config_credentials_token');
|
||||
const wrapper = getInput('tofu_wrapper') === 'true';
|
||||
const useCache = getInput('cache') === 'true';
|
||||
const checksums = getMultilineInput('checksums');
|
||||
let githubToken = getInput('github_token');
|
||||
if (
|
||||
githubToken === '' &&
|
||||
@@ -34832,12 +34868,12 @@ async function run () {
|
||||
pathToCLI = cachedPath;
|
||||
} else {
|
||||
core_debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
|
||||
const extractedPath = await downloadAndExtractCLI(build.url);
|
||||
const extractedPath = await downloadAndExtractCLI(build.url, checksums);
|
||||
core_debug(`Caching OpenTofu version ${release.version} to tool cache`);
|
||||
pathToCLI = await cacheDir(extractedPath, 'tofu', release.version, buildArch);
|
||||
}
|
||||
} else {
|
||||
pathToCLI = await downloadAndExtractCLI(build.url);
|
||||
pathToCLI = await downloadAndExtractCLI(build.url, checksums);
|
||||
}
|
||||
|
||||
// Install our wrapper
|
||||
|
||||
Reference in new issue
Block a user