Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow appending deployment key to username (#2062) #96

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import subprocess

from collections import namedtuple
from typing import Optional

from poetry.core.utils._compat import decode


pattern_formats = {
"protocol": r"\w+",
"user": r"[a-zA-Z0-9_.-]+",
"user": r"[a-zA-Z0-9_.\+-]+",
"password": r"[\w\d-]+",
"resource": r"[a-zA-Z0-9_.-]+",
"port": r"\d+",
"path": r"[\w~.\-/\\]+",
Expand All @@ -21,14 +23,15 @@
re.compile(
r"^(git\+)?"
r"(?P<protocol>https?|git|ssh|rsync|file)://"
r"(?:(?P<user>{user})@)?"
r"(?:(?P<user>{user})(:(?P<password>{password}))?@)?"
r"(?P<resource>{resource})?"
r"(:(?P<port>{port}))?"
r"(?P<pathname>[:/\\]({path}[/\\])?"
r"((?P<name>{name}?)(\.git|[/\\])?)?)"
r"([@#](?P<rev>{rev}))?"
r"$".format(
user=pattern_formats["user"],
password=pattern_formats["password"],
resource=pattern_formats["resource"],
port=pattern_formats["port"],
path=pattern_formats["path"],
Expand All @@ -39,7 +42,7 @@
re.compile(
r"(git\+)?"
r"((?P<protocol>{protocol})://)"
r"(?:(?P<user>{user})@)?"
r"(?:(?P<user>{user})(:(?P<password>{password}))?@)?"
r"(?P<resource>{resource}:?)"
r"(:(?P<port>{port}))?"
r"(?P<pathname>({path})"
Expand All @@ -48,6 +51,7 @@
r"$".format(
protocol=pattern_formats["protocol"],
user=pattern_formats["user"],
password=pattern_formats["password"],
resource=pattern_formats["resource"],
port=pattern_formats["port"],
path=pattern_formats["path"],
Expand All @@ -56,14 +60,15 @@
)
),
re.compile(
r"^(?:(?P<user>{user})@)?"
r"^(?:(?P<user>{user})(:(?P<password>{password}))?@)?"
r"(?P<resource>{resource})"
r"(:(?P<port>{port}))?"
r"(?P<pathname>([:/]{path}/)"
r"(?P<name>{name})(\.git|/)?)"
r"([@#](?P<rev>{rev}))?"
r"$".format(
user=pattern_formats["user"],
password=pattern_formats["password"],
resource=pattern_formats["resource"],
port=pattern_formats["port"],
path=pattern_formats["path"],
Expand All @@ -72,14 +77,15 @@
)
),
re.compile(
r"((?P<user>{user})@)?"
r"((?P<user>{user})(:(?P<password>{password}))?@)?"
r"(?P<resource>{resource})"
r"[:/]{{1,2}}"
r"(?P<pathname>({path})"
r"(?P<name>{name})(\.git|/)?)"
r"([@#](?P<rev>{rev}))?"
r"$".format(
user=pattern_formats["user"],
password=pattern_formats["password"],
resource=pattern_formats["resource"],
path=pattern_formats["path"],
name=pattern_formats["name"],
Expand All @@ -90,17 +96,28 @@


class ParsedUrl:
def __init__(self, protocol, resource, pathname, user, port, name, rev):
def __init__(
self,
protocol=None,
resource=None,
pathname=None,
user=None,
password=None,
port=None,
name=None,
rev=None,
): # type: (Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str],Optional[str], Optional[str]) -> None
self.protocol = protocol
self.resource = resource
self.pathname = pathname
self.user = user
self.password = password
self.port = port
self.name = name
self.rev = rev

@classmethod
def parse(cls, url): # type: () -> ParsedUrl
def parse(cls, url): # type: (str) -> ParsedUrl
for pattern in PATTERNS:
m = pattern.match(url)
if m:
Expand All @@ -110,6 +127,7 @@ def parse(cls, url): # type: () -> ParsedUrl
groups.get("resource"),
groups.get("pathname"),
groups.get("user"),
groups.get("password"),
groups.get("port"),
groups.get("name"),
groups.get("rev"),
Expand All @@ -119,14 +137,23 @@ def parse(cls, url): # type: () -> ParsedUrl

@property
def url(self): # type: () -> str
return "{}{}{}{}{}".format(
return "{}{}{}{}{}{}{}".format(
"{}://".format(self.protocol) if self.protocol else "",
"{}@".format(self.user) if self.user else "",
"{}".format(self.user) if self.user else "",
":{}".format(self.password) if self.password else "",
"@" if self.user else "",
self.resource,
":{}".format(self.port) if self.port else "",
"/" + self.pathname.lstrip(":/"),
)

@property
def is_unsafe(self): # type: () -> bool
if self.password is not None:
return True
else:
return False

def format(self): # type: () -> str
return self.url

Expand Down
Loading