From 28d12eb2240ff717892d9a79e2ef2cdfc35b2bfa Mon Sep 17 00:00:00 2001 From: xuu Date: Sun, 12 Nov 2017 08:15:57 -0700 Subject: [PATCH] fix json decode issue --- check-my-stuff | 13 +------------ check-pol | 1 + utils/schema-check/dn42-schema.py | 5 ++++- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/check-my-stuff b/check-my-stuff index c05221225..79ebd8e1b 100755 --- a/check-my-stuff +++ b/check-my-stuff @@ -1,4 +1,5 @@ #!/bin/sh +set -eo pipefail if [ "$#" -eq "0" ] then @@ -19,15 +20,3 @@ cd "$BASE" || exit 1 utils/schema-check/dn42-schema.py -v scan data/ $MNT || ( echo "Schema validation failed, please check above!" ; exit 1 ) -exit 0 - -git diff --cached --name-only | while IFS='/' read -ra LINE; do -if [[ "${LINE[0]}" = "data" ]]; then - if ! utils/schema-check/dn42-schema.py policy ${LINE[1]} ${LINE[2]} $MNT; then - echo "# This file fails policy checks. To continue with the commit revert the change." - echo "# git reset HEAD -- " ${LINE[1]}/${LINE[1]}/${LINE[2]} - echo "# git checkout -- " ${LINE[1]}/${LINE[1]}/${LINE[2]} - exit 1 - fi -fi -done diff --git a/check-pol b/check-pol index 55baefb80..133c86e01 100755 --- a/check-pol +++ b/check-pol @@ -1,4 +1,5 @@ #!/bin/sh +set -eo pipefail if [ $# -eq 0 ] then diff --git a/utils/schema-check/dn42-schema.py b/utils/schema-check/dn42-schema.py index b1b620e0e..b29a1d191 100755 --- a/utils/schema-check/dn42-schema.py +++ b/utils/schema-check/dn42-schema.py @@ -374,7 +374,10 @@ def http_get(server, url, query=None, headers=None): if "application/json" in req.getheader("Content-Type", "application/json"): if req.status > 299: return {} - return json.loads(req.read()) + r = req.read() + if not isinstance(r, str): + r = r.decode("utf-8") + return json.loads(r) if req.status > 299: return ""