mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-29 22:04:20 +00:00
ux: Warn on invalid device name when trying to start a service
Device names with newlines cause reboot loops, due to newlines not being supported by docker. This PR will warn when a device name contains a newline. Change-type: patch Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
88b0e2fc45
commit
ae446c01b2
@ -5,7 +5,7 @@ JSONStream = require 'JSONStream'
|
|||||||
fs = Promise.promisifyAll(require('fs'))
|
fs = Promise.promisifyAll(require('fs'))
|
||||||
|
|
||||||
logTypes = require '../lib/log-types'
|
logTypes = require '../lib/log-types'
|
||||||
{ checkInt } = require '../lib/validation'
|
{ checkInt, isValidDeviceName } = require '../lib/validation'
|
||||||
constants = require '../lib/constants'
|
constants = require '../lib/constants'
|
||||||
|
|
||||||
Service = require './service'
|
Service = require './service'
|
||||||
@ -103,6 +103,11 @@ module.exports = class ServiceManager extends EventEmitter
|
|||||||
|
|
||||||
@config.get('name')
|
@config.get('name')
|
||||||
.then (deviceName) =>
|
.then (deviceName) =>
|
||||||
|
if !isValidDeviceName(deviceName)
|
||||||
|
throw new Error(
|
||||||
|
'The device name contains a newline, which is unsupported by balena. ' +
|
||||||
|
'Please fix the device name.'
|
||||||
|
)
|
||||||
|
|
||||||
service.environment['RESIN_DEVICE_NAME_AT_INIT'] = deviceName
|
service.environment['RESIN_DEVICE_NAME_AT_INIT'] = deviceName
|
||||||
|
|
||||||
|
@ -154,6 +154,15 @@ export function isValidLabelsObject(obj: LabelObject): boolean {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isValidDeviceName(name: string): boolean {
|
||||||
|
// currently the only disallowed value in a device name is a newline
|
||||||
|
const newline = name.indexOf('\n') !== -1;
|
||||||
|
if (newline) {
|
||||||
|
console.log('debug: newline found in device name. This is invalid and should be removed');
|
||||||
|
}
|
||||||
|
return !newline;
|
||||||
|
}
|
||||||
|
|
||||||
function undefinedOrValidEnv(val: EnvVarObject): boolean {
|
function undefinedOrValidEnv(val: EnvVarObject): boolean {
|
||||||
return val == null || isValidEnv(val);
|
return val == null || isValidEnv(val);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user