From 5f2a6cd8bf3f9d3204c9a79865346cdc8f2ba728 Mon Sep 17 00:00:00 2001 From: hordunlarmy Date: Thu, 29 Jan 2026 17:52:39 +0100 Subject: [PATCH] refactor: Improved handling of environment variables and secrets --- changelogs/2026-01-29_17-26-50.md | 2 +- changelogs/2026-01-29_17-52-23.md | 12 ++ coverage.xml | 273 +++++++++++++++++------------- src/config.py | 13 +- src/env_manager.py | 3 +- 5 files changed, 180 insertions(+), 123 deletions(-) create mode 100644 changelogs/2026-01-29_17-52-23.md diff --git a/changelogs/2026-01-29_17-26-50.md b/changelogs/2026-01-29_17-26-50.md index d5eb377..a20e008 100644 --- a/changelogs/2026-01-29_17-26-50.md +++ b/changelogs/2026-01-29_17-26-50.md @@ -17,4 +17,4 @@ - No explicit bug fixes mentioned in the diff, but several changes improve the handling of environment variables and secrets, potentially fixing related issues. ### Removed -- No features or functionality explicitly removed in the diff, but some configuration options and internal logic have been updated or simplified. \ No newline at end of file +- No features or functionality explicitly removed in the diff, but some configuration options and internal logic have been updated or simplified. diff --git a/changelogs/2026-01-29_17-52-23.md b/changelogs/2026-01-29_17-52-23.md new file mode 100644 index 0000000..b7cd9b4 --- /dev/null +++ b/changelogs/2026-01-29_17-52-23.md @@ -0,0 +1,12 @@ +# Changelog + +## [Unreleased] + +### Changed +- Improved handling of environment variables and secrets, potentially fixing related issues. +- Updated configuration options and internal logic for environment file generation. +- Modified the `GIT_DIR` calculation to handle cases where the project name matches the remote directory name. +- Changed the `create_env_file` function to only create directories without changing their permissions, avoiding potential permission errors. + +### Fixed +- No explicit bug fixes mentioned, but several changes improve the handling of environment variables and secrets, potentially fixing related issues. \ No newline at end of file diff --git a/coverage.xml b/coverage.xml index 445281f..72ea4b8 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,12 +1,12 @@ - + /workspace/personal/MetalDeploy/src - + @@ -14,7 +14,7 @@ - + @@ -56,25 +56,31 @@ - + + - - + + - - - - - - - - - - + + + + + + + + + + + + + + + @@ -154,7 +160,7 @@ - + @@ -227,176 +233,211 @@ - + - - - - + + + + + - - + + - - - - - - + + + + + + + + - - - - + - - + - + + + - - - + + - + - - - + + + + - + + + - - - + - - + + - - + + + + + - - - + - + + + - - - - + + - + - - - - - - + + + + + + + - - - + + + - - - - + + + + - - - - + + + - + + + - - + + - - - - - - - - - - - - - + + + + + + + + + + - - - - + + + - - - - - - - + + + + + + + + + - - - + + + + + + + - + - - - + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/config.py b/src/config.py index 45abaef..34be74e 100644 --- a/src/config.py +++ b/src/config.py @@ -51,11 +51,14 @@ def get_env(name, default=None): self.USE_SUDO = get_bool_env("USE_SUDO") self.PROJECT_NAME = self.GIT_URL.split("/")[-1].split(".")[0] if self.GIT_URL else "" - self.GIT_DIR = ( - os.path.join(self.REMOTE_DIR, self.PROJECT_NAME) - if self.PROJECT_NAME - else self.REMOTE_DIR - ) + if self.PROJECT_NAME and self.REMOTE_DIR.rstrip("/").split("/")[-1] == self.PROJECT_NAME: + self.GIT_DIR = self.REMOTE_DIR + else: + self.GIT_DIR = ( + os.path.join(self.REMOTE_DIR, self.PROJECT_NAME) + if self.PROJECT_NAME + else self.REMOTE_DIR + ) self.GIT_SUBDIR = os.path.join(self.GIT_DIR, "") # Environment file generation configuration diff --git a/src/env_manager.py b/src/env_manager.py index 6d47817..579e14e 100644 --- a/src/env_manager.py +++ b/src/env_manager.py @@ -373,7 +373,8 @@ def create_env_file(conn, file_path: str, env_vars: Dict[str, str]) -> None: return dir_path = os.path.dirname(file_path) if dir_path and dir_path != file_path: - conn.run(f"mkdir -p {dir_path} && chmod 755 {dir_path}") + # Only mkdir, skip chmod on directory to avoid permission errors if it exists/owned by others + conn.run(f"mkdir -p {dir_path}") env_content = "\n".join([f"{k}={v}" for k, v in env_vars.items()]) conn.run(f"cat > \"{file_path}\" << 'EOF'\n{env_content}\nEOF") conn.run(f'chmod 644 "{file_path}"')