Merge pull request #1763 from balena-os/alexgg/development-features

Replace OS variant with development mode
This commit is contained in:
bulldozer-balena[bot] 2021-09-07 15:01:22 +00:00 committed by GitHub
commit dbb563a0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 10 deletions

View File

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

View File

@ -79,6 +79,11 @@ export const schema = {
mutable: false,
removeIfNull: false,
},
developmentMode: {
source: 'config.json',
mutable: true,
removeIfNull: false,
},
name: {
source: 'db',

View File

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

View File

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

View File

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