Skip to content

Commit c9493d6

Browse files
committed
Add test before start to check IPC accesibility
1 parent a23c08b commit c9493d6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

aikido_zen/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import os
66

7+
from aikido_zen.background_process.test_uds_file_access import test_uds_file_access
8+
79
# Re-export functions :
810
from aikido_zen.context.users import set_user
911
from aikido_zen.middleware import should_block_request
@@ -30,6 +32,9 @@ def protect(mode="daemon", token=""):
3032
if aikido_disabled_flag_active():
3133
# Do not run any aikido code when the disabled flag is on
3234
return
35+
if not test_uds_file_access():
36+
return # Unable to start background process
37+
3338
if token:
3439
os.environ["AIKIDO_TOKEN"] = token
3540

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import platform
3+
import sys
4+
5+
from aikido_zen.background_process import get_uds_filename
6+
from aikido_zen.helpers.logging import logger
7+
8+
9+
def test_uds_file_access():
10+
"""Returns true if access is possible, false if it's not."""
11+
filename = get_uds_filename()
12+
directory = "/".join(filename.split("/")[:-1])
13+
14+
if platform.system() == "Windows":
15+
# Python does not support Windows UDS just yet, so we have to rely on INET
16+
return True
17+
18+
if not os.access(directory, os.R_OK) or not os.access(directory, os.W_OK):
19+
# We need both read and write permissions in order to start the socket
20+
logger.critical(
21+
"Cannot start Zen: no read/write permissions for directory %s. "
22+
+ "You can change the path by setting "
23+
+ "the AIKIDO_TMP_DIR environment variable.",
24+
directory,
25+
)
26+
return False
27+
return True

0 commit comments

Comments
 (0)