Skip to content

Commit

Permalink
Merge pull request composer#4670 from mishak87/patch-1
Browse files Browse the repository at this point in the history
Configuration of gitlab-oauth via CLI followup
  • Loading branch information
alcohol committed Dec 3, 2015
2 parents dc5f8cf + ce74477 commit ee8871b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
12 changes: 12 additions & 0 deletions res/composer-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
"description": "A hash of domain name => github API oauth tokens, typically {\"github.com\":\"<token>\"}.",
"additionalProperties": true
},
"gitlab-oauth": {
"type": "object",
"description": "A hash of domain name => gitlab API oauth tokens, typically {\"gitlab.com\":\"<token>\"}.",
"additionalProperties": true
},
"http-basic": {
"type": "object",
"description": "A hash of domain name => {\"username\": \"...\", \"password\": \"...\"}.",
Expand Down Expand Up @@ -221,6 +226,13 @@
"type": "boolean",
"description": "Defaults to true. If set to false, the OAuth tokens created to access the github API will have a date instead of the machine hostname."
},
"gitlab-domains": {
"type": "array",
"description": "A list of domains to use in gitlab mode. This is used for custom GitLab setups, defaults to [\"gitlab.com\"].",
"items": {
"type": "string"
}
},
"archive-format": {
"type": "string",
"description": "The default archiving format when not provided on cli, defaults to \"tar\"."
Expand Down
18 changes: 15 additions & 3 deletions src/Composer/Command/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
}
if ($input->getOption('global') && !$this->authConfigFile->exists()) {
touch($this->authConfigFile->getPath());
$this->authConfigFile->write(array('http-basic' => new \ArrayObject, 'github-oauth' => new \ArrayObject));
$this->authConfigFile->write(array('http-basic' => new \ArrayObject, 'github-oauth' => new \ArrayObject, 'gitlab-oauth' => new \ArrayObject));
@chmod($this->authConfigFile->getPath(), 0600);
}

Expand Down Expand Up @@ -358,6 +358,18 @@ function ($vals) {
return $vals;
},
),
'gitlab-domains' => array(
function ($vals) {
if (!is_array($vals)) {
return 'array expected';
}

return true;
},
function ($vals) {
return $vals;
},
),
);

foreach ($uniqueConfigValues as $name => $callbacks) {
Expand Down Expand Up @@ -433,15 +445,15 @@ function ($vals) {
}

// handle github-oauth
if (preg_match('/^(github-oauth|http-basic)\.(.+)/', $settingKey, $matches)) {
if (preg_match('/^(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]);

return;
}

if ($matches[1] === 'github-oauth') {
if ($matches[1] === 'github-oauth' || $matches[1] === 'gitlab-oauth') {
if (1 !== count($values)) {
throw new \RuntimeException('Too many arguments, expected only one token');
}
Expand Down
3 changes: 2 additions & 1 deletion src/Composer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Config
'archive-dir' => '.',
// valid keys without defaults (auth config stuff):
// github-oauth
// gitlab-oauth
// http-basic
);

Expand Down Expand Up @@ -111,7 +112,7 @@ public function merge($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', 'http-basic')) && isset($this->config[$key])) {
if (in_array($key, array('github-oauth', 'gitlab-oauth', 'http-basic')) && isset($this->config[$key])) {
$this->config[$key] = array_merge($this->config[$key], $val);
} else {
$this->config[$key] = $val;
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Config/JsonConfigSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function removeRepository($name)
public function addConfigSetting($name, $value)
{
$this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) {
if (preg_match('{^(gitlab-oauth|github-oauth|http-basic|platform)\.}', $key)) {
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
list($key, $host) = explode('.', $key, 2);
if ($this->authConfig) {
$config[$key][$host] = $val;
Expand All @@ -98,7 +98,7 @@ public function addConfigSetting($name, $value)
public function removeConfigSetting($name)
{
$this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) {
if (preg_match('{^(gitlab-oauth|github-oauth|http-basic|platform)\.}', $key)) {
if (preg_match('{^(github-oauth|gitlab-oauth|http-basic|platform)\.}', $key)) {
list($key, $host) = explode('.', $key, 2);
if ($this->authConfig) {
unset($config[$key][$host]);
Expand Down

0 comments on commit ee8871b

Please sign in to comment.