Skip to content

Commit

Permalink
Fix: Solved PR comments and wrong conditionals.
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor committed Jun 5, 2024
1 parent 8fc195c commit 5d2eb5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
13 changes: 5 additions & 8 deletions src/aleph/vm/orchestrator/views/operator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
from datetime import timedelta

import aiohttp.web_exceptions
Expand Down Expand Up @@ -158,23 +157,21 @@ async def operate_start(request: web.Request, authenticated_sender: str) -> web.
post = await request.post()

vm_session_path = settings.CONFIDENTIAL_SESSION_DIRECTORY / vm_hash
os.makedirs(vm_session_path, exist_ok=True)
vm_session_path.mkdir(exist_ok=True)

session_file_content = post.get("session")
if session_file_content:
if not session_file_content:
return web.Response(status=403, body=f"Session file required for VM with ref {vm_hash}")

session_file_path = vm_session_path / "vm_session.b64"
with open(session_file_path, "wb") as session_file:
session_file.write(session_file_content.file.read())
session_file_path.write_bytes(session_file_content.file.read())

godh_file_content = post.get("godh")
if godh_file_content:
if not godh_file_content:
return web.Response(status=403, body=f"GODH file required for VM with ref {vm_hash}")

godh_file_path = vm_session_path / "vm_godh.b64"
with open(godh_file_path, "wb") as godh_file:
godh_file.write(godh_file_content.file.read())
godh_file_path.write_bytes(godh_file_content.file.read())

pool.systemd_manager.enable_and_start(execution.controller_service)

Expand Down
5 changes: 0 additions & 5 deletions src/aleph/vm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,3 @@ def file_hashes_differ(source: Path, destination: Path, checksum: Callable[[Path
return True

return checksum(source) != checksum(destination)


def write_bytes_file(file_path: Path, file_content: bytes):
"""Save a file on disk in async way."""
file_path.write_bytes(file_content)

0 comments on commit 5d2eb5f

Please sign in to comment.