UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

140 lines 7.12 kB
// SPDX-License-Identifier: Apache-2.0 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var VfkitDependencyManager_1; import * as constants from '../constants.js'; import * as version from '../../../version.js'; import { inject, injectable } from 'tsyringe-neo'; import { patchInject } from '../dependency-injection/container-helper.js'; import { InjectTokens } from '../dependency-injection/inject-tokens.js'; import { BaseDependencyManager } from './base-dependency-manager.js'; import { PackageDownloader } from '../package-downloader.js'; import util from 'node:util'; import { SoloError } from '../errors/solo-error.js'; import { OperatingSystem } from '../../business/utils/operating-system.js'; const VFKIT_RELEASES_LIST_URL = 'https://api.github.com/repos/crc-org/vfkit/releases'; let VfkitDependencyManager = VfkitDependencyManager_1 = class VfkitDependencyManager extends BaseDependencyManager { checksum; releaseBaseUrl; artifactFileName; artifactVersion; constructor(downloader, installationDirectory, osArch, vfkitVersion) { super(patchInject(downloader, InjectTokens.PackageDownloader, VfkitDependencyManager_1.name), patchInject(installationDirectory, InjectTokens.PodmanDependenciesInstallationDirectory, VfkitDependencyManager_1.name), patchInject(osArch, InjectTokens.OsArch, VfkitDependencyManager_1.name), patchInject(vfkitVersion, InjectTokens.VfkitVersion, VfkitDependencyManager_1.name) || version.VFKIT_VERSION, constants.VFKIT, ''); } getVerifyChecksum() { return false; } /** * Get the Vfkit artifact name based on version, OS, and architecture */ getArtifactName() { return util.format(this.artifactFileName, this.getRequiredVersion(), OperatingSystem.getFormattedPlatform(), this.osArch); } async getVersion(executableWithPath) { // The retry logic is to handle potential transient issues with the command execution // The command `vfkit --version` was sometimes observed to return an empty output in the CI environment const maxAttempts = 3; for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { const output = await this.run(`${executableWithPath} --version`); if (output.length > 0) { const match = output[0].trim().match(/(\d+\.\d+\.\d+)/); return match[1]; } } catch (error) { throw new SoloError('Failed to check vfkit version', error); } } throw new SoloError('Failed to check vfkit version'); } /** * Fetches the latest release information from GitHub API * @returns Promise with the release base URL, asset name, digest, and version */ async fetchReleaseInfo(tagName) { try { // Make a GET request to GitHub API using fetch const response = await fetch(VFKIT_RELEASES_LIST_URL, { method: 'GET', // Changed from HEAD to GET to retrieve the body headers: { 'User-Agent': constants.SOLO_USER_AGENT_HEADER, Accept: 'application/vnd.github.v3+json', // Explicitly request GitHub API v3 format }, }); if (!response.ok) { throw new SoloError(`GitHub API request failed with status ${response.status}`); } // Parse the JSON response const releases = await response.json(); if (!releases || releases.length === 0) { throw new SoloError('No releases found'); } // Get the latest release const release = releases.find(release => release.tag_name === tagName); const version = release.tag_name.replace(/^v/, ''); // Remove 'v' prefix if present // Normalize platform/arch for asset matching const arch = this.getArch(); const assetName = 'vfkit'; const matchingAsset = release.assets.find(asset => asset.name.includes(assetName)); if (!matchingAsset) { throw new SoloError(`No matching asset found for ${OperatingSystem.getFormattedPlatform()}-${arch}`); } const checksum = matchingAsset.digest || '0000000000000000000000000000000000000000000000000000000000000000'; // Construct the release base URL (removing the filename from the download URL) const downloadUrl = matchingAsset.browser_download_url.slice(0, Math.max(0, matchingAsset.browser_download_url.lastIndexOf('/'))); return { downloadUrl, assetName: matchingAsset.name, checksum, version, }; } catch (error) { if (error instanceof SoloError) { throw error; } throw new SoloError('Failed to parse GitHub API response', error); } } async preInstall() { const releaseInfo = await this.fetchReleaseInfo(version.VFKIT_VERSION); this.checksum = releaseInfo.checksum; this.releaseBaseUrl = releaseInfo.downloadUrl; this.artifactFileName = releaseInfo.assetName; this.artifactVersion = releaseInfo.version; } getDownloadURL() { return `${this.releaseBaseUrl}/${this.artifactFileName}`; } /** * Handle any post-download processing before copying to destination * Child classes can override this for custom extraction or processing */ async processDownloadedPackage(packageFilePath, _temporaryDirectory) { return [packageFilePath]; } getChecksumURL() { return this.checksum; } }; VfkitDependencyManager = VfkitDependencyManager_1 = __decorate([ injectable(), __param(0, inject(InjectTokens.PackageDownloader)), __param(1, inject(InjectTokens.PodmanDependenciesInstallationDirectory)), __param(2, inject(InjectTokens.OsArch)), __param(3, inject(InjectTokens.VfkitVersion)), __metadata("design:paramtypes", [PackageDownloader, String, String, String]) ], VfkitDependencyManager); export { VfkitDependencyManager }; //# sourceMappingURL=vfkit-dependency-manager.js.map