1
0
Fork 0

Fix gitlab support for basic-auth fallback from ssh URLs

pull/8401/head
Jordi Boggiano 2019-10-30 11:25:00 +01:00
parent ae9cc3db58
commit b925d06861
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 12 additions and 4 deletions

View File

@ -153,7 +153,14 @@ class Git
return; return;
} }
} }
} elseif (preg_match('{^(https?)://' . self::getGitLabDomainsRegex($this->config) . '/(.*)}', $url, $match)) { } elseif (
preg_match('{^(git)@' . self::getGitLabDomainsRegex($this->config) . ':(.+?)\.git$}i', $url, $match)
|| preg_match('{^(https?)://' . self::getGitLabDomainsRegex($this->config) . '/(.*)}', $url, $match)
) {
if ($match[1] === 'git') {
$match[1] = 'https';
}
if (!$this->io->hasAuthentication($match[2])) { if (!$this->io->hasAuthentication($match[2])) {
$gitLabUtil = new GitLab($this->io, $this->config, $this->process); $gitLabUtil = new GitLab($this->io, $this->config, $this->process);
$message = 'Cloning failed, enter your GitLab credentials to access private repos'; $message = 'Cloning failed, enter your GitLab credentials to access private repos';
@ -165,11 +172,12 @@ class Git
if ($this->io->hasAuthentication($match[2])) { if ($this->io->hasAuthentication($match[2])) {
$auth = $this->io->getAuthentication($match[2]); $auth = $this->io->getAuthentication($match[2]);
if($auth['password'] === 'private-token' || $auth['password'] === 'oauth2') { if ($auth['password'] === 'private-token' || $auth['password'] === 'oauth2' || $auth['password'] === 'gitlab-ci-token') {
$authUrl = $match[1] . '://' . rawurlencode($auth['password']) . ':' . rawurlencode($auth['username']) . '@' . $match[2] . '/' . $match[3]; // swap username and password $authUrl = $match[1] . '://' . rawurlencode($auth['password']) . ':' . rawurlencode($auth['username']) . '@' . $match[2] . '/' . $match[3]; // swap username and password
} else { } else {
$authUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . '/' . $match[3]; $authUrl = $match[1] . '://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . '/' . $match[3];
} }
$command = call_user_func($commandCallable, $authUrl); $command = call_user_func($commandCallable, $authUrl);
if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) { if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
return; return;

View File

@ -689,7 +689,7 @@ class RemoteFilesystem
$message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->originUrl . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit'); $message = "\n".'Could not fetch '.$this->fileUrl.', enter your ' . $this->originUrl . ' credentials ' .($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit');
$gitLabUtil = new GitLab($this->io, $this->config, null); $gitLabUtil = new GitLab($this->io, $this->config, null);
if ($this->io->hasAuthentication($this->originUrl) && ($auth = $this->io->getAuthentication($this->originUrl)) && $auth['password'] === 'private-token') { if ($this->io->hasAuthentication($this->originUrl) && ($auth = $this->io->getAuthentication($this->originUrl)) && in_array($auth['password'], array('gitlab-ci-token', 'private-token'), true)) {
throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus); throw new TransportException("Invalid credentials for '" . $this->fileUrl . "', aborting.", $httpStatus);
} }
@ -820,7 +820,7 @@ class RemoteFilesystem
} elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) { } elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) {
if ($auth['password'] === 'oauth2') { if ($auth['password'] === 'oauth2') {
$headers[] = 'Authorization: Bearer '.$auth['username']; $headers[] = 'Authorization: Bearer '.$auth['username'];
} elseif ($auth['password'] === 'private-token') { } elseif ($auth['password'] === 'private-token' || $auth['password'] === 'gitlab-ci-token') {
$headers[] = 'PRIVATE-TOKEN: '.$auth['username']; $headers[] = 'PRIVATE-TOKEN: '.$auth['username'];
} }
} elseif ('bitbucket.org' === $originUrl } elseif ('bitbucket.org' === $originUrl