Allow the authentications to be loaded in the IO independently
parent
472037fb90
commit
14fcff8aa8
|
@ -208,16 +208,7 @@ class Factory
|
||||||
// Configuration defaults
|
// Configuration defaults
|
||||||
$config = static::createConfig();
|
$config = static::createConfig();
|
||||||
$config->merge($localConfig);
|
$config->merge($localConfig);
|
||||||
|
$io->loadConfiguration($config);
|
||||||
// reload oauth token from config if available
|
|
||||||
if ($tokens = $config->get('github-oauth')) {
|
|
||||||
foreach ($tokens as $domain => $token) {
|
|
||||||
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
|
||||||
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
|
||||||
}
|
|
||||||
$io->setAuthentication($domain, $token, 'x-oauth-basic');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$vendorDir = $config->get('vendor-dir');
|
$vendorDir = $config->get('vendor-dir');
|
||||||
$binDir = $config->get('bin-dir');
|
$binDir = $config->get('bin-dir');
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\IO;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Helper\HelperSet;
|
||||||
|
use Composer\Config;
|
||||||
|
|
||||||
|
class BaseIO implements IOInterface
|
||||||
|
{
|
||||||
|
protected $authentications = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getAuthentications()
|
||||||
|
{
|
||||||
|
return $this->authentications;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function hasAuthentication($repositoryName)
|
||||||
|
{
|
||||||
|
return isset($this->authentications[$repositoryName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getAuthentication($repositoryName)
|
||||||
|
{
|
||||||
|
if (isset($this->authentications[$repositoryName])) {
|
||||||
|
return $this->authentications[$repositoryName];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('username' => null, 'password' => null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function setAuthentication($repositoryName, $username, $password = null)
|
||||||
|
{
|
||||||
|
$this->authentications[$repositoryName] = array('username' => $username, 'password' => $password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function loadConfiguration(Config $config)
|
||||||
|
{
|
||||||
|
// reload oauth token from config if available
|
||||||
|
if ($tokens = $config->get('github-oauth')) {
|
||||||
|
foreach ($tokens as $domain => $token) {
|
||||||
|
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
||||||
|
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
||||||
|
}
|
||||||
|
$io->setAuthentication($domain, $token, 'x-oauth-basic');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,12 +22,11 @@ use Symfony\Component\Console\Helper\HelperSet;
|
||||||
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
* @author François Pluchino <francois.pluchino@opendisplay.com>
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class ConsoleIO implements IOInterface
|
class ConsoleIO extends BaseIO
|
||||||
{
|
{
|
||||||
protected $input;
|
protected $input;
|
||||||
protected $output;
|
protected $output;
|
||||||
protected $helperSet;
|
protected $helperSet;
|
||||||
protected $authentications = array();
|
|
||||||
protected $lastMessage;
|
protected $lastMessage;
|
||||||
private $startTime;
|
private $startTime;
|
||||||
|
|
||||||
|
@ -225,40 +224,4 @@ class ConsoleIO implements IOInterface
|
||||||
// not able to hide the answer, proceed with normal question handling
|
// not able to hide the answer, proceed with normal question handling
|
||||||
return $this->ask($question);
|
return $this->ask($question);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAuthentications()
|
|
||||||
{
|
|
||||||
return $this->authentications;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function hasAuthentication($repositoryName)
|
|
||||||
{
|
|
||||||
$auths = $this->getAuthentications();
|
|
||||||
|
|
||||||
return isset($auths[$repositoryName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAuthentication($repositoryName)
|
|
||||||
{
|
|
||||||
$auths = $this->getAuthentications();
|
|
||||||
|
|
||||||
return isset($auths[$repositoryName]) ? $auths[$repositoryName] : array('username' => null, 'password' => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function setAuthentication($repositoryName, $username, $password = null)
|
|
||||||
{
|
|
||||||
$this->authentications[$repositoryName] = array('username' => $username, 'password' => $password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
namespace Composer\IO;
|
namespace Composer\IO;
|
||||||
|
|
||||||
|
use Composer\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Input/Output helper interface.
|
* The Input/Output helper interface.
|
||||||
*
|
*
|
||||||
|
@ -155,4 +157,11 @@ interface IOInterface
|
||||||
* @param string $password The password
|
* @param string $password The password
|
||||||
*/
|
*/
|
||||||
public function setAuthentication($repositoryName, $username, $password = null);
|
public function setAuthentication($repositoryName, $username, $password = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads authentications from a config instance
|
||||||
|
*
|
||||||
|
* @param Config $config
|
||||||
|
*/
|
||||||
|
public function loadConfiguration(Config $config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Composer\IO;
|
||||||
*
|
*
|
||||||
* @author Christophe Coevoet <stof@notk.org>
|
* @author Christophe Coevoet <stof@notk.org>
|
||||||
*/
|
*/
|
||||||
class NullIO implements IOInterface
|
class NullIO extends BaseIO
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -104,35 +104,4 @@ class NullIO implements IOInterface
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAuthentications()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function hasAuthentication($repositoryName)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function getAuthentication($repositoryName)
|
|
||||||
{
|
|
||||||
return array('username' => null, 'password' => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public function setAuthentication($repositoryName, $username, $password = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue