Skip to content

Commit

Permalink
Merge pull request #1052 from Kitware/oauth2_config_migrate
Browse files Browse the repository at this point in the history
Update config migration to handle oauth2 settings
  • Loading branch information
zackgalbreath authored Aug 25, 2020
2 parents baf07ed + 7fe3459 commit fc1fa33
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/Console/Commands/MigrateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ public function handle()
include $cdash_app_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
include $cdash_app_dir . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'version.php';
foreach (get_defined_vars() as $key => $value) {

if ($key == 'OAUTH2_PROVIDERS') {
foreach ($value as $k => $v) {
$provider = strtoupper($k);
if (array_key_exists('clientId', $v)) {
$config["{$provider}_CLIENT_ID"] = $v['clientId'];
}
if (array_key_exists('clientSecret', $v)) {
$config["{$provider}_CLIENT_SECRET"] = $v['clientSecret'];
}
if (array_key_exists('domain', $v)) {
$config["{$provider}_DOMAIN"] = $v['domain'];
}
}
}

if (strpos($key, 'CDASH_') !== 0) {
continue;
}
Expand Down Expand Up @@ -154,7 +170,6 @@ public function handle()
}

/* still TODO for special handling:
* oauth2 stuff
* associative arrays that will need code-level changes:
MEMCACHE_SERVER, GOOGLE_MAP_API_KEY
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/MigrateConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public function testMigrateConfigCommand()
$CDASH_BASE_URL = 'http://localhost/CDash';
$CDASH_LOG_LEVEL = LOG_DEBUG;
$CDASH_UNLIMITED_PROJECTS = ['Project1', 'Project2'];
$OAUTH2_PROVIDERS['GitHub'] = [
'clientId' => 'github_client_id',
'clientSecret' => 'github_client_secret'
];
$OAUTH2_PROVIDERS['GitLab'] = [
'clientId' => 'gitlab_client_id',
'clientSecret' => 'gitlab_client_secret',
'domain' => 'https://gitlab.kitware.com'
];
$OAUTH2_PROVIDERS['Google'] = [
'clientId' => 'google_client_id',
'clientSecret' => 'google_client_secret'
];
EOT;
file_put_contents($this->config_file, $config_contents);

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

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

0 comments on commit fc1fa33

Please sign in to comment.