Make sure COMPOSER_AUTH is also loaded in Config, refs #4546
parent
2617ec5d28
commit
7c3e621102
|
@ -190,6 +190,20 @@ class Factory
|
||||||
}
|
}
|
||||||
$config->setAuthConfigSource(new JsonConfigSource($file, true));
|
$config->setAuthConfigSource(new JsonConfigSource($file, true));
|
||||||
|
|
||||||
|
// load COMPOSER_AUTH environment variable if set
|
||||||
|
if ($composerAuthEnv = getenv('COMPOSER_AUTH')) {
|
||||||
|
$authData = json_decode($composerAuthEnv, true);
|
||||||
|
|
||||||
|
if (is_null($authData)) {
|
||||||
|
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($io && $io->isDebug()) {
|
||||||
|
$io->writeError('Loading auth config from COMPOESR_AUTH');
|
||||||
|
}
|
||||||
|
$config->merge(array('config' => $authData));
|
||||||
|
}
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,47 +64,22 @@ abstract class BaseIO implements IOInterface
|
||||||
$gitlabOauth = $config->get('gitlab-oauth') ?: array();
|
$gitlabOauth = $config->get('gitlab-oauth') ?: array();
|
||||||
$httpBasic = $config->get('http-basic') ?: array();
|
$httpBasic = $config->get('http-basic') ?: array();
|
||||||
|
|
||||||
// Use COMPOSER_AUTH environment variable if set
|
|
||||||
if ($composerAuthEnv = getenv('COMPOSER_AUTH')) {
|
|
||||||
$authData = json_decode($composerAuthEnv, true);
|
|
||||||
|
|
||||||
if (is_null($authData)) {
|
|
||||||
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($authData['github-oauth'])) {
|
|
||||||
$githubOauth = array_merge($githubOauth, $authData['github-oauth']);
|
|
||||||
}
|
|
||||||
if (isset($authData['gitlab-oauth'])) {
|
|
||||||
$gitlabOauth = array_merge($gitlabOauth, $authData['gitlab-oauth']);
|
|
||||||
}
|
|
||||||
if (isset($authData['http-basic'])) {
|
|
||||||
$httpBasic = array_merge($httpBasic, $authData['http-basic']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload oauth token from config if available
|
// reload oauth token from config if available
|
||||||
if ($githubOauth) {
|
|
||||||
foreach ($githubOauth as $domain => $token) {
|
foreach ($githubOauth as $domain => $token) {
|
||||||
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
||||||
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
||||||
}
|
}
|
||||||
$this->setAuthentication($domain, $token, 'x-oauth-basic');
|
$this->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($gitlabOauth) {
|
|
||||||
foreach ($gitlabOauth as $domain => $token) {
|
foreach ($gitlabOauth as $domain => $token) {
|
||||||
$this->setAuthentication($domain, $token, 'oauth2');
|
$this->setAuthentication($domain, $token, 'oauth2');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// reload http basic credentials from config if available
|
// reload http basic credentials from config if available
|
||||||
if ($httpBasic) {
|
|
||||||
foreach ($httpBasic as $domain => $cred) {
|
foreach ($httpBasic as $domain => $cred) {
|
||||||
$this->setAuthentication($domain, $cred['username'], $cred['password']);
|
$this->setAuthentication($domain, $cred['username'], $cred['password']);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// setup process timeout
|
// setup process timeout
|
||||||
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
|
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
|
||||||
|
|
Loading…
Reference in New Issue