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:
Cameron Diver 2018-08-16 17:17:34 +01:00
parent 88b0e2fc45
commit ae446c01b2
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
2 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,7 @@ JSONStream = require 'JSONStream'
fs = Promise.promisifyAll(require('fs'))
logTypes = require '../lib/log-types'
{ checkInt } = require '../lib/validation'
{ checkInt, isValidDeviceName } = require '../lib/validation'
constants = require '../lib/constants'
Service = require './service'
@ -103,6 +103,11 @@ module.exports = class ServiceManager extends EventEmitter
@config.get('name')
.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

View File

@ -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 {
return val == null || isValidEnv(val);
}