Skip to content

Commit

Permalink
fix: fix markers population in generis.conf (#3860)
Browse files Browse the repository at this point in the history
* fix: fix markers population in generis.conf

* codestyle fix

* Review changes

* fix: notification and review fixes

* fix: ci fixes

* Update getConfigurationMarkers as non static

Co-authored-by: Héctor Arroyo <[email protected]>
Signed-off-by: Kiril Hatalski <[email protected]>

---------

Signed-off-by: Kiril Hatalski <[email protected]>
Co-authored-by: Kirill-Hatalski <[email protected]>
Co-authored-by: Héctor Arroyo <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2023
1 parent 53dda88 commit ca6d4a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
16 changes: 12 additions & 4 deletions install/class.Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public function __invoke($params)
}

$global = $parameters['configuration']['global'];

$markers = $this->getConfigurationMarkers();

$global = $markers->replaceMarkers($global);
$options['module_namespace'] = $global['namespace'];
$options['instance_name'] = $global['instance_name'];
$options['module_url'] = $global['url'];
Expand Down Expand Up @@ -228,10 +232,6 @@ public function __invoke($params)
}

//@TODO use $serviceManager->getContainer(ConfigurationMarkers::class) after refactoring taoSetup to use full DI
$markers = new ConfigurationMarkers(
new SerializableSecretDtoFactory(),
$this->getLogger()
);
$parameters = $markers->replaceMarkers($parameters);

foreach ($parameters['configuration'] as $extension => $configs) {
Expand Down Expand Up @@ -452,4 +452,12 @@ private function isMasterSlaveConnection(array $defaultPersistenceConfig): bool
true
);
}

private function getConfigurationMarkers(): ConfigurationMarkers
{
return new ConfigurationMarkers(
new SerializableSecretDtoFactory(),
$this->getLogger()
);
}
}
4 changes: 2 additions & 2 deletions install/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

require_once($root . 'vendor/autoload.php');

new DotEnvReader();

if (tao_install_utils_System::isTAOInstalled()) {
require_once($root . 'config/generis.conf.php');
}

new DotEnvReader();

// Logger service initialization.
$loggerService = new \oat\oatbox\log\LoggerService();
$loggerService->addLogger(
Expand Down
6 changes: 6 additions & 0 deletions install/utils/class.ConfigWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
*/

use oat\tao\model\configurationMarkers\Secrets\SerializableSecretDto;

/**
* The ConfigWriter class enables you to create config file from samples
* and to write the constants inside.
Expand Down Expand Up @@ -123,6 +125,10 @@ public function writeConstants(array $constants)
$content = preg_replace('/(\'' . $name . '\')(.*?)$/ms', '$1, ' . $val . ');', $content);
} elseif (is_numeric($val)) {
$content = preg_replace('/(\'' . $name . '\')(.*?)$/ms', '$1, ' . $val . ');', $content);
} elseif ($val instanceof SerializableSecretDto) {
// Operating with .env values
$content = preg_replace('/(\'' . $name . '\')(.*?)$/ms', '$1, '
. $val->__toPhpCode() . ');', $content);
}
}
file_put_contents($this->file, $content);
Expand Down
5 changes: 5 additions & 0 deletions models/classes/configurationMarkers/ConfigurationMarkers.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ConfigurationMarkers
private SerializableSecretDtoFactory $serializableFactory;
private Report $report;
private array $envVars;
private array $matchedVars = [];

public function __construct(
SerializableSecretDtoFactory $serializableFactory,
Expand Down Expand Up @@ -126,6 +127,10 @@ private function findMatches(string $item): array

private function printMatchNotification(bool $isSecretDefined, string $secretName): void
{
if (in_array($secretName, $this->matchedVars)) {
return;
}
array_push($this->matchedVars, $secretName);
$message = sprintf('Found seed file marker: %s', $secretName);
if ($isSecretDefined) {
$message .= ' and its Secrets Storage value.';
Expand Down

0 comments on commit ca6d4a3

Please sign in to comment.