From 027c2575b1147b5395c61e3d824f9dff95e7f1d0 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Thu, 16 May 2024 11:28:41 -0400 Subject: [PATCH] Move OS variant retrieval to config module This also deprecates the `getOSVariant` function of the `os-release` module, as the OS variant are no longer defined in `/etc/os-release`. Change-type: patch --- src/config/functions.ts | 9 +++++++-- src/lib/os-release.ts | 12 +++++++----- src/lib/request.ts | 11 ++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/config/functions.ts b/src/config/functions.ts index fa5a6c51..0c98fc92 100644 --- a/src/config/functions.ts +++ b/src/config/functions.ts @@ -31,8 +31,13 @@ export const fnSchema = { osVersion: () => { return osRelease.getOSVersion(constants.hostOSVersionPath); }, - osVariant: () => { - return osRelease.getOSVariant(constants.hostOSVersionPath); + osVariant: async () => { + const osVariant = await osRelease.getOSVariant(constants.hostOSVersionPath); + if (osVariant === undefined) { + const developmentMode = await config.get('developmentMode'); + return developmentMode === true ? 'dev' : 'prod'; + } + return osVariant; }, macAddress: () => { return macAddress.getAll(constants.macAddressPath); diff --git a/src/lib/os-release.ts b/src/lib/os-release.ts index 40a8e6f4..1b3d8147 100644 --- a/src/lib/os-release.ts +++ b/src/lib/os-release.ts @@ -4,7 +4,6 @@ import { promises as fs } from 'fs'; import { InternalInconsistencyError } from './errors'; import { exec } from './fs-utils'; import log from './supervisor-console'; -import * as conf from '../config'; // Retrieve the data for the OS once only per path const getOSReleaseData = _.memoize( @@ -53,12 +52,15 @@ export async function getOSVersion(path: string): Promise { return getOSReleaseField(path, 'PRETTY_NAME'); } +/** + * Returns the OS variant information from /etc/release + * + * OS variants no longer exist and this function only exists for legacy reasons + * + * @deprecated + */ export async function getOSVariant(path: string): Promise { const osVariant = await getOSReleaseField(path, 'VARIANT_ID'); - if (osVariant === undefined) { - const developmentMode = await conf.get('developmentMode'); - return developmentMode === true ? 'dev' : 'prod'; - } return osVariant; } diff --git a/src/lib/request.ts b/src/lib/request.ts index 76eae460..42f86a4f 100644 --- a/src/lib/request.ts +++ b/src/lib/request.ts @@ -2,9 +2,7 @@ import Bluebird from 'bluebird'; import once = require('lodash/once'); import requestLib from 'request'; import resumableRequestLib from 'resumable-request'; - -import * as constants from './constants'; -import * as osRelease from './os-release'; +import * as config from '../config'; import supervisorVersion = require('./supervisor-version'); @@ -41,9 +39,12 @@ type PromisifiedRequest = typeof requestLib & { }; const getRequestInstances = once(async () => { + await config.initialized(); // Generate the user agents with out versions - const osVersion = await osRelease.getOSVersion(constants.hostOSVersionPath); - const osVariant = await osRelease.getOSVariant(constants.hostOSVersionPath); + const { osVersion, osVariant } = await config.getMany([ + 'osVersion', + 'osVariant', + ]); let userAgent = `Supervisor/${supervisorVersion}`; if (osVersion != null) { if (osVariant != null) {