Skip to content

Commit 0820e44

Browse files
committed
ignore tamper settings if we're using a model manifest fallback
1 parent 1e5c6b9 commit 0820e44

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

adk/modeldata.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
class ModelData(object):
88
def __init__(self, client, model_manifest_path):
9-
self.manifest_path = model_manifest_path
10-
self.manifest_freeze_path = "{}.freeze".format(self.manifest_path)
11-
self.manifest_data = get_manifest(self.manifest_freeze_path, self.manifest_path)
9+
self.manifest_reg_path = model_manifest_path
10+
self.manifest_frozen_path = "{}.freeze".format(self.manifest_reg_path)
11+
self.manifest_data = self.get_manifest()
1212
self.client = client
1313
self.models = {}
1414
self.usr_key = "__user__"
15+
self.using_frozen = True
1516

1617
def __getitem__(self, key):
1718
return getattr(self, self.usr_key + key)
@@ -78,28 +79,32 @@ def find_optional_model(self, file_name):
7879
with self.client.file(source_uri).getFile() as f:
7980
local_data_path = f.name
8081
real_hash = md5_for_file(local_data_path)
81-
if real_hash != expected_hash and fail_on_tamper:
82-
raise Exception("Model File Mismatch for " + file_name +
83-
"\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash)
82+
if self.using_frozen:
83+
if real_hash != expected_hash and fail_on_tamper:
84+
raise Exception("Model File Mismatch for " + file_name +
85+
"\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash)
86+
else:
87+
self.models[file_name] = FileData(real_hash, local_data_path)
8488
else:
8589
self.models[file_name] = FileData(real_hash, local_data_path)
8690

8791

88-
def get_manifest(manifest_frozen_path, manifest_reg_path):
89-
if os.path.exists(manifest_frozen_path):
90-
with open(manifest_frozen_path) as f:
91-
manifest_data = json.load(f)
92-
if check_lock(manifest_data):
92+
def get_manifest(self):
93+
if os.path.exists(self.manifest_frozen_path):
94+
with open(self.manifest_frozen_path) as f:
95+
manifest_data = json.load(f)
96+
if check_lock(manifest_data):
97+
return manifest_data
98+
else:
99+
raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your "
100+
"algorithm's freeze file.")
101+
elif os.path.exists(self.manifest_reg_path):
102+
with open(self.manifest_reg_path) as f:
103+
manifest_data = json.load(f)
104+
self.using_frozen = False
93105
return manifest_data
94106
else:
95-
raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your "
96-
"algorithm's freeze file.")
97-
elif os.path.exists(manifest_reg_path):
98-
with open(manifest_reg_path) as f:
99-
manifest_data = json.load(f)
100-
return manifest_data
101-
else:
102-
return None
107+
return None
103108

104109

105110
def check_lock(manifest_data):

0 commit comments

Comments
 (0)