Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular Acls: ETL Support #97

Merged
merged 2 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,695 changes: 1,695 additions & 0 deletions bin/acl-config

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions bin/acl-etl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env php
<?php

require_once __DIR__ . '/../configuration/linker.php';

ini_set('memory_limit', -1);

use CCR\Log;
use OpenXdmod\Setup\AclEtl;

try {
main();
} catch (Exception $e) {
do {
$msg = $e->getMessage();
$stacktrace = $e->getTraceAsString();

fwrite(STDERR, "$msg\n");
fwrite(STDERR, "$stacktrace\n");
} while ($e = $e->getPrevious());
exit(1);
}

function main()
{
$params = array();
$opts = array(
'c::' => 'config_file::',
'p:' => 'section:',
'v' => 'verbose',
'g' => 'debug',
'h' => 'help'
);

$args = getopt(
implode('', array_keys($opts)),
array_values($opts)
);

foreach ($args as $key => $value) {
if (is_array($value)) {
fwrite(STDERR, "Multiple values not allowed for '$key'\n");
exit(1);
}

switch ($key) {
case 'c':
case 'config_file':
$params['config_file'] = $value;
break;
case 'p':
case 'section':
$params['section'] = $value;
break;
case 'v':
case 'verbose':
$params['log_level'] = 'info';
break;
case 'g':
case 'debug':
$params['log_level'] = 'debug';
break;
case 'h':
case 'help':
displayHelp();
exit(0);
}
}

$aclEtl = new AclEtl($params);
$aclEtl->execute();
}

function displayHelp()
{
$msg = <<<EOF
Usage acl-etl [options]

-c | --config_file [file] the config file to use during the etl operation.
-p | --section [section] the section that should be executed.
-v | --verbose output additional information during processing.
-g | --debug output debug information during processing.
EOF;
echo "$msg\n";
}
2 changes: 2 additions & 0 deletions bin/acl-import
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
acl-etl -pacls-import -g
2 changes: 2 additions & 0 deletions bin/acl-xdmod-management
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
acl-etl -pacls-xdmod-management -g
6 changes: 2 additions & 4 deletions classes/ETL/Maintenance/ExecuteSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ public function execute(EtlOverseerOptions $etlOverseerOptions)
// Remove comments from the SQL before executing for clarity.

$commentPatterns = array(
// Inline or multi-line C-style comments. The U (ungreedy) is needed!
'/\/\*(.|[\r\n])*\*\//U',
// Hash-style comments
'/#.*[\r\n]+/',
'/^\s*#.*[\r\n]+/',
// Standard SQL comments.
'/-- ?.*[\r\n]+/'
'/^\s*-- ?.*[\r\n]+/'
);
$sql = preg_replace($commentPatterns, "", $sql);

Expand Down
149 changes: 148 additions & 1 deletion classes/OpenXdmod/Build/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ class Config
*/
private $commandsPreBuild;


/**
* the 'major' portion of the '$version' value.
* ex. '6.6.0-rc1'
* ^
* @var string
**/
private $versionMajor;

/**
* the 'minor' portion of the '$version' value.
* ex. '6.6.0-rc1'
* ^
* @var string

**/
private $versionMinor;

/**
* the 'patch' portion of the '$version' value.
* ex. '6.6.0-rc1'
* ^
* @var string
**/
private $versionPatch;

/**
* the 'preRelease' portion of the '$version' value.
* ex. '6.6.0-rc1'
* ^^^
* @var string
**/
private $versionPreRelease;


/**
* Factory method.
*
Expand Down Expand Up @@ -159,7 +194,7 @@ public static function createFromConfigFile($file)
'file_exclude_paths' => $fileExcludePaths,
'file_exclude_patterns' => $fileExcludePatterns,
'file_maps' => $fileMaps,
'commands_pre_build' => $commandsPreBuild,
'commands_pre_build' => $commandsPreBuild
));
}

Expand Down Expand Up @@ -297,6 +332,64 @@ private static function normalizeFileMapDestination($src, $dest)
}
}

/**
* This function will attempt to, given a version string, parse out the
* components of a semver compliant version number. Returning them in an
* array in the format:
* array(
* $versionMajor,
* $versionMinor,
* $versionPatch,
* $versionPreRelease
* );
*
* If a piece of the version can not be parsed it will default to an empty
* string ('').
*
* @param string $version the version as provided by the file 'build.json'
*
* @return array()
**/
private function getVersionDetails($version)
{
$MAJOR = 1;
$MINOR = 2;
$PATCH = 3;
$PRE_RELEASE = 4;

$major = '';
$minor = '';
$patch = '';
$preRelease = '';

$matches = array();
preg_match("/(\d+)?\.(\d+)?\.?(\d+)?\.?-?([0-9A-Za-z-.]+)?/", $version, $matches);
$length = count($matches);
for ($i = 1; $i < $length; $i++) {
switch ( $i ) {
case $MAJOR:
$major = $matches[$i];
break;
case $MINOR:
$minor = $matches[$i];
break;
case $PATCH:
$patch = $matches[$i];
break;
case $PRE_RELEASE:
$preRelease = $matches[i];
break;
}
}

return array(
$major,
$minor,
$patch,
$preRelease
);
}

/**
* Private constructor to enforce use of factory method.
*
Expand Down Expand Up @@ -327,6 +420,12 @@ private function __construct(array $conf)
$this->fileMaps = $conf['file_maps'];

$this->commandsPreBuild = $conf['commands_pre_build'];
list(
$this->versionMajor,
$this->versionMinor,
$this->versionPatch,
$this->versionPreRelease
) = $this->getVersionDetails($this->version);
}

/**
Expand All @@ -349,6 +448,54 @@ public function getVersion()
return $this->version;
}

/**
* Retrieve the 'major' portion of this module's version number.
* Ex. 6.6.0-rc1
* ^
* in this example the first '6' is the major portion of the version number.
**/
public function getVersionMajor()
{
return $this->versionMajor;
}

/**
* Retrieve the 'minor' portion of this module's version number.
* Ex. 6.6.0-rc1
* ^
* in this example the second '6' is the major portion of the version
* number.
**/
public function getVersionMinor()
{
return $this->versionMinor;
}

/**
* Retrieve the 'patch' portion of this module's version number.
* Ex. 6.6.0-rc1
* ^
* in this example the '0' is the patch portion of the version number.
**/
public function getVersionPatch()
{
return $this->versionPatch;
}

/**
* Retrieve the 'pre-release' portion of this module's version number.
* Ex. 6.6.0-rc1
* ^^^
* in this example the 'rc1' is the pre-release portion of the version
* number.
*
* Note: Anything after the '-' character will be stored here.
**/
public function getVersionPreRelease()
{
return $this->versionPreRelease;
}

/**
* Get the RPM release string.
*
Expand Down
57 changes: 57 additions & 0 deletions classes/OpenXdmod/Build/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public function createPackage()

$this->copySourceFiles();
$this->copyModuleFiles();
$this->createModuleFile();
$this->createInstallScript();
$this->createTarFile();
$this->cleanUp();
Expand Down Expand Up @@ -401,6 +402,62 @@ private function runCommandsPreBuild()
}
}

/**
* Attempt to create a module file that will reside within
* CONF_DIRECTORY/modules.d named <module_name>.json.
*
**/
private function createModuleFile()
{
$this->logger->debug("Creating Module File");
$delim = '-';
$name = $this->config->getName();
if (strpos($name, $delim) !== false) {
$nameParts = explode($delim, $name);
$name = $nameParts[1];
}

$data = array(
'WARNING' => '*** THIS FILE IS AUTOGENERATED. MODIFY AT YOUR OWN RISK ***',
$name => array(
"display" => ucfirst($name),
"enabled" => true,
"packaged_on" => date("Y-m-d H:i:s"),
"version" => array(
"major" => $this->config->getVersionMajor(),
"minor" => $this->config->getVersionMinor(),
"patch" => $this->config->getVersionPatch(),
"pre_release" => $this->config->getVersionPreRelease(),
"value" => $this->config->getVersion()
)
)
);
$modulesDirectory = implode(
DIRECTORY_SEPARATOR,
array(
$this->getPackageDir(),
"configuration",
"modules.d"
)
);

if (!is_dir($modulesDirectory)) {
mkdir($modulesDirectory);
}

$destination = implode(
DIRECTORY_SEPARATOR,
array(
$modulesDirectory,
"$name.json"
)
);

\CCR\Json::saveFile($destination, $data);

$this->logger->info("Generated Module Json File: $destination");
}

/**
* Copy files from source to temporary location.
*/
Expand Down
Loading