mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 07:46:41 +00:00
Merge pull request #1763 from balena-os/alexgg/development-features
Replace OS variant with development mode
This commit is contained in:
commit
dbb563a0ea
@ -170,6 +170,10 @@ export const schemaTypes = {
|
||||
type: PermissiveBoolean,
|
||||
default: true,
|
||||
},
|
||||
developmentMode: {
|
||||
type: PermissiveBoolean,
|
||||
default: false,
|
||||
},
|
||||
|
||||
// Function schema types
|
||||
// The type should be the value that the promise resolves
|
||||
|
@ -79,6 +79,11 @@ export const schema = {
|
||||
mutable: false,
|
||||
removeIfNull: false,
|
||||
},
|
||||
developmentMode: {
|
||||
source: 'config.json',
|
||||
mutable: true,
|
||||
removeIfNull: false,
|
||||
},
|
||||
|
||||
name: {
|
||||
source: 'db',
|
||||
|
@ -125,12 +125,10 @@ export const authMiddleware: AuthorizedRequestHandler = async (
|
||||
};
|
||||
|
||||
try {
|
||||
const conf = await config.getMany(['localMode', 'unmanaged', 'osVariant']);
|
||||
const conf = await config.getMany(['localMode', 'unmanaged']);
|
||||
|
||||
// we only need to check the API key if a) unmanaged and on a production image, or b) managed and not in local mode
|
||||
const needsAuth = conf.unmanaged
|
||||
? conf.osVariant === 'prod'
|
||||
: !conf.localMode;
|
||||
// we only need to check the API key if managed and not in local mode
|
||||
const needsAuth = !conf.unmanaged && !conf.localMode;
|
||||
|
||||
// no need to authenticate, shortcut
|
||||
if (!needsAuth) {
|
||||
|
@ -4,6 +4,7 @@ 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(
|
||||
@ -37,7 +38,7 @@ async function getOSReleaseField(
|
||||
try {
|
||||
const data = await getOSReleaseData(path);
|
||||
const value = data[field];
|
||||
if (value == null) {
|
||||
if (value == null && field !== 'VARIANT_ID') {
|
||||
log.warn(
|
||||
`Field ${field} is not available in OS information file: ${path}`,
|
||||
);
|
||||
@ -52,8 +53,13 @@ export async function getOSVersion(path: string): Promise<string | undefined> {
|
||||
return getOSReleaseField(path, 'PRETTY_NAME');
|
||||
}
|
||||
|
||||
export function getOSVariant(path: string): Promise<string | undefined> {
|
||||
return getOSReleaseField(path, 'VARIANT_ID');
|
||||
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;
|
||||
}
|
||||
|
||||
export function getOSSemver(path: string): Promise<string | undefined> {
|
||||
|
@ -99,13 +99,13 @@ describe('Config', () => {
|
||||
conf.set({ name: 'someValue' });
|
||||
});
|
||||
|
||||
it("returns an undefined OS variant if it doesn't exist", async () => {
|
||||
it("returns production OS variant if it doesn't exist", async () => {
|
||||
const oldPath = constants.hostOSVersionPath;
|
||||
constants.hostOSVersionPath = 'test/data/etc/os-release-novariant';
|
||||
|
||||
const osVariant = await conf.get('osVariant');
|
||||
constants.hostOSVersionPath = oldPath;
|
||||
expect(osVariant).to.be.undefined;
|
||||
expect(osVariant).to.equal('prod');
|
||||
});
|
||||
|
||||
it('reads and exposes MAC addresses', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user