Commit a100ff15 authored by Hendrik Heneke's avatar Hendrik Heneke
Browse files

Initial version.

parents
Pipeline #360 passed with stage
in 26 seconds
root = true
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
###> symfony/framework-bundle ###
APP_ENV=test
APP_SECRET=secret
###< symfony/framework-bundle ###
admin_password='overidden'
.idea
.phpunit.result.cache
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
image: composer:2
test:
script:
- composer install --ignore-platform-reqs
- composer run php-cs:check
- vendor/bin/phpunit
#!/usr/bin/env php
<?php
use HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the ' . PHP_SAPI . ' SAPI' . PHP_EOL;
}
set_time_limit(0);
$candidates = [
dirname(__DIR__) . '/../../autoload.php' => dirname(__DIR__) . '/../../',
dirname(__DIR__) . '/../autoload.php' => dirname(__DIR__) . '/../',
dirname(__DIR__) . '/vendor/autoload.php' => dirname(__DIR__)
];
$autoloaderPath = null;
$pojectDir = null;
foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) {
if (file_exists($autoloaderPathCandidate)) {
$autoloaderPath = $autoloaderPathCandidate;
$projectDir = $projectDirCandidate;
echo realpath($projectDir) ."\n";
break;
}
}
if (null === $autoloaderPath) {
throw new RuntimeException('Unable to locate autoload.php file.');
}
require_once $autoloaderPath;
unset($candidates, $autoloaderPathCandidate, $projectDirCandidate);
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}
if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG=' . $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
if (file_exists($projectDir . '/.env')) {
(new Dotenv())->bootEnv($projectDir . '/.env');
}
$debug = false;
if (isset($_SERVER['APP_DEBUG']) && $_SERVER['APP_DEBUG']) {
$debug = true;
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new StandaloneKernel($_SERVER['APP_ENV'], $debug);
$application = new Application($kernel);
$application->run($input);
{
"name": "hhit/cfgen-bundle",
"type": "library",
"license": "MIT",
"authors": [
{"name": "Hendrik Heneke", "email": "heneke@gmail.com"}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"paragonie/sodium_compat": "^1.14",
"symfony/framework-bundle": "5.2.*",
"symfony/yaml": "4.4.* ||5.2.*",
"zordius/lightncandy": "^1.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^9.5",
"symfony/console": "4.4.* || 5.2.*",
"symfony/dotenv": "4.4.* || 5.2.*"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"HHIT\\ConfigGeneratorBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"HHIT\\ConfigGeneratorBundle\\Tests\\": "tests/"
}
},
"extra": {
"symfony": {
"require": "4.4.* || 5.2.*"
}
},
"scripts": {
"cfgen:standalone:generate-configs:test": "bin/cfgen -e test cfgen:generate-configs -c tests/cfgen.json --vault symfony --overwrite",
"php-cs:check": "php-cs-fixer fix --dry-run --stop-on-violation --using-cache=no --rules=-line_ending src",
"php-cs:fix": "php-cs-fixer fix --using-cache=no src"
}
}
This diff is collapsed.
<?php // test.admin_password.dc3565 on Fri, 26 Feb 2021 23:19:44 +0100
return "F\x8FwZ\x80\x8C\x19\x02\xAB\x9CZ\x7F\xA6\xAF2\xEA\x1A\xC7\xAE\x26Y\xBB\x85\x93\x8Da\x3E\x82D\x06\x25G\x14I\x7DvsN\xB9g\x94\x06-\xC2\x1EMR\xE2VL\x8C\x3Ao\x85\x3F\xFA";
<?php // dev.decrypt.private on Sun, 21 Feb 2021 13:44:05 +0100
return "\x89\xC3uC\x0A\xC2\xF3O\x2B\xA7\xB6\xF9\xACZ\xB3\xB6\x2B\xEB\xD5\x01h\xD8\x1EOF\xFB\x20hn\xEC\x95.\xF0\xCFo\xB0\x3D.Q\xB5\x13fS\xA9\x0FA\x20\xCF1\x12\xF3\x9B\x86\x08\xE7\xCC\x99\xF7\x22\x10\xAE\x07\x88\x12";
<?php // dev.encrypt.public on Sun, 21 Feb 2021 13:44:05 +0100
return "\xF0\xCFo\xB0\x3D.Q\xB5\x13fS\xA9\x0FA\x20\xCF1\x12\xF3\x9B\x86\x08\xE7\xCC\x99\xF7\x22\x10\xAE\x07\x88\x12";
<?php
return array (
'admin_password' => NULL,
'operator_password' => NULL,
'secret' => NULL,
);
<?php // test.operator_password.b45a1e on Fri, 26 Feb 2021 23:19:55 +0100
return "\x3A\xB7\x10\x07\xB7\x97\x06\xB0\xAB\xF1\x95\x9B\xBD\xD7\xB3\xA1\x23\xC4\xA8\x1D9E\x9F\x29\x22\xA9\xFC\x0B\xEC\x0C\x84\x3AV\xC7J\x3B.\xE4\x3A\xD0\xD5\xB9\x8C\x88\x7CqO\x13z\xD7\xA7\xCB\xC0\x9F\x91\x21";
<?php // test.secret.5ebe22 on Fri, 26 Feb 2021 23:21:17 +0100
return "\xB5\x7F\x8E9\x1D\x29\x94\xF2\x84\xB8\x94\xADARc\xB1FA\x08\xA8.\xCD\xA4\xB6\x2C.\x26\xEE\x2B\x95RN\xD1\xEE\x9D\x88\xB9\x2A.\x09\xA2\x87\x1A\xABEY\x2B\xB3X\xAD\xC2\x14\xA4T\x85\xCA\x22\x08";
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<env name="KERNEL_CLASS" value="HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel"/>
</php>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Command;
use HHIT\ConfigGeneratorBundle\Generator\Generator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class GenerateConfigsCommand extends Command
{
protected static $defaultName = "cfgen:generate-configs";
private Generator $generator;
public function __construct(
Generator $generator,
string $name = null
) {
parent::__construct($name);
$this->generator = $generator;
}
protected function configure()
{
$this->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'configuration file (default is %kernel.project_dir%/cfgen.json)');
$this->addOption('vault', null, InputOption::VALUE_REQUIRED, 'vault type', 'symfony');
$this->addOption('overwrite', null, InputOption::VALUE_NONE, 'overwrite existing files');
}
public function execute(InputInterface $input, OutputInterface $output)
{
$success = $this->generator->processConfigurations(
$input->getOption('vault'),
$input->getOption('overwrite') ? true : false,
$input->getOption('config') ?: null,
$output
);
return $success ? Command::SUCCESS : Command::FAILURE;
}
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ConfigGeneratorBundle extends Bundle
{
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class ConfigGeneratorExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yaml');
}
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Compiler;
use HHIT\ConfigGeneratorBundle\Generator\IO\File;
use HHIT\ConfigGeneratorBundle\Generator\IO\FileReader;
use HHIT\ConfigGeneratorBundle\Generator\Values\ValuesLoader;
use LightnCandy\LightnCandy;
class Compiler extends FileReader
{
private ValuesLoader $loader;
private ?\Closure $fn = null;
private array $helpers = [];
public function __construct(File $file, ValuesLoader $loader)
{
parent::__construct($file);
$this->loader = $loader;
$this->helpers = [
'password_hash_default' => function ($password) {
return password_hash($password, PASSWORD_DEFAULT);
},
'password_hash_bcrypt' => function ($password) {
if (!in_array('2y', password_algos())) {
throw new \Exception('bcrypt algorithm not supported!');
}
return password_hash($password, PASSWORD_BCRYPT);
},
'password_hash_argon2i' => function ($password) {
if (!in_array('argon2i', password_algos())) {
throw new \Exception('argon2i algorithm not supported!');
}
return password_hash($password, PASSWORD_ARGON2I);
},
'password_hash_argon2id' => function ($password) {
if (!in_array('argon2id', password_algos())) {
throw new \Exception('argon2id algorithm not supported!');
}
return password_hash($password, PASSWORD_ARGON2ID);
}
];
}
public function compile()
{
if (!$this->fn) {
$compiled = LightnCandy::compile($this->read(), [
'flags' => LightnCandy::FLAG_BESTPERFORMANCE | LightnCandy::FLAG_HANDLEBARS,
'helpers' => $this->helpers
]);
$this->fn = eval($compiled);
}
return $this->fn->call($this, $this->loader->getValues());
}
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Definition;
use HHIT\ConfigGeneratorBundle\Generator\IO\File;
use HHIT\ConfigGeneratorBundle\Generator\IO\Path;
class Definition
{
private string $id;
private File $templateFile;
private string $type;
private File $valuesFile;
private File $destinationFile;
public function __construct(string $id, File $templateFile, string $type, File $valuesFile, File $destinationFile)
{
$this->id = $id;
$this->templateFile = $templateFile;
$this->type = $type;
$this->valuesFile = $valuesFile;
$this->destinationFile = $destinationFile;
}
public function getId(): string
{
return $this->id;
}
public function getTemplateFile(): File
{
return $this->templateFile;
}
public function getType(): string
{
return $this->type;
}
public function getValuesFile(): File
{
return $this->valuesFile;
}
public function getDestinationFile(): File
{
return $this->destinationFile;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment