mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-31 11:07:01 +00:00
Merge pull request #971 from balena-io/case-insensitive-validation
Perform case-insensitive checking when converting booleans from strings
This commit is contained in:
commit
6b5da8ba1e
@ -448,7 +448,7 @@ export class Service {
|
||||
|
||||
// We cannot use || for this value, as the empty string is a
|
||||
// valid restart policy but will equate to null in an OR
|
||||
let restart = (container.HostConfig.RestartPolicy || {}).Name;
|
||||
let restart = _.get(container.HostConfig.RestartPolicy, 'Name');
|
||||
if (restart == null) {
|
||||
restart = 'always';
|
||||
}
|
||||
@ -462,7 +462,9 @@ export class Service {
|
||||
// the entire ContainerInspectInfo object, or upstream the extra
|
||||
// fields to DefinitelyTyped
|
||||
svc.config = {
|
||||
networkMode: container.HostConfig.NetworkMode,
|
||||
// The typings say that this is optional, but it's
|
||||
// always set by docker
|
||||
networkMode: container.HostConfig.NetworkMode!,
|
||||
|
||||
portMaps,
|
||||
expose,
|
||||
|
@ -19,8 +19,8 @@ export const PermissiveBoolean = new t.Type<boolean, t.TypeOf<PermissiveType>>(
|
||||
(m, c) =>
|
||||
permissiveValue.validate(m, c).chain(v => {
|
||||
switch (typeof v) {
|
||||
case 'boolean':
|
||||
case 'string':
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
const val = checkTruthy(v);
|
||||
if (val == null) {
|
||||
|
@ -61,6 +61,9 @@ export function checkString(s: NullableLiteral): string | void {
|
||||
* which represents if the input was truthy
|
||||
*/
|
||||
export function checkTruthy(v: string | boolean | number): boolean | void {
|
||||
if (_.isString(v)) {
|
||||
v = v.toLowerCase();
|
||||
}
|
||||
switch (v) {
|
||||
case '1':
|
||||
case 'true':
|
||||
|
Loading…
Reference in New Issue
Block a user