Skip to content

Bug Fixes #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adk/ADK.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 24 additions & 19 deletions adk/modeldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down