Merge pull request #971 from balena-io/case-insensitive-validation

Perform case-insensitive checking when converting booleans from strings
This commit is contained in:
CameronDiver 2019-05-03 11:55:23 +01:00 committed by GitHub
commit 6b5da8ba1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

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

View File

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

View File

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