Skip to content

Commit

Permalink
ruff: Fix S108 Probable insecure usage of temporary file or directory.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk authored and timabbott committed Nov 10, 2023
1 parent 8ebacd0 commit 188d459
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions zulip/integrations/codebase/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platformdirs
5 changes: 4 additions & 1 deletion zulip/integrations/codebase/zulip_codebase_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
from typing import Optional

import platformdirs

# Change these values to configure authentication for your codebase account
# Note that this is the Codebase API Username, found in the Settings page
# for your account
Expand Down Expand Up @@ -36,4 +39,4 @@

# This file is used to resume this mirror in case the script shuts down.
# It is required and needs to be writeable.
RESUME_FILE = "/var/tmp/zulip_codebase.state"
RESUME_FILE = os.path.join(platformdirs.user_state_dir(), "zulip_codebase.state")
9 changes: 5 additions & 4 deletions zulip/integrations/log2zulip/log2zulip
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import platform
import re
import subprocess
import sys
import tempfile
import traceback
from pathlib import Path
from typing import List
Expand All @@ -26,9 +25,11 @@ except ImportError:

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../"))

import platformdirs

import zulip

temp_dir = "/var/tmp/" if os.name == "posix" else tempfile.gettempdir()
state_dir = platformdirs.user_state_dir()


def mkdir_p(path: str) -> None:
Expand Down Expand Up @@ -71,7 +72,7 @@ def process_lines(raw_lines: List[str], file_name: str) -> None:


def process_logs() -> None:
data_file_path = os.path.join(temp_dir, "log2zulip.state")
data_file_path = os.path.join(state_dir, "log2zulip.state")
mkdir_p(os.path.dirname(data_file_path))
if not os.path.exists(data_file_path):
Path(data_file_path).write_text("{}")
Expand Down Expand Up @@ -106,7 +107,7 @@ if __name__ == "__main__":
parser.add_argument("--control-path", default="/etc/log2zulip.conf")
args = parser.parse_args()

lock_path = os.path.join(temp_dir, "log2zulip.lock")
lock_path = os.path.join(state_dir, "log2zulip.lock")
if os.path.exists(lock_path):
# This locking code is here to protect against log2zulip,
# running in a cron job, ending up with multiple copies
Expand Down
1 change: 1 addition & 0 deletions zulip/integrations/log2zulip/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platformdirs
7 changes: 4 additions & 3 deletions zulip/integrations/zephyr/zephyr_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,10 @@ def die_gracefully(signal: int, frame: Optional[FrameType]) -> None:
logger.error("\nnagios_path is required with nagios_class\n")
sys.exit(1)

if options.use_sessions and options.session_path is None:
logger.error("--session-path is required with --use-sessions")
sys.exit(1)

zulip_account_email = options.user + "@mit.edu"

start_time = time.time()
Expand Down Expand Up @@ -1330,9 +1334,6 @@ def die_gracefully(signal: int, frame: Optional[FrameType]) -> None:
if options.forward_mail_zephyrs is None:
options.forward_mail_zephyrs = subscribed_to_mail_messages()

if options.session_path is None:
options.session_path = f"/var/tmp/{options.user}"

if options.forward_from_zulip:
child_pid: Optional[int] = os.fork()
if child_pid == 0:
Expand Down

0 comments on commit 188d459

Please sign in to comment.