mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
doc/testing: fix syntax
This commit is contained in:
parent
9292bb8524
commit
eb1f1a2c33
@ -183,7 +183,6 @@ echo "VACUUM FREEZE" | su - postgres -c psql template1
|
|||||||
su - postgres -c 'createuser -a -d gitlab-runner'
|
su - postgres -c 'createuser -a -d gitlab-runner'
|
||||||
|
|
||||||
# Register the runner with your Gitlab installation
|
# Register the runner with your Gitlab installation
|
||||||
```sh
|
|
||||||
gitlab-ci-multi-runner register -n \
|
gitlab-ci-multi-runner register -n \
|
||||||
-r "$REGISTRATION_TOKEN" \
|
-r "$REGISTRATION_TOKEN" \
|
||||||
--executor shell \
|
--executor shell \
|
||||||
@ -210,7 +209,6 @@ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -q -y \
|
|||||||
su - postgres -c 'createuser -a -d gitlab-runner'
|
su - postgres -c 'createuser -a -d gitlab-runner'
|
||||||
|
|
||||||
# Register the runner with your Gitlab installation
|
# Register the runner with your Gitlab installation
|
||||||
```sh
|
|
||||||
gitlab-ci-multi-runner register -n \
|
gitlab-ci-multi-runner register -n \
|
||||||
-r "$REGISTRATION_TOKEN" \
|
-r "$REGISTRATION_TOKEN" \
|
||||||
--executor shell \
|
--executor shell \
|
||||||
@ -243,7 +241,6 @@ mysql -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User='roo
|
|||||||
su - postgres -c 'createuser -a -d gitlab-runner'
|
su - postgres -c 'createuser -a -d gitlab-runner'
|
||||||
|
|
||||||
# Register the runner with your Gitlab installation
|
# Register the runner with your Gitlab installation
|
||||||
```sh
|
|
||||||
gitlab-ci-multi-runner register -n \
|
gitlab-ci-multi-runner register -n \
|
||||||
-r "$REGISTRATION_TOKEN" \
|
-r "$REGISTRATION_TOKEN" \
|
||||||
--executor shell \
|
--executor shell \
|
||||||
|
56
library/Director/Objects/IcingaFlatVar.php
Normal file
56
library/Director/Objects/IcingaFlatVar.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\CustomVariable\CustomVariable;
|
||||||
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
|
use Icinga\Module\Director\Db;
|
||||||
|
|
||||||
|
class IcingaFlatVar extends DbObject
|
||||||
|
{
|
||||||
|
protected $table = 'icinga_flat_var';
|
||||||
|
|
||||||
|
protected $keyName = array(
|
||||||
|
'checksum',
|
||||||
|
'flatname_checksum'
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $defaultProperties = array(
|
||||||
|
'var_checksum' => null,
|
||||||
|
'flatname_checksum' => null,
|
||||||
|
'flatname' => null,
|
||||||
|
'flatvalue' => null,
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function generateForCustomVar(CustomVariable $var, Db $db)
|
||||||
|
{
|
||||||
|
$flatVars = static::forCustomVar($var, $db);
|
||||||
|
foreach ($flatVars as $flat) {
|
||||||
|
$flat->store();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $flatVars;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function forCustomVar(CustomVariable $var, Db $db)
|
||||||
|
{
|
||||||
|
$flat = array();
|
||||||
|
$varSum = $var->checksum();
|
||||||
|
$var->flatten($flat, $var->getKey());
|
||||||
|
$flatVars = array();
|
||||||
|
|
||||||
|
foreach ($flat as $name => $value) {
|
||||||
|
$flatVar = static::create(array(
|
||||||
|
'var_checksum' => $varSum,
|
||||||
|
'flatname_checksum' => sha1($name, true),
|
||||||
|
'flatname' => $name,
|
||||||
|
'flatvalue' => $value,
|
||||||
|
), $db);
|
||||||
|
|
||||||
|
$flatVar->store();
|
||||||
|
$flatVars[] = $flatVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $flatVars;
|
||||||
|
}
|
||||||
|
}
|
85
library/Director/Objects/IcingaVar.php
Normal file
85
library/Director/Objects/IcingaVar.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\CustomVariable\CustomVariable;
|
||||||
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||||
|
use Icinga\Module\Director\Db;
|
||||||
|
|
||||||
|
class IcingaVar extends DbObject
|
||||||
|
{
|
||||||
|
protected $table = 'icinga_var';
|
||||||
|
|
||||||
|
protected $keyName = 'checksum';
|
||||||
|
|
||||||
|
/** @var CustomVariable */
|
||||||
|
protected $var;
|
||||||
|
|
||||||
|
protected $defaultProperties = array(
|
||||||
|
'checksum' => null,
|
||||||
|
'rendered_checksum' => null,
|
||||||
|
'varname' => null,
|
||||||
|
'varvalue' => null,
|
||||||
|
'rendered' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CustomVariable $var
|
||||||
|
* @param Db $db
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function forCustomVar(CustomVariable $customVar, Db $db)
|
||||||
|
{
|
||||||
|
$rendered = static::renderVar($customVar);
|
||||||
|
|
||||||
|
$var = static::create(array(
|
||||||
|
'checksum' => $customVar->checksum(),
|
||||||
|
'rendered_checksum' => sha1($rendered, true),
|
||||||
|
'varname' => $customVar->getKey(),
|
||||||
|
'varvalue' => $customVar->toJson(),
|
||||||
|
'rendered' => $rendered,
|
||||||
|
), $db);
|
||||||
|
|
||||||
|
$var->var = $customVar;
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function renderVar(CustomVariable $var)
|
||||||
|
{
|
||||||
|
$renderExpressions = false; // TODO!
|
||||||
|
return c::renderKeyValue(
|
||||||
|
static::renderKeyName($var->getKey()),
|
||||||
|
$var->toConfigStringPrefetchable($renderExpressions)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function renderKeyName($key)
|
||||||
|
{
|
||||||
|
if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) {
|
||||||
|
return 'vars.' . c::escapeIfReserved($key);
|
||||||
|
} else {
|
||||||
|
return 'vars[' . c::renderString($key) . ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CustomVariable $var
|
||||||
|
* @param Db $db
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function generateForCustomVar(CustomVariable $customVar, Db $db)
|
||||||
|
{
|
||||||
|
$var = static::forCustomVar($customVar, $db);
|
||||||
|
$var->store();
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function onInsert()
|
||||||
|
{
|
||||||
|
IcingaFlatVar::generateForCustomVar($this->var, $this->getConnection());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user