Skip to content

Commit a97eb56

Browse files
Marca23Nattapat Iammelap
andauthored
using the content hash as the execute file name (#12)
Co-authored-by: Nattapat Iammelap <[email protected]>
1 parent 8128f2c commit a97eb56

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

google-cloud-functions/google_cloud_function.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shlex
44
import subprocess
55
import base64
6+
import hashlib
67

78
# Set environment flag of MAX_EXECUTABLE, MAX_DATA_SIZE
89

@@ -66,7 +67,8 @@ def execute(request):
6667
except ValueError:
6768
return bad_request("Timeout format invalid")
6869

69-
path = "/tmp/execute.sh"
70+
hash = hashlib.sha256(executable).hexdigest().upper()
71+
path = f"/tmp/{hash}.sh"
7072
with open(path, "w") as f:
7173
f.write(executable.decode())
7274

lambda/lambda_function.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shlex
44
import base64
55
import subprocess
6+
import hashlib
67

78
HEADERS = {
89
"content-type": "application/json",
@@ -75,7 +76,8 @@ def lambda_handler(event, context):
7576
except ValueError:
7677
return bad_request("Timeout format invalid")
7778

78-
path = "/tmp/execute.sh"
79+
hash = hashlib.sha256(executable).hexdigest().upper()
80+
path = f"/tmp/{hash}.sh"
7981
with open(path, "w") as f:
8082
f.write(executable.decode())
8183

0 commit comments

Comments
 (0)