Skip to content

Commit

Permalink
MAGECLOUD-1906: Validate configurations used by ece-tools for deploym…
Browse files Browse the repository at this point in the history
…ent (#250)
  • Loading branch information
oshmyheliuk authored and Bohdan Korablov committed May 21, 2018
1 parent 5edb76e commit b2fc6df
Show file tree
Hide file tree
Showing 31 changed files with 2,188 additions and 481 deletions.
6 changes: 4 additions & 2 deletions src/App/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ function () {
'validators' => [
ValidatorInterface::LEVEL_CRITICAL => [
$this->container->make(ConfigValidator\Build\StageConfig::class),
$this->container->make(ConfigValidator\Build\BuildOptionsIni::class),
],
ValidatorInterface::LEVEL_WARNING => [
$this->container->make(ConfigValidator\Build\ConfigFileExists::class),
$this->container->make(ConfigValidator\Build\ConfigFileStructure::class),
$this->container->make(ConfigValidator\Build\DeprecatedBuildOptionsIni::class),
$this->container->make(ConfigValidator\Build\ModulesExists::class),
],
],
Expand Down Expand Up @@ -198,8 +200,8 @@ function () {
'validators' => [
ValidatorInterface::LEVEL_CRITICAL => [
$this->container->make(ConfigValidator\Deploy\AdminEmail::class),
$this->container->make(ConfigValidator\Build\StageConfig::class),
$this->container->make(ConfigValidator\Deploy\Variables::class),
$this->container->make(ConfigValidator\Deploy\RawEnvVariable::class),
$this->container->make(ConfigValidator\Deploy\MagentoCloudVariables::class),
$this->container->make(ConfigValidator\Deploy\AdminCredentials::class),
],
ValidatorInterface::LEVEL_WARNING => [
Expand Down
1 change: 0 additions & 1 deletion src/Config/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function __construct(
* returns false if not found
*
* @param string $key
* @param string|int|null $default
* @return array|string|int|null
*/
public function getEnv(string $key)
Expand Down
28 changes: 10 additions & 18 deletions src/Config/GlobalSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ class GlobalSection implements StageConfigInterface
*/
private $mergedConfig;

/**
* @var Schema
*/
private $schema;

/**
* @param EnvironmentReader $environmentReader
* @param Schema $schema
*/
public function __construct(EnvironmentReader $environmentReader)
public function __construct(EnvironmentReader $environmentReader, Schema $schema)
{
$this->environmentReader = $environmentReader;
$this->schema = $schema;
}

/**
* @inheritdoc
*/
public function get(string $name)
{
if (!array_key_exists($name, $this->getDefault())) {
if (!array_key_exists($name, $this->schema->getDefaults(StageConfigInterface::STAGE_GLOBAL))) {
throw new \RuntimeException(sprintf(
'Config %s was not defined.',
$name
Expand Down Expand Up @@ -66,26 +73,11 @@ private function mergeConfig(): array
$envConfig = $this->environmentReader->read()[self::SECTION_STAGE] ?? [];

$this->mergedConfig = array_replace(
$this->getDefault(),
$this->schema->getDefaults(StageConfigInterface::STAGE_GLOBAL),
$envConfig[self::STAGE_GLOBAL] ?? []
);
}

return $this->mergedConfig;
}

/**
* Resolves default configuration value if other was not provided.
*
* @return array
*/
private function getDefault(): array
{
return [
self::VAR_SCD_ON_DEMAND => false,
self::VAR_SKIP_HTML_MINIFICATION => false,
self::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT => false,
self::VAR_DEPLOY_FROM_GIT_OPTIONS => [],
];
}
}
Loading

0 comments on commit b2fc6df

Please sign in to comment.