fix config add/remove/unset/merge for bitbucket
parent
40c14709f7
commit
cf43244f85
|
@ -167,7 +167,7 @@ EOT
|
|||
}
|
||||
if ($input->getOption('global') && !$this->authConfigFile->exists()) {
|
||||
touch($this->authConfigFile->getPath());
|
||||
$this->authConfigFile->write(array('http-basic' => new \ArrayObject, 'github-oauth' => new \ArrayObject, 'gitlab-oauth' => new \ArrayObject));
|
||||
$this->authConfigFile->write(array('bitbucket-oauth' => new \ArrayObject, 'github-oauth' => new \ArrayObject, 'gitlab-oauth' => new \ArrayObject, 'http-basic' => new \ArrayObject));
|
||||
Silencer::call('chmod', $this->authConfigFile->getPath(), 0600);
|
||||
}
|
||||
|
||||
|
@ -465,8 +465,8 @@ EOT
|
|||
return $this->configSource->addConfigSetting($settingKey, $values[0]);
|
||||
}
|
||||
|
||||
// handle github-oauth
|
||||
if (preg_match('/^(github-oauth|gitlab-oauth|http-basic)\.(.+)/', $settingKey, $matches)) {
|
||||
// handle auth
|
||||
if (preg_match('/^(bitbucket-oauth|github-oauth|gitlab-oauth|http-basic)\.(.+)/', $settingKey, $matches)) {
|
||||
if ($input->getOption('unset')) {
|
||||
$this->authConfigSource->removeConfigSetting($matches[1].'.'.$matches[2]);
|
||||
$this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
|
||||
|
@ -474,7 +474,13 @@ EOT
|
|||
return;
|
||||
}
|
||||
|
||||
if ($matches[1] === 'github-oauth' || $matches[1] === 'gitlab-oauth') {
|
||||
if ($matches[1] === 'bitbucket-oauth') {
|
||||
if (2 !== count($values)) {
|
||||
throw new \RuntimeException('Expected two arguments (consumer-key, consumer-secret), got '.count($values));
|
||||
}
|
||||
$this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
|
||||
$this->authConfigSource->addConfigSetting($matches[1].'.'.$matches[2], array('consumer-key' => $values[0], 'consumer-secret' => $values[1]));
|
||||
} elseif ($matches[1] === 'github-oauth' || $matches[1] === 'gitlab-oauth') {
|
||||
if (1 !== count($values)) {
|
||||
throw new \RuntimeException('Too many arguments, expected only one token');
|
||||
}
|
||||
|
@ -491,17 +497,6 @@ EOT
|
|||
return;
|
||||
}
|
||||
|
||||
// handle bitbucket-oauth
|
||||
if (preg_match('/^(bitbucket-oauth)\.(.+)/', $settingKey, $matches)) {
|
||||
if (2 !== count($values)) {
|
||||
throw new \RuntimeException('Expected two arguments (consumer-key, consumer-secret), got '.count($values));
|
||||
}
|
||||
$this->configSource->removeConfigSetting($matches[1].'.'.$matches[2]);
|
||||
$this->authConfigSource->addConfigSetting($matches[1].'.'.$matches[2], array('consumer-key' => $values[0], 'consumer-secret' => $values[1]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Setting '.$settingKey.' does not exist or is not supported by this command');
|
||||
}
|
||||
|
||||
|
|
|
@ -58,10 +58,10 @@ class Config
|
|||
'archive-format' => 'tar',
|
||||
'archive-dir' => '.',
|
||||
// valid keys without defaults (auth config stuff):
|
||||
// bitbucket-oauth
|
||||
// github-oauth
|
||||
// gitlab-oauth
|
||||
// http-basic
|
||||
// bitbucket-oauth
|
||||
);
|
||||
|
||||
public static $defaultRepositories = array(
|
||||
|
@ -121,7 +121,7 @@ class Config
|
|||
// override defaults with given config
|
||||
if (!empty($config['config']) && is_array($config['config'])) {
|
||||
foreach ($config['config'] as $key => $val) {
|
||||
if (in_array($key, array('github-oauth', 'gitlab-oauth', 'http-basic')) && isset($this->config[$key])) {
|
||||
if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'http-basic')) && isset($this->config[$key])) {
|
||||
$this->config[$key] = array_merge($this->config[$key], $val);
|
||||
} elseif ('preferred-install' === $key && isset($this->config[$key])) {
|
||||
if (is_array($val) || is_array($this->config[$key])) {
|
||||
|
|
|
@ -81,7 +81,7 @@ class JsonConfigSource implements ConfigSourceInterface
|
|||
{
|
||||
$authConfig = $this->authConfig;
|
||||
$this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) use ($authConfig) {
|
||||
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform|bitbucket-oauth)\.}', $key)) {
|
||||
if (preg_match('{^(bitbucket-oauth|github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
|
||||
list($key, $host) = explode('.', $key, 2);
|
||||
if ($authConfig) {
|
||||
$config[$key][$host] = $val;
|
||||
|
@ -101,7 +101,7 @@ class JsonConfigSource implements ConfigSourceInterface
|
|||
{
|
||||
$authConfig = $this->authConfig;
|
||||
$this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) use ($authConfig) {
|
||||
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
|
||||
if (preg_match('{^(bitbucket-oauth|github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
|
||||
list($key, $host) = explode('.', $key, 2);
|
||||
if ($authConfig) {
|
||||
unset($config[$key][$host]);
|
||||
|
|
|
@ -85,12 +85,17 @@ abstract class BaseIO implements IOInterface
|
|||
*/
|
||||
public function loadConfiguration(Config $config)
|
||||
{
|
||||
$bitbucketOauth = $config->get('bitbucket-oauth') ?: array();
|
||||
$githubOauth = $config->get('github-oauth') ?: array();
|
||||
$gitlabOauth = $config->get('gitlab-oauth') ?: array();
|
||||
$httpBasic = $config->get('http-basic') ?: array();
|
||||
$bitbucketOauth = $config->get('bitbucket-oauth') ?: array();
|
||||
|
||||
// reload oauth token from config if available
|
||||
// reload oauth tokens from config if available
|
||||
|
||||
foreach ($bitbucketOauth as $domain => $cred) {
|
||||
$this->checkAndSetAuthentication($domain, $cred['consumer-key'], $cred['consumer-secret']);
|
||||
}
|
||||
|
||||
foreach ($githubOauth as $domain => $token) {
|
||||
if (!preg_match('{^[a-z0-9]+$}', $token)) {
|
||||
throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
|
||||
|
@ -107,10 +112,6 @@ abstract class BaseIO implements IOInterface
|
|||
$this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
|
||||
}
|
||||
|
||||
foreach ($bitbucketOauth as $domain => $cred) {
|
||||
$this->checkAndSetAuthentication($domain, $cred['consumer-key'], $cred['consumer-secret']);
|
||||
}
|
||||
|
||||
// setup process timeout
|
||||
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue