Fix ssh://user@domain@server.com/ in git repo link (Issue #149)

This commit is contained in:
allegroai 2020-06-20 22:15:08 +03:00
parent d2d3e595af
commit 575f391ba7
2 changed files with 24 additions and 3 deletions

View File

@ -7,11 +7,10 @@ from tempfile import mkstemp
import attr
import logging
import json
from furl import furl
from pathlib2 import Path
from threading import Thread, Event
from .util import get_command_output
from .util import get_command_output, remove_user_pass_from_url
from ....backend_api import Session
from ....debugging import get_logger
from .detectors import GitEnvDetector, GitDetector, HgEnvDetector, HgDetector, Result as DetectionResult
@ -634,7 +633,7 @@ class ScriptInfo(object):
script_requirements = None
script_info = dict(
repository=furl(repo_info.url).remove(username=True, password=True).tostr(),
repository=remove_user_pass_from_url(repo_info.url),
branch=repo_info.branch,
version_num=repo_info.commit,
entry_point=entry_point,

View File

@ -1,6 +1,8 @@
import os
from subprocess import check_output
from furl import furl
def get_command_output(command, path=None):
"""
@ -10,3 +12,23 @@ def get_command_output(command, path=None):
"""
with open(os.devnull, "wb") as devnull:
return check_output(command, cwd=path, stderr=devnull).decode().strip()
def remove_user_pass_from_url(url):
# remove user / password, if we have it embedded in the git repo
url = str(url)
# noinspection PyBroadException
try:
url = furl(url).remove(username=True, password=True).tostr()
except ValueError:
# check if for any reason we have two @
# (e.g. ssh://user@abc.com@domain.com/path or ssh://user@abc.com:pass@domain.com/path)
if len(url.split('@')) >= 3:
# noinspection PyBroadException
try:
url = furl(url.replace('@', '_', 1)).remove(username=True, password=True).tostr()
except Exception:
pass
except Exception:
pass
return url