From 0820e4412c775195480795bfd2485b6f50330da1 Mon Sep 17 00:00:00 2001 From: James Sutton <1892175+zeryx@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:56:08 -0400 Subject: [PATCH 1/2] ignore tamper settings if we're using a model manifest fallback --- adk/modeldata.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/adk/modeldata.py b/adk/modeldata.py index 529d8ff..0b6acab 100644 --- a/adk/modeldata.py +++ b/adk/modeldata.py @@ -6,12 +6,13 @@ class ModelData(object): def __init__(self, client, model_manifest_path): - self.manifest_path = model_manifest_path - self.manifest_freeze_path = "{}.freeze".format(self.manifest_path) - self.manifest_data = get_manifest(self.manifest_freeze_path, self.manifest_path) + self.manifest_reg_path = model_manifest_path + self.manifest_frozen_path = "{}.freeze".format(self.manifest_reg_path) + self.manifest_data = self.get_manifest() self.client = client self.models = {} self.usr_key = "__user__" + self.using_frozen = True def __getitem__(self, key): return getattr(self, self.usr_key + key) @@ -78,28 +79,32 @@ def find_optional_model(self, file_name): with self.client.file(source_uri).getFile() as f: local_data_path = f.name real_hash = md5_for_file(local_data_path) - if real_hash != expected_hash and fail_on_tamper: - raise Exception("Model File Mismatch for " + file_name + - "\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash) + if self.using_frozen: + if real_hash != expected_hash and fail_on_tamper: + raise Exception("Model File Mismatch for " + file_name + + "\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash) + else: + self.models[file_name] = FileData(real_hash, local_data_path) else: self.models[file_name] = FileData(real_hash, local_data_path) -def get_manifest(manifest_frozen_path, manifest_reg_path): - if os.path.exists(manifest_frozen_path): - with open(manifest_frozen_path) as f: - manifest_data = json.load(f) - if check_lock(manifest_data): + def get_manifest(self): + if os.path.exists(self.manifest_frozen_path): + with open(self.manifest_frozen_path) as f: + manifest_data = json.load(f) + if check_lock(manifest_data): + return manifest_data + else: + raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your " + "algorithm's freeze file.") + elif os.path.exists(self.manifest_reg_path): + with open(self.manifest_reg_path) as f: + manifest_data = json.load(f) + self.using_frozen = False return manifest_data else: - raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your " - "algorithm's freeze file.") - elif os.path.exists(manifest_reg_path): - with open(manifest_reg_path) as f: - manifest_data = json.load(f) - return manifest_data - else: - return None + return None def check_lock(manifest_data): From 35a17a3006962e80746d93244f434bde441a83fc Mon Sep 17 00:00:00 2001 From: James Sutton <1892175+zeryx@users.noreply.github.com> Date: Tue, 1 Mar 2022 12:36:22 -0400 Subject: [PATCH 2/2] ensured that init checks for any kind of payload; including "" or {} as input --- adk/ADK.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adk/ADK.py b/adk/ADK.py index 913ca19..10c0222 100644 --- a/adk/ADK.py +++ b/adk/ADK.py @@ -94,7 +94,7 @@ def process_local(self, local_payload, pprint): def init(self, local_payload=None, pprint=print): self.load() - if self.is_local and local_payload: + if self.is_local and local_payload is not None: if self.loading_exception: load_error = create_exception(self.loading_exception, loading_exception=True) self.write_to_pipe(load_error, pprint=pprint)