Skip to content

Commit 7fe3459

Browse files
committed
Update config migration to handle oauth2 settings
1 parent baf07ed commit 7fe3459

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/Console/Commands/MigrateConfig.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ public function handle()
115115
include $cdash_app_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
116116
include $cdash_app_dir . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'version.php';
117117
foreach (get_defined_vars() as $key => $value) {
118+
119+
if ($key == 'OAUTH2_PROVIDERS') {
120+
foreach ($value as $k => $v) {
121+
$provider = strtoupper($k);
122+
if (array_key_exists('clientId', $v)) {
123+
$config["{$provider}_CLIENT_ID"] = $v['clientId'];
124+
}
125+
if (array_key_exists('clientSecret', $v)) {
126+
$config["{$provider}_CLIENT_SECRET"] = $v['clientSecret'];
127+
}
128+
if (array_key_exists('domain', $v)) {
129+
$config["{$provider}_DOMAIN"] = $v['domain'];
130+
}
131+
}
132+
}
133+
118134
if (strpos($key, 'CDASH_') !== 0) {
119135
continue;
120136
}
@@ -154,7 +170,6 @@ public function handle()
154170
}
155171

156172
/* still TODO for special handling:
157-
* oauth2 stuff
158173
* associative arrays that will need code-level changes:
159174
MEMCACHE_SERVER, GOOGLE_MAP_API_KEY
160175
*/

tests/Feature/MigrateConfigCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ public function testMigrateConfigCommand()
3838
$CDASH_BASE_URL = 'http://localhost/CDash';
3939
$CDASH_LOG_LEVEL = LOG_DEBUG;
4040
$CDASH_UNLIMITED_PROJECTS = ['Project1', 'Project2'];
41+
$OAUTH2_PROVIDERS['GitHub'] = [
42+
'clientId' => 'github_client_id',
43+
'clientSecret' => 'github_client_secret'
44+
];
45+
$OAUTH2_PROVIDERS['GitLab'] = [
46+
'clientId' => 'gitlab_client_id',
47+
'clientSecret' => 'gitlab_client_secret',
48+
'domain' => 'https://gitlab.kitware.com'
49+
];
50+
$OAUTH2_PROVIDERS['Google'] = [
51+
'clientId' => 'google_client_id',
52+
'clientSecret' => 'google_client_secret'
53+
];
4154
EOT;
4255
file_put_contents($this->config_file, $config_contents);
4356

@@ -64,6 +77,12 @@ public function testMigrateConfigCommand()
6477
$this->assertContains('APP_TIMEZONE=America/New_York', $actual);
6578
$this->assertContains('APP_LOG_LEVEL=debug', $actual);
6679
$this->assertContains('UNLIMITED_PROJECTS=["Project1","Project2"]', $actual);
80+
$this->assertContains('GITHUB_CLIENT_SECRET=github_client_secret', $actual);
81+
$this->assertContains('GITLAB_CLIENT_ID=gitlab_client_id', $actual);
82+
$this->assertContains('GITLAB_CLIENT_SECRET=gitlab_client_secret', $actual);
83+
$this->assertContains('GITLAB_DOMAIN=https://gitlab.kitware.com', $actual);
84+
$this->assertContains('GOOGLE_CLIENT_ID=google_client_id', $actual);
85+
$this->assertContains('GOOGLE_CLIENT_SECRET=google_client_secret', $actual);
6786

6887
// Default value (mysql) does not get written to .env.
6988
$this->assertNotContains('DB_CONNECTION=', $actual);

0 commit comments

Comments
 (0)