mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-05 05:24:12 +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
|
// We cannot use || for this value, as the empty string is a
|
||||||
// valid restart policy but will equate to null in an OR
|
// 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) {
|
if (restart == null) {
|
||||||
restart = 'always';
|
restart = 'always';
|
||||||
}
|
}
|
||||||
@ -462,7 +462,9 @@ export class Service {
|
|||||||
// the entire ContainerInspectInfo object, or upstream the extra
|
// the entire ContainerInspectInfo object, or upstream the extra
|
||||||
// fields to DefinitelyTyped
|
// fields to DefinitelyTyped
|
||||||
svc.config = {
|
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,
|
portMaps,
|
||||||
expose,
|
expose,
|
||||||
|
@ -19,8 +19,8 @@ export const PermissiveBoolean = new t.Type<boolean, t.TypeOf<PermissiveType>>(
|
|||||||
(m, c) =>
|
(m, c) =>
|
||||||
permissiveValue.validate(m, c).chain(v => {
|
permissiveValue.validate(m, c).chain(v => {
|
||||||
switch (typeof v) {
|
switch (typeof v) {
|
||||||
case 'boolean':
|
|
||||||
case 'string':
|
case 'string':
|
||||||
|
case 'boolean':
|
||||||
case 'number':
|
case 'number':
|
||||||
const val = checkTruthy(v);
|
const val = checkTruthy(v);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
|
@ -61,6 +61,9 @@ export function checkString(s: NullableLiteral): string | void {
|
|||||||
* which represents if the input was truthy
|
* which represents if the input was truthy
|
||||||
*/
|
*/
|
||||||
export function checkTruthy(v: string | boolean | number): boolean | void {
|
export function checkTruthy(v: string | boolean | number): boolean | void {
|
||||||
|
if (_.isString(v)) {
|
||||||
|
v = v.toLowerCase();
|
||||||
|
}
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case '1':
|
case '1':
|
||||||
case 'true':
|
case 'true':
|
||||||
|
Loading…
Reference in New Issue
Block a user