diff --git a/doc/93-Testing.md b/doc/93-Testing.md index c12862b9..31ce2e67 100644 --- a/doc/93-Testing.md +++ b/doc/93-Testing.md @@ -183,7 +183,6 @@ echo "VACUUM FREEZE" | su - postgres -c psql template1 su - postgres -c 'createuser -a -d gitlab-runner' # Register the runner with your Gitlab installation -```sh gitlab-ci-multi-runner register -n \ -r "$REGISTRATION_TOKEN" \ --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' # Register the runner with your Gitlab installation -```sh gitlab-ci-multi-runner register -n \ -r "$REGISTRATION_TOKEN" \ --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' # Register the runner with your Gitlab installation -```sh gitlab-ci-multi-runner register -n \ -r "$REGISTRATION_TOKEN" \ --executor shell \ diff --git a/library/Director/Objects/IcingaFlatVar.php b/library/Director/Objects/IcingaFlatVar.php new file mode 100644 index 00000000..7a60508c --- /dev/null +++ b/library/Director/Objects/IcingaFlatVar.php @@ -0,0 +1,56 @@ + 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; + } +} diff --git a/library/Director/Objects/IcingaVar.php b/library/Director/Objects/IcingaVar.php new file mode 100644 index 00000000..45bf4a3c --- /dev/null +++ b/library/Director/Objects/IcingaVar.php @@ -0,0 +1,85 @@ + 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()); + } +}