mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Updated ApplicationConfigCustomizer to support new keys in the future
This commit is contained in:
parent
3a75ac0486
commit
757cf2e193
@ -6,28 +6,54 @@ namespace Shlinkio\Shlink\Installer\Config\Plugin;
|
|||||||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
||||||
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
|
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use function array_diff;
|
||||||
|
use function array_keys;
|
||||||
|
|
||||||
class ApplicationConfigCustomizer implements ConfigCustomizerInterface
|
class ApplicationConfigCustomizer implements ConfigCustomizerInterface
|
||||||
{
|
{
|
||||||
use StringUtilsTrait;
|
use StringUtilsTrait;
|
||||||
|
|
||||||
|
private const SECRET = 'SECRET';
|
||||||
|
private const DISABLE_TRACK_PARAM = 'DISABLE_TRACK_PARAM';
|
||||||
|
private const EXPECTED_KEYS = [
|
||||||
|
self::SECRET,
|
||||||
|
self::DISABLE_TRACK_PARAM,
|
||||||
|
];
|
||||||
|
|
||||||
public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void
|
public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void
|
||||||
{
|
{
|
||||||
$io->title('APPLICATION');
|
$io->title('APPLICATION');
|
||||||
|
|
||||||
if ($appConfig->hasApp() && $io->confirm('Do you want to keep imported application config?')) {
|
$app = $appConfig->getApp();
|
||||||
|
$keysToAskFor = $appConfig->hasApp() && $io->confirm('Do you want to keep imported application config?')
|
||||||
|
? array_diff(self::EXPECTED_KEYS, array_keys($app))
|
||||||
|
: self::EXPECTED_KEYS;
|
||||||
|
|
||||||
|
if (empty($keysToAskFor)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$appConfig->setApp([
|
foreach ($keysToAskFor as $key) {
|
||||||
'SECRET' => $io->ask(
|
$app[$key] = $this->ask($io, $key);
|
||||||
|
}
|
||||||
|
$appConfig->setApp($app);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ask(SymfonyStyle $io, string $key)
|
||||||
|
{
|
||||||
|
switch ($key) {
|
||||||
|
case self::SECRET:
|
||||||
|
return $io->ask(
|
||||||
'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one) '
|
'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one) '
|
||||||
. '<fg=red>[DEPRECATED. TO BE REMOVED]</>'
|
. '<fg=red>[DEPRECATED. TO BE REMOVED]</>'
|
||||||
) ?: $this->generateRandomString(32),
|
) ?: $this->generateRandomString(32);
|
||||||
'DISABLE_TRACK_PARAM' => $io->ask(
|
case self::DISABLE_TRACK_PARAM:
|
||||||
|
return $io->ask(
|
||||||
'Provide a parameter name that you will be able to use to disable tracking on specific request to '
|
'Provide a parameter name that you will be able to use to disable tracking on specific request to '
|
||||||
. 'short URLs (leave empty and this feature won\'t be enabled)'
|
. 'short URLs (leave empty and this feature won\'t be enabled)'
|
||||||
),
|
);
|
||||||
]);
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use Shlinkio\Shlink\Installer\Util\AskUtilsTrait;
|
|||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Filesystem\Exception\IOException;
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use function array_keys;
|
||||||
|
|
||||||
class DatabaseConfigCustomizer implements ConfigCustomizerInterface
|
class DatabaseConfigCustomizer implements ConfigCustomizerInterface
|
||||||
{
|
{
|
||||||
@ -55,7 +56,7 @@ class DatabaseConfigCustomizer implements ConfigCustomizerInterface
|
|||||||
|
|
||||||
// Select database type
|
// Select database type
|
||||||
$params = [];
|
$params = [];
|
||||||
$databases = \array_keys(self::DATABASE_DRIVERS);
|
$databases = array_keys(self::DATABASE_DRIVERS);
|
||||||
$dbType = $io->choice('Select database type', $databases, $databases[0]);
|
$dbType = $io->choice('Select database type', $databases, $databases[0]);
|
||||||
$params['DRIVER'] = self::DATABASE_DRIVERS[$dbType];
|
$params['DRIVER'] = self::DATABASE_DRIVERS[$dbType];
|
||||||
|
|
||||||
|
@ -114,6 +114,7 @@ final class CustomizableAppConfig implements ArraySerializableInterface
|
|||||||
{
|
{
|
||||||
$this->setApp([
|
$this->setApp([
|
||||||
'SECRET' => $array['app_options']['secret_key'] ?? null,
|
'SECRET' => $array['app_options']['secret_key'] ?? null,
|
||||||
|
'DISABLE_TRACK_PARAM' => $array['app_options']['disable_track_param'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->deserializeDatabase($array['entity_manager']['connection'] ?? []);
|
$this->deserializeDatabase($array['entity_manager']['connection'] ?? []);
|
||||||
|
@ -79,12 +79,14 @@ class ApplicationConfigCustomizerTest extends TestCase
|
|||||||
$config = new CustomizableAppConfig();
|
$config = new CustomizableAppConfig();
|
||||||
$config->setApp([
|
$config->setApp([
|
||||||
'SECRET' => 'foo',
|
'SECRET' => 'foo',
|
||||||
|
'DISABLE_TRACK_PARAM' => 'the_new_secret',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->plugin->process($this->io->reveal(), $config);
|
$this->plugin->process($this->io->reveal(), $config);
|
||||||
|
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'SECRET' => 'foo',
|
'SECRET' => 'foo',
|
||||||
|
'DISABLE_TRACK_PARAM' => 'the_new_secret',
|
||||||
], $config->getApp());
|
], $config->getApp());
|
||||||
$confirm->shouldHaveBeenCalledTimes(1);
|
$confirm->shouldHaveBeenCalledTimes(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user