Skip to content

Commit

Permalink
SC-18436: Adjusted zone generation to 4-level for internal endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yuklia committed Feb 1, 2024
1 parent eaf37e9 commit cd9a09b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 88 deletions.
1 change: 0 additions & 1 deletion bin/command/install/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Registry::Help::command -s -c "bootstrap | boot" -a "[-v] <project-yml-file>" "P
Registry::Help::command -s -c "bootstrap | boot" -a "[-v]" "Prepares all the files to run the application based on ${HELP_HIGH}deploy.local.yml${HELP_DESC} or ${HELP_HIGH}deploy.yml${HELP_DESC}."

function Command::bootstrap() {

while getopts ":vsx" opt; do
case ${opt} in
v)
Expand Down
178 changes: 91 additions & 87 deletions generator/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,105 +341,109 @@ static function ($endpoint) use ($projectData) {
];
}

foreach ($applicationData['endpoints'] ?? [] as $endpoint => $endpointData) {
if (isset($applicationData['endpoints']) && is_array($applicationData['endpoints'])) {
foreach ($applicationData['endpoints'] ?? [] as $endpoint => $endpointData) {
$internal = isset($endpointData['internal']) && $endpointData['internal'] === true;
$host = strtok($endpoint, ':');
$zone = $internal ? getFrontendZoneByDomainLevel($host, 4) : getFrontendZoneByDomainLevel($host, 2);

$host = strtok($endpoint, ':');
$frontend[$host] = [
'zone' => getFrontendZoneByDomainLevel($host),
'type' => $applicationName,
'internal' => (bool)($endpointData['internal'] ?? false),
];
$frontend[$host] = [
'zone' => $zone,
'type' => $applicationName,
'internal' => $internal,
];

$authEngine = $endpointData['auth']['engine'] ?? 'none';
if ($authEngine === 'basic') {
$authEngine = $endpointData['auth']['engine'] ?? 'none';
if ($authEngine === 'basic') {

if (!is_array($endpointData['auth']['users'])) {
throw new Exception('Basic auth demands user list to be applied.');
}
if (!is_array($endpointData['auth']['users'])) {
throw new Exception('Basic auth demands user list to be applied.');
}

$authFolder = $deploymentDir . DS . 'context' . DS . 'nginx' . DS . 'auth';
$authFolder = $deploymentDir . DS . 'context' . DS . 'nginx' . DS . 'auth';

file_put_contents(
$authFolder . DS . $host . '.htpasswd',
generatePasswords($endpointData['auth']['users']),
FILE_APPEND
);
}
file_put_contents(
$authFolder . DS . $host . '.htpasswd',
generatePasswords($endpointData['auth']['users']),
FILE_APPEND
);
}

$services = [];
$isEndpointDataHasStore = array_key_exists('store', $endpointData);
$isEndpointDataHasRegion = array_key_exists('region', $endpointData);
$currentRegion = array_key_exists('region', $endpointData)
? $endpointData['region']
: $groupData['region'];

if ($isEndpointDataHasStore) {
$services = array_replace_recursive(
$projectData['regions'][$groupData['region']]['stores'][$endpointData['store']]['services'] ?? [],
$endpointData['services'] ?? []
);
}
$services = [];
$isEndpointDataHasStore = array_key_exists('store', $endpointData);
$isEndpointDataHasRegion = array_key_exists('region', $endpointData);
$currentRegion = array_key_exists('region', $endpointData)
? $endpointData['region']
: $groupData['region'];

if ($isEndpointDataHasStore) {
$services = array_replace_recursive(
$projectData['regions'][$groupData['region']]['stores'][$endpointData['store']]['services'] ?? [],
$endpointData['services'] ?? []
);
}

if ($isEndpointDataHasRegion) {
$services = array_replace_recursive(
$projectData['regions'][$currentRegion]['services'] ?? [],
$endpointData['services'] ?? []
);
}
if ($isEndpointDataHasRegion) {
$services = array_replace_recursive(
$projectData['regions'][$currentRegion]['services'] ?? [],
$endpointData['services'] ?? []
);
}

$projectData['_testing']['dynamicStoreMode'] = $projectData['dynamicStoreMode'] ?? false;
$projectData['_testing']['dynamicStoreMode'] = $projectData['dynamicStoreMode'] ?? false;

if ($isEndpointDataHasStore && $endpointData['store'] === ($projectData['docker']['testing']['store'] ?? '')) {
$projectData['_testing']['storeName'] = $endpointData['store'];
$projectData['_testing']['identifier'] = $endpointData['identifier'];
$projectData['_testing']['regionServices'] = array_merge($projectData['_testing']['services'] ?? [], $services);
$projectData['_testing']['services'][$endpointData['store']][$applicationData['application']] = $services;
}
if ($isEndpointDataHasStore && $endpointData['store'] === ($projectData['docker']['testing']['store'] ?? '')) {
$projectData['_testing']['storeName'] = $endpointData['store'];
$projectData['_testing']['identifier'] = $endpointData['identifier'];
$projectData['_testing']['regionServices'] = array_merge($projectData['_testing']['services'] ?? [], $services);
$projectData['_testing']['services'][$endpointData['store']][$applicationData['application']] = $services;
}

if ($isEndpointDataHasRegion && $groupData['region'] === ($projectData['docker']['testing']['region'] ?? '')) {
$projectData['_testing']['regionName'] = $groupData['region'];
$projectData['_testing']['identifier'] = $endpointData['identifier'];
$projectData['_testing']['regionServices'] = array_merge($projectData['_testing']['services'] ?? [], $services);
$projectData['_testing']['services'][$currentRegion][$applicationData['application']] = $services;
}
if ($isEndpointDataHasRegion && $groupData['region'] === ($projectData['docker']['testing']['region'] ?? '')) {
$projectData['_testing']['regionName'] = $groupData['region'];
$projectData['_testing']['identifier'] = $endpointData['identifier'];
$projectData['_testing']['regionServices'] = array_merge($projectData['_testing']['services'] ?? [], $services);
$projectData['_testing']['services'][$currentRegion][$applicationData['application']] = $services;
}

$envVarEncoder->setIsActive(true);

if ($isEndpointDataHasStore || $isEndpointDataHasRegion) {
file_put_contents(
$deploymentDir . DS . 'env' . DS . 'cli' . DS . strtolower($endpointData['identifier']) . '.env',
$twig->render('env/cli/store.env.twig', [
'applicationName' => $applicationName,
'applicationData' => $applicationData,
'project' => $projectData,
'regionName' => $currentRegion,
'regionData' => $projectData['regions'][$currentRegion],
'brokerConnections' => getBrokerConnections($projectData),
'storeName' => $endpointData['store'] ?? '',
'services' => $services,
'endpointMap' => $endpointMap,
'identifier' => $endpointData['identifier'],
])
);

file_put_contents(
$deploymentDir . DS . 'terraform' . DS . 'cli' . DS . strtolower($endpointData['identifier']) . '.env',
$twig->render('terraform/store.env.twig', [
'applicationName' => $applicationName,
'applicationData' => $applicationData,
'project' => $projectData,
'regionName' => $currentRegion,
'regionData' => $projectData['regions'][$currentRegion],
'brokerConnections' => getBrokerConnections($projectData),
'storeName' => $endpointData['store'] ?? '',
'services' => $services,
'endpointMap' => $endpointMap,
'identifier' => $endpointData['identifier'],
])
);
}
$envVarEncoder->setIsActive(true);

if ($isEndpointDataHasStore || $isEndpointDataHasRegion) {
file_put_contents(
$deploymentDir . DS . 'env' . DS . 'cli' . DS . strtolower($endpointData['identifier']) . '.env',
$twig->render('env/cli/store.env.twig', [
'applicationName' => $applicationName,
'applicationData' => $applicationData,
'project' => $projectData,
'regionName' => $currentRegion,
'regionData' => $projectData['regions'][$currentRegion],
'brokerConnections' => getBrokerConnections($projectData),
'storeName' => $endpointData['store'] ?? '',
'services' => $services,
'endpointMap' => $endpointMap,
'identifier' => $endpointData['identifier'],
])
);

file_put_contents(
$deploymentDir . DS . 'terraform' . DS . 'cli' . DS . strtolower($endpointData['identifier']) . '.env',
$twig->render('terraform/store.env.twig', [
'applicationName' => $applicationName,
'applicationData' => $applicationData,
'project' => $projectData,
'regionName' => $currentRegion,
'regionData' => $projectData['regions'][$currentRegion],
'brokerConnections' => getBrokerConnections($projectData),
'storeName' => $endpointData['store'] ?? '',
'services' => $services,
'endpointMap' => $endpointMap,
'identifier' => $endpointData['identifier'],
])
);
}

$envVarEncoder->setIsActive(false);
$envVarEncoder->setIsActive(false);
}
}
}
}
Expand Down

0 comments on commit cd9a09b

Please sign in to comment.