diff options
author | Zuul <zuul@review.opendev.org> | 2023-04-03 11:39:05 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-04-03 11:39:05 +0000 |
commit | 19b80e0c6ed1174e41aa225999d4f41332d118fd (patch) | |
tree | eedc2eabfd00dd5412cebad31639ae388c0372e7 /ironicclient/common/utils.py | |
parent | 138d7974ad93771c5e5f01bac2dbe22d6b28e3af (diff) | |
parent | e9140862822f214030208c26ce8c117990ae4585 (diff) | |
download | python-ironicclient-19b80e0c6ed1174e41aa225999d4f41332d118fd.tar.gz |
Merge "Accept configdrive as a JSON file"
Diffstat (limited to 'ironicclient/common/utils.py')
-rw-r--r-- | ironicclient/common/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ironicclient/common/utils.py b/ironicclient/common/utils.py index 963d2f2..769ef31 100644 --- a/ironicclient/common/utils.py +++ b/ironicclient/common/utils.py @@ -435,3 +435,24 @@ def handle_json_arg(json_arg, info_desc): if json_arg: json_arg = handle_json_or_file_arg(json_arg) return json_arg + + +def get_json_data(data): + """Check if the binary data is JSON and parse it if so. + + Only supports dictionaries. + """ + # We don't want to simply loads() a potentially large binary. Doing so, + # in my testing, is orders of magnitude (!!) slower than this process. + for idx in range(len(data)): + char = data[idx:idx + 1] + if char.isspace(): + continue + if char != b'{' and char != 'b[': + return None # not JSON, at least not JSON we care about + break # maybe JSON + + try: + return json.loads(data) + except ValueError: + return None |