1
0
Fork 0

Add autoconfiguration of gitlab-domains/github-domains when auth is present for custom domains, fixes #11062

pull/11071/head
Jordi Boggiano 2022-09-16 12:48:02 +02:00
parent de067ff0e8
commit 22bedfd8d8
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 17 additions and 0 deletions

View File

@ -237,6 +237,8 @@ EOT
$this->config->merge(['config' => $this->authConfigFile->exists() ? $this->authConfigFile->read() : []], $this->authConfigFile->getPath()); $this->config->merge(['config' => $this->authConfigFile->exists() ? $this->authConfigFile->read() : []], $this->authConfigFile->getPath());
} }
$this->getIO()->loadConfiguration($this->config);
// List the configuration of the file settings // List the configuration of the file settings
if (true === $input->getOption('list')) { if (true === $input->getOption('list')) {
$this->listConfiguration($this->config->all(), $this->config->raw(), $output, null, $input->getOption('source')); $this->listConfiguration($this->config->all(), $this->config->raw(), $output, null, $input->getOption('source'));

View File

@ -128,6 +128,11 @@ abstract class BaseIO implements IOInterface
} }
foreach ($githubOauth as $domain => $token) { foreach ($githubOauth as $domain => $token) {
if ($domain !== 'github.com' && !in_array($domain, $config->get('github-domains'), true)) {
$this->debug($domain.' is not in the configured github-domains, adding it implicitly as authentication is configured for this domain');
$config->merge(['config' => ['github-domains' => array_merge($config->get('github-domains'), [$domain])]], 'implicit-due-to-auth');
}
// allowed chars for GH tokens are from https://github.blog/changelog/2021-03-04-authentication-token-format-updates/ // allowed chars for GH tokens are from https://github.blog/changelog/2021-03-04-authentication-token-format-updates/
// plus dots which were at some point used for GH app integration tokens // plus dots which were at some point used for GH app integration tokens
if (!Preg::isMatch('{^[.A-Za-z0-9_]+$}', $token)) { if (!Preg::isMatch('{^[.A-Za-z0-9_]+$}', $token)) {
@ -137,11 +142,21 @@ abstract class BaseIO implements IOInterface
} }
foreach ($gitlabOauth as $domain => $token) { foreach ($gitlabOauth as $domain => $token) {
if ($domain !== 'gitlab.com' && !in_array($domain, $config->get('gitlab-domains'), true)) {
$this->debug($domain.' is not in the configured gitlab-domains, adding it implicitly as authentication is configured for this domain');
$config->merge(['config' => ['gitlab-domains' => array_merge($config->get('gitlab-domains'), [$domain])]], 'implicit-due-to-auth');
}
$token = is_array($token) ? $token["token"] : $token; $token = is_array($token) ? $token["token"] : $token;
$this->checkAndSetAuthentication($domain, $token, 'oauth2'); $this->checkAndSetAuthentication($domain, $token, 'oauth2');
} }
foreach ($gitlabToken as $domain => $token) { foreach ($gitlabToken as $domain => $token) {
if ($domain !== 'gitlab.com' && !in_array($domain, $config->get('gitlab-domains'), true)) {
$this->debug($domain.' is not in the configured gitlab-domains, adding it implicitly as authentication is configured for this domain');
$config->merge(['config' => ['gitlab-domains' => array_merge($config->get('gitlab-domains'), [$domain])]], 'implicit-due-to-auth');
}
$username = is_array($token) ? $token["username"] : $token; $username = is_array($token) ? $token["username"] : $token;
$password = is_array($token) ? $token["token"] : 'private-token'; $password = is_array($token) ? $token["token"] : 'private-token';
$this->checkAndSetAuthentication($domain, $username, $password); $this->checkAndSetAuthentication($domain, $username, $password);