Skip to content

Commit

Permalink
Merge branch 'release/9.x' of github.com:ec-europa/toolkit into relea…
Browse files Browse the repository at this point in the history
…se/10.x
  • Loading branch information
joaocsilva committed Aug 31, 2023
2 parents 4d354a0 + a32ccdf commit 32aef20
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Toolkit change log

## Version 9.13.0
- DQA-7528: Allow to block access to files in htaccess.
- DQA-7379: Force max-age in Cache-Control headers.

## Version 9.12.0 | 10.2.0
- DQA-7395: Replace security-checker with composer audit.
- DQA-6756: Create example section in the toolkit documentation.
Expand Down
4 changes: 4 additions & 0 deletions config/runner/toolkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ toolkit:
- composer.lock
- composer.json
remove:
- CHANGELOG.md
- CHANGELOG.txt
- COPYRIGHT.txt
- INSTALL.mysql.txt
Expand All @@ -50,6 +51,9 @@ toolkit:
commands: [ ]
dev:
commands: [ ]
htaccess:
block:
file-match: '(README\.(md|txt)|CHANGELOG\.(md|txt))$'
custom-code-folder: 'lib'
npm:
theme-task-runner: grunt
Expand Down
2 changes: 1 addition & 1 deletion phpdoc.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<paths>
<output>docs</output>
</paths>
<version number="10.2.0">
<version number="9.13.0">
<folder>latest</folder>
<api>
<source dsn=".">
Expand Down
77 changes: 73 additions & 4 deletions src/TaskRunner/Commands/BuildCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
class BuildCommands extends AbstractCommands
{

/**
* Comment starting the Toolkit block.
*
* @var string
*/
protected string $blockStart = '# Start Toolkit block.';

/**
* Comment ending the Toolkit block.
*
* @var string
*/
protected string $blockEnd = '# End Toolkit block.';

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -127,25 +141,28 @@ public function buildDist(array $options = [
'version' => $tag,
'sha' => $hash,
]));
$tasks[] = $this->taskWriteToFile($options['dist-root'] . '/' . $options['root'] . '/VERSION.txt')
$tasks[] = $this->taskWriteToFile("{$options['dist-root']}/{$options['root']}/VERSION.txt")
->text($tag);

// Copy and process drush.yml file.
if (file_exists('resources/Drush/drush.yml.dist')) {
$tasks[] = $this->taskFilesystemStack()
->copy('resources/Drush/drush.yml.dist', $options['dist-root'] . '/web/sites/all/drush/drush.yml');
->copy('resources/Drush/drush.yml.dist', "{$options['dist-root']}/{$options['root']}/sites/all/drush/drush.yml");
}

// Collect and execute list of commands set on local runner.yml.
$commands = $this->getConfig()->get('toolkit.build.dist.commands');
$commands = $config->get('toolkit.build.dist.commands');
if (!empty($commands)) {
$tasks[] = $this->taskExecute($commands);
}

// Remove 'unwanted' files from distribution.
$remove = '-name "' . implode('" -o -name "', explode(',', $options['remove'])) . '"';
$tasks[] = $this->taskExecStack()
->exec("find dist -maxdepth 3 -type f \( $remove \) -exec rm -rf {} +");
->exec("find {$options['dist-root']} -maxdepth 3 -type f \( $remove \) -exec rm -rf {} +");

// Add custom block to .htaccess file.
$tasks[] = $this->getHtaccessTask("{$options['dist-root']}/{$options['root']}");

// Build and return task collection.
return $this->collectionBuilder()->addTaskList($tasks);
Expand Down Expand Up @@ -210,6 +227,9 @@ public function buildDev(array $options = [
$tasks[] = $this->taskExecute($commands);
}

// Add custom block to .htaccess file.
$tasks[] = $this->getHtaccessTask($root);

// Build and return task collection.
return $this->collectionBuilder()->addTaskList($tasks);
}
Expand Down Expand Up @@ -368,4 +388,53 @@ public function buildAssets(ConsoleIO $io, array $options = [
}
}

/**
* Returns the task for adding custom block to htaccess file.
*
* @param string $root
* The drupal root where the .htaccess file is.
*/
private function getHtaccessTask(string $root) {
return $this->collectionBuilder()->addCode(function () use ($root) {
$htaccess = "$root/.htaccess";
if (!file_exists($htaccess)) {
return;
}
$htaccessBlock = $this->getHtaccessBlock();
if (empty($htaccessBlock)) {
return;
}
// Clean up.
$this->taskReplaceBlock($htaccess)->excludeStartEnd()
->start(PHP_EOL . $this->blockStart)->end($this->blockEnd)
->content('')->run();

// Append Toolkit block to htaccess file.
$this->taskWriteToFile($htaccess)->append()->text($htaccessBlock)->run();
});
}

/**
* Returns the block for the htaccess file.
*/
private function getHtaccessBlock(): string {
$fileMatch = $this->getConfig()->get('toolkit.build.htaccess.block.file-match');
if (empty($fileMatch)) {
return '';
}
return <<< EOF
{$this->blockStart}
<FilesMatch "$fileMatch">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
</IfModule>
</FilesMatch>
{$this->blockEnd}
EOF;
}

}
9 changes: 6 additions & 3 deletions src/TaskRunner/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,15 @@ protected function getToolkitSettingsBlock()
\$settings['file_private_path'] = getenv('DRUPAL_PRIVATE_FILE_SYSTEM') !== FALSE ? getenv('DRUPAL_PRIVATE_FILE_SYSTEM') : 'sites/default/private_files';
\$settings['file_temp_path'] = getenv('DRUPAL_FILE_TEMP_PATH') !== FALSE ? getenv('DRUPAL_FILE_TEMP_PATH') : '/tmp';
// Reverse proxy
// Reverse proxy.
if (intval(getenv('DRUPAL_REVERSE_PROXY_ENABLE')) === 1) {
\$settings["reverse_proxy"] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
\$settings["reverse_proxy_addresses"] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
\$settings['reverse_proxy'] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
\$settings['reverse_proxy_addresses'] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
}
// Dropsolid requires a value to be set for max-age.
\$config['cache.page.max_age'] = 21600;
{$additionalSettings}
// Load environment development override configuration, if available.
Expand Down
2 changes: 1 addition & 1 deletion src/Toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class Toolkit
/**
* Constant holding the current version.
*/
public const VERSION = '10.2.0';
public const VERSION = '9.13.0';

/**
* Returns the Toolkit root.
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/commands/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
[Simulator] Simulating File\Write('dist/web/VERSION.txt')
->text('')
[Simulator] Simulating ExecStack()
->exec('find dist -maxdepth 3 -type f \( -name "CHANGELOG.txt" ... ) -exec rm -rf {} +')
->exec('find dist -maxdepth 3 -type f \( -name "CHANGELOG.md" ... ) -exec rm -rf {} +')
- command: 'toolkit:build-dev'
configuration: []
Expand Down
27 changes: 18 additions & 9 deletions tests/fixtures/commands/drupal-settings-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
$settings['file_private_path'] = getenv('DRUPAL_PRIVATE_FILE_SYSTEM') !== FALSE ? getenv('DRUPAL_PRIVATE_FILE_SYSTEM') : 'sites/default/private_files';
$settings['file_temp_path'] = getenv('DRUPAL_FILE_TEMP_PATH') !== FALSE ? getenv('DRUPAL_FILE_TEMP_PATH') : '/tmp';
// Reverse proxy
// Reverse proxy.
if (intval(getenv('DRUPAL_REVERSE_PROXY_ENABLE')) === 1) {
$settings["reverse_proxy"] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings["reverse_proxy_addresses"] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
$settings['reverse_proxy'] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings['reverse_proxy_addresses'] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
}
// Dropsolid requires a value to be set for max-age.
$config['cache.page.max_age'] = 21600;
// Load environment development override configuration, if available.
Expand Down Expand Up @@ -93,12 +96,15 @@
$settings['file_private_path'] = getenv('DRUPAL_PRIVATE_FILE_SYSTEM') !== FALSE ? getenv('DRUPAL_PRIVATE_FILE_SYSTEM') : 'sites/default/private_files';
$settings['file_temp_path'] = getenv('DRUPAL_FILE_TEMP_PATH') !== FALSE ? getenv('DRUPAL_FILE_TEMP_PATH') : '/tmp';
// Reverse proxy
// Reverse proxy.
if (intval(getenv('DRUPAL_REVERSE_PROXY_ENABLE')) === 1) {
$settings["reverse_proxy"] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings["reverse_proxy_addresses"] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
$settings['reverse_proxy'] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings['reverse_proxy_addresses'] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
}
// Dropsolid requires a value to be set for max-age.
$config['cache.page.max_age'] = 21600;
$config['cas.settings']['server']['hostname'] = getenv('CAS_HOSTNAME');
$config['cas.settings']['server']['port'] = getenv('CAS_PORT');
Expand Down Expand Up @@ -151,12 +157,15 @@
$settings['file_private_path'] = getenv('DRUPAL_PRIVATE_FILE_SYSTEM') !== FALSE ? getenv('DRUPAL_PRIVATE_FILE_SYSTEM') : 'sites/default/private_files';
$settings['file_temp_path'] = getenv('DRUPAL_FILE_TEMP_PATH') !== FALSE ? getenv('DRUPAL_FILE_TEMP_PATH') : '/tmp';
// Reverse proxy
// Reverse proxy.
if (intval(getenv('DRUPAL_REVERSE_PROXY_ENABLE')) === 1) {
$settings["reverse_proxy"] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings["reverse_proxy_addresses"] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
$settings['reverse_proxy'] = (bool) getenv('DRUPAL_REVERSE_PROXY_ENABLE');
$settings['reverse_proxy_addresses'] = explode(',', getenv('DRUPAL_REVERSE_PROXY_ADDRESSES'));
}
// Dropsolid requires a value to be set for max-age.
$config['cache.page.max_age'] = 21600;
// Load environment development override configuration, if available.
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/commands/tool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
[WARNING] Failed to get Toolkit version from composer.lock.
Minimum version: ^10
Current version: 10.2.0
Current version: 9.13.0
Version check: OK
- command: toolkit:check-version
Expand All @@ -99,7 +99,7 @@
> Checking Toolkit version:
Minimum version: ^10
Current version: 10.2.0
Current version: 9.13.0
Version check: OK
- command: toolkit:vendor-list
Expand Down

0 comments on commit 32aef20

Please sign in to comment.