From 8135a6facfd0864c8f26fefd59f318927d4c5357 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sun, 4 Oct 2020 19:40:04 +0300 Subject: [PATCH] Add agent.git_domain setting for limiting git credential usage for a specific domain (env var TRAINS_AGENT_GIT_DOMAIN is also supported) --- trains_agent/definitions.py | 1 + trains_agent/helper/repo.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/trains_agent/definitions.py b/trains_agent/definitions.py index 75e2a27..0295338 100644 --- a/trains_agent/definitions.py +++ b/trains_agent/definitions.py @@ -122,6 +122,7 @@ PIP_EXTRA_INDICES = [ DEFAULT_PIP_DOWNLOAD_CACHE = normalize_path(CONFIG_DIR, "pip-download-cache") ENV_AGENT_GIT_USER = EnvironmentConfig('TRAINS_AGENT_GIT_USER') ENV_AGENT_GIT_PASS = EnvironmentConfig('TRAINS_AGENT_GIT_PASS') +ENV_AGENT_GIT_DOMAIN = EnvironmentConfig('TRAINS_AGENT_GIT_DOMAIN') ENV_TASK_EXECUTE_AS_USER = 'TRAINS_AGENT_EXEC_USER' ENV_TASK_EXTRA_PYTHON_PATH = 'TRAINS_AGENT_EXTRA_PYTHON_PATH' ENV_DOCKER_HOST_MOUNT = EnvironmentConfig('TRAINS_AGENT_K8S_HOST_MOUNT', 'TRAINS_AGENT_DOCKER_HOST_MOUNT') diff --git a/trains_agent/helper/repo.py b/trains_agent/helper/repo.py index 195fd9b..4dfea20 100644 --- a/trains_agent/helper/repo.py +++ b/trains_agent/helper/repo.py @@ -13,7 +13,7 @@ from pathlib2 import Path import six -from trains_agent.definitions import ENV_AGENT_GIT_USER, ENV_AGENT_GIT_PASS +from trains_agent.definitions import ENV_AGENT_GIT_USER, ENV_AGENT_GIT_PASS, ENV_AGENT_GIT_DOMAIN from trains_agent.helper.console import ensure_text, ensure_binary from trains_agent.errors import CommandFailedError from trains_agent.helper.base import ( @@ -443,10 +443,12 @@ class VCS(object): return parsed_url.url config_user = ENV_AGENT_GIT_USER.get() or config.get("agent.{}_user".format(cls.executable_name), None) config_pass = ENV_AGENT_GIT_PASS.get() or config.get("agent.{}_pass".format(cls.executable_name), None) + config_domain = ENV_AGENT_GIT_DOMAIN.get() or config.get("agent.{}_domain".format(cls.executable_name), None) if ( (not (parsed_url.username and parsed_url.password)) and config_user and config_pass + and (not config_domain or config_domain.lower() == parsed_url.host) ): parsed_url.set(username=config_user, password=config_pass) return parsed_url.url