Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 7a70291

Browse files
docker IO files are now in bytes
1 parent 59cf29b commit 7a70291

File tree

4 files changed

+18
-39
lines changed

4 files changed

+18
-39
lines changed

vantage/node/docker_manager.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def is_docker_image_allowed(self, docker_image_name: str):
133133
return False
134134

135135
def run(self, result_id: int, image: str, database_uri: str,
136-
docker_input: str, tmp_vol_name: int, token: str) -> bool:
136+
docker_input: bytes, tmp_vol_name: int, token: str) -> bool:
137137
""" Runs the docker-image in detached mode.
138138
139139
It will will attach all mounts (input, output and datafile)
@@ -158,8 +158,8 @@ def run(self, result_id: int, image: str, database_uri: str,
158158
self.log.debug("prepare IO files in docker volume")
159159
io_files = [
160160
('input', docker_input),
161-
('output', ''),
162-
('token', token),
161+
('output', b''),
162+
('token', token.encode("ascii")),
163163
]
164164

165165
# the data-volume is shared amongst all algorithm containers,
@@ -174,8 +174,8 @@ def run(self, result_id: int, image: str, database_uri: str,
174174
io_path = pathlib.Path("/mnt/data-volume") / folder_name
175175
os.makedirs(io_path, exist_ok=True)
176176
for (filename, contents) in io_files:
177-
path = io_path / f"{filename}.txt"
178-
with open(path, 'w') as fp:
177+
path = io_path / f"{filename}"
178+
with open(path, 'wb') as fp:
179179
fp.write(contents)
180180

181181
# attempt to pull the latest image
@@ -190,9 +190,9 @@ def run(self, result_id: int, image: str, database_uri: str,
190190
# facilitate indirect communication with the central server
191191
tmp_folder = "/mnt/tmp" # docker env
192192
environment_variables = {
193-
"INPUT_FILE": str(io_path / "input.txt"),
194-
"OUTPUT_FILE": str(io_path / "output.txt"),
195-
"TOKEN_FILE": str(io_path / "token.txt"),
193+
"INPUT_FILE": str(io_path / "input"),
194+
"OUTPUT_FILE": str(io_path / "output"),
195+
"TOKEN_FILE": str(io_path / "token"),
196196
"TEMPORARY_FOLDER": tmp_folder,
197197
"DATABASE_URI": "/mnt/data-volume/database.csv",
198198
"HOST": f"http://{cs.NODE_PROXY_SERVER_HOSTNAME}",
@@ -228,7 +228,7 @@ def run(self, result_id: int, image: str, database_uri: str,
228228
self.active_tasks.append({
229229
"result_id": result_id,
230230
"container": container,
231-
"output_file": io_path / "output.txt"
231+
"output_file": io_path / "output"
232232
})
233233

234234
return True

vantage/node/encryption.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,10 @@ def __init__(self, private_key_file=None):
247247
self.log.warning(
248248
"Encrpytion disabled! Use this only for debugging")
249249

250-
251-
def encrypt_obj_to_base64(
252-
self, msg: dict, public_key_base64: str) -> str:
253-
""" Encrypt dictonairy `msg` using `public_key_base64`.
254-
"""
255-
msg_ = prepare_bytes_for_transport(msg)
256-
return pickle.dumps(msg_)
257-
258-
def encrypt_str_to_base64(
259-
self, msg: str, public_key_base64: str) -> str:
260-
return msg
261-
250+
262251
def encrypt_bytes_to_base64(
263252
self, msg: bytes, public_key_base64: str) -> str:
264-
return msg.decode(cs.STRING_ENCODING)
253+
return prepare_bytes_for_transport(msg)
265254

266255
def encrypt_bytes(self, msg: bytes, public_key_bytes: bytes) -> bytes:
267256
return msg
@@ -270,14 +259,4 @@ def decrypt_bytes(self, msg: bytes) -> bytes:
270259
return msg
271260

272261
def decrypt_bytes_from_base64(self, msg: str) -> bytes:
273-
return msg.encode(cs.STRING_ENCODING)
274-
275-
def decrypt_str_from_base64(self, msg: str) -> str:
276-
return msg
277-
278-
def decrypt_obj_from_base64(self, msg: str) -> dict:
279-
if msg:
280-
msg_ = unpack_bytes_from_transport(msg)
281-
return pickle.loads(msg_)
282-
else:
283-
return b""
262+
return unpack_bytes_from_transport(msg)

vantage/node/proxy_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def proxy_task_result(id):
139139
).json()
140140
unencrypted = []
141141
for result in results:
142-
result["result"] = server_io.cryptor.decrypt_obj_from_base64(
142+
result["result"] = server_io.cryptor.decrypt_bytes_from_base64(
143143
result["result"]
144144
)
145145
unencrypted.append(result)
@@ -172,7 +172,7 @@ def proxy_results(id):
172172
headers={'Authorization': auth}
173173
)
174174
encrypted_input = response["result"]
175-
response["result"] = server_io.cryptor.decrypt_obj_from_base64(
175+
response["result"] = server_io.cryptor.decrypt_bytes_from_base64(
176176
response["result"]
177177
)
178178
log.error(response)

vantage/node/server_io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ def get_results(self, id=None, state=None, include_task=False,
351351
if not id:
352352
for result in results:
353353
try:
354-
result["input"] = self.cryptor.decrypt_obj_from_base64(
354+
result["input"] = self.cryptor.decrypt_bytes_from_base64(
355355
result["input"]
356356
)
357357
if result["result"]:
358-
result["result"] = self.cryptor.decrypt_obj_from_base64(
358+
result["result"] = self.cryptor.decrypt_bytes_from_base64(
359359
result["result"]
360360
)
361361

@@ -370,10 +370,10 @@ def get_results(self, id=None, state=None, include_task=False,
370370
return results_unencrypted
371371
else:
372372
try:
373-
results["input"] = self.cryptor.decrypt_obj_from_base64(
373+
results["input"] = self.cryptor.decrypt_bytes_from_base64(
374374
results["input"]
375375
)
376-
results["result"] = self.cryptor.decrypt_obj_from_base64(
376+
results["result"] = self.cryptor.decrypt_bytes_from_base64(
377377
results["result"]
378378
)
379379
except ValueError as e:

0 commit comments

Comments
 (0)