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
This commit is contained in:
Felipe Lalanne 2024-05-16 11:28:41 -04:00
parent 59689b2789
commit 027c2575b1
3 changed files with 20 additions and 12 deletions

View File

@ -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);

View File

@ -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<string | undefined> {
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<string | undefined> {
const osVariant = await getOSReleaseField(path, 'VARIANT_ID');
if (osVariant === undefined) {
const developmentMode = await conf.get('developmentMode');
return developmentMode === true ? 'dev' : 'prod';
}
return osVariant;
}

View File

@ -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) {