commit 2529f5cd2cb82f6fdcc657e4bfc8750363e9a125
parent f82d853ef367545878c168b444f89e8a42e445eb
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Fri, 12 Dec 2025 20:17:50 +0100
Pass tokens as env variables
Diffstat:
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/git-backup.py b/git-backup.py
@@ -22,24 +22,12 @@ import git
import requests
-ENV_GITLAB_TOKEN_PATH = "GITLAB_TOKEN_PATH"
-ENV_GITHUB_TOKEN_PATH = "GITHUB_TOKEN_PATH"
+ENV_GITLAB_TOKEN = "GITLAB_TOKEN"
+ENV_GITHUB_TOKEN = "GITHUB_TOKEN"
ENV_CUSTOM_REPOSITORIES_PATH = "CUSTOM_REPOSITORIES_PATH"
ENV_TARGET_DIR = "TARGET_DIR"
-def read_file(env_var):
- token_path = os.environ.get(env_var)
- if not token_path:
- return None
- try:
- with open(token_path, "r") as f:
- return f.read().strip()
- except FileNotFoundError:
- print("Error: File {token_path} not found", file=sys.stderr)
- return None
-
-
def backup_gitlab(token):
def get_repositories_data_gitlab(url, page):
response = requests.get(url + "&page=" + str(page))
@@ -132,23 +120,13 @@ def main():
backup_data["time"] = str(datetime.datetime.now())
backup_data["sites"] = {}
- token_path = os.environ.get(ENV_GITLAB_TOKEN_PATH)
- if token_path:
- try:
- with open(token_path, "r") as f:
- token = f.read().strip()
- backup_gitlab(token)
- except FileNotFoundError:
- print("Error: File " + token_path + " not found", file=sys.stderr)
+ token = os.environ.get(ENV_GITLAB_TOKEN)
+ if token:
+ backup_gitlab(token)
- token_path = os.environ.get(ENV_GITHUB_TOKEN_PATH)
- if token_path:
- try:
- with open(token_path, "r") as f:
- token = f.read().strip()
- backup_github(token)
- except FileNotFoundError:
- print("Error: File " + token_path + " not found", file=sys.stderr)
+ token = os.environ.get(ENV_GITHUB_TOKEN)
+ if token:
+ backup_github(token)
custom_repositories_path = os.environ.get(ENV_CUSTOM_REPOSITORIES_PATH)
if custom_repositories_path: