Skip to content
Snippets Groups Projects
Commit 8b4016fc authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update all plugins

parent 045cc974
No related branches found
No related tags found
1 merge request!66php8 only; added variable types; short array syntax; remove glyphicons
This commit is part of merge request !66. Comments created here will be created in the context of that merge request.
......@@ -5,6 +5,8 @@
* Build plugin - TGZ
*
* @author <axel.hahn@iml.unibe.ch>
*
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class build_tgz extends build_base
{
......
......@@ -5,6 +5,8 @@
* Build plugin - TGZ
*
* @author <axel.hahn@iml.unibe.ch>
*
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class build_zip extends build_base
{
......
......@@ -4,18 +4,23 @@
*
* Rollout plugin - awx
*
* Run an Https POST request to AWX
* Run an Https GET or POST request to AWX
*
* @author <axel.hahn@iml.unibe.ch>
*
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class rollout_awx extends rollout_base
{
// url part for AWX API request to set count of results per page
protected $_sAwxApiPaging = '&page_size=10000&page=1';
protected string $_sAwxApiPaging = '&page_size=10000&page=1';
/**
* check requirements if the plugin could work
* Get an array with shell commands to check requirements if the plugin
* can work
*
* @return array
*/
public function checkRequirements(): array
{
......@@ -24,26 +29,31 @@ class rollout_awx extends rollout_base
}
/**
* check access to a deploy target
* Get an array with shell commands to check access to a deploy target
*
* @return array
*/
public function checkConnectionToTarget()
public function checkConnectionToTarget(): array
{
// do nothing ... always empty
return [];
}
/**
* make an http get request and return the response body
* Make an http get request and return the response body
* it is called by _makeRequest
* $aRequest contains subkeys
* - url
* - method; one of GET|POST|PUT|DELETE
* - postdata; for POST only
* - url relative urr; part behind api base url
* - method one of GET|POST|PUT|DELETE
* - postdata for POST only
* - ignore-ssl-error flag: if true it willignores ssl verifiction (not recommended)
* - user, password authentication with "user:password"
*
* @param array $aRequest arrayurl for Foreman API
* @return array
* @param array $aRequest array with request data
* @param integer $iTimeout timeout in seconds
* @return array ... with subkeys "header" and "body" - or "error" if something went wrong
*/
protected function _httpRequest($aRequest = false, $iTimeout = 5)
protected function _httpRequest(array $aRequest = [], int $iTimeout = 5): array
{
if (!function_exists("curl_init")) {
......@@ -51,8 +61,10 @@ class rollout_awx extends rollout_base
}
$aConfig = $this->getConfig();
$sAwxApiUrl=$aConfig['url'] . $aRequest['url'];
// base url --^ ^-- relative url to api
$ch = curl_init($aConfig['url'] . $aRequest['url']);
$ch = curl_init($sAwxApiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $aRequest['method']);
if ($aRequest['method'] === 'POST') {
......@@ -74,6 +86,14 @@ class rollout_awx extends rollout_base
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
if (!$res) {
$iErrorCode = curl_errno($ch);
$sErrorMsg = curl_error($ch);
curl_close($ch);
return [
'error' => "Failed to fetch $sAwxApiUrl - curl error #$iErrorCode: $sErrorMsg"
];
}
$aReturn = ['info' => curl_getinfo($ch), 'error' => curl_error($ch)];
curl_close($ch);
......@@ -87,17 +107,19 @@ class rollout_awx extends rollout_base
}
/**
* get AWX inventories and return them as array for select box
* [id] => array('value' => [ID], 'label' => [NAME] [ID])
* Get AWX inventories and return them as array for select box
* [id] => ['value' => <ID>, 'label' => <NAME> <ID>]
* It returns false if the status code in the response is not 200
*
* @return bool|array
*/
public function getAwxInventories()
public function getAwxInventories(): bool|array
{
$aResponse = $this->_httpRequest(
array(
[
'url' => '/inventories/?order_by=name' . $this->_sAwxApiPaging,
'method' => 'GET',
)
]
);
if (!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code'] !== 200) {
......@@ -131,16 +153,16 @@ class rollout_awx extends rollout_base
}
/**
* get AWX Job Templates and return them as array for select box
* [id] => array('value' => [ID], 'label' => [PLAYBOOK] [ID])
* [id] => ['value' => [ID], 'label' => [PLAYBOOK] [ID]]
* @return bool|array
*/
public function getAwxJobTemplates()
{
$aResponse = $this->_httpRequest(
array(
[
'url' => '/job_templates/?order_by=name' . $this->_sAwxApiPaging,
'method' => 'GET',
)
]
);
if (!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code'] !== 200) {
......@@ -173,15 +195,15 @@ class rollout_awx extends rollout_base
/**
* get array with commands to execute to deploy a package
* Get an array with shell commands to execute for deployment of built file
*
* @param string $sPhase
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase, $bMask = false)
public function getDeployCommands(string $sPhase, bool $bMask = false): array
{
$aReturn = array();
$aReturn = [];
$aConfig = $this->getConfig($sPhase, $bMask);
// ----- Checks:
......@@ -199,7 +221,7 @@ class rollout_awx extends rollout_base
}
// ----- Send variables having values only
$aBodyvars = array();
$aBodyvars = [];
foreach (['inventory' => 'inventory', 'limit' => 'limit', 'job_tags' => 'tags', 'extra_vars' => 'extravars'] as $sParam => $sVarkey) {
if (isset($aConfig[$sVarkey]) && $aConfig[$sVarkey]) {
$aBodyvars[$sParam] = $aConfig[$sVarkey];
......
......@@ -6,12 +6,17 @@
* no action
*
* @author <axel.hahn@iml.unibe.ch>
*
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class rollout_default extends rollout_base
{
/**
* check requirements if the plugin could work
* Get an array with shell commands to check requirements if the plugin
* can work
*
* @return array
*/
public function checkRequirements(): array
{
......@@ -20,22 +25,24 @@ class rollout_default extends rollout_base
}
/**
* check access to a deploy target
* Get an array with shell commands to check access to a deploy target
*
* @return array
*/
public function checkConnectionToTarget()
public function checkConnectionToTarget(): array
{
// do nothing ... always empty
return [];
}
/**
* get array with commands to execute to deploy a package
* Get an array with shell commands to execute for deployment of built file
*
* @param string $sPhase
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase, $bMask = false)
public function getDeployCommands(string $sPhase, bool $bMask = false): array
{
return [
'echo "SKIP"'
......@@ -48,18 +55,18 @@ class rollout_default extends rollout_base
*
* @return string
*/
public function renderFormdata4Project()
public function renderFormdata4Project(): string
{
return $this->_t('no-cfg');
}
/**
* override general form renderer: show a single message that no
* configuration items exist
*
* override of form renderer: show configuration for a given phase
* @param string $sPhase phaese; one of preview|stage|live
* @return string
*/
public function renderFormdata4Phase($sPhase)
public function renderFormdata4Phase(string $sPhase): string
{
return $this->_t('no-cfg');
}
......
......@@ -7,35 +7,44 @@
* Run a SSH command on remote targets
*
* @author <axel.hahn@iml.unibe.ch>
*
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class rollout_ssh extends rollout_base {
/**
* check requirements if the plugin could work
* Get an array with shell commands to check requirements if the plugin
* can work
*
* @return array
*/
public function checkRequirements(): array {
public function checkRequirements(): array
{
// no specific checks needed ... always empty
return [];
}
/**
* check access to a deploy target
* Get an array with shell commands to check access to a deploy target
*
* @return array
*/
public function checkConnectionToTarget() {
public function checkConnectionToTarget(): array
{
// do nothing ... always empty
return [];
}
/**
* get array with commands to execute to deploy a package
* Get an array with shell commands to execute for deployment of built file
*
* @param string $sPhase phase
* @param string $sPhase
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase,$bMask=false){
$aReturn=array();
public function getDeployCommands(string $sPhase, bool $bMask = false): array
{
$aReturn=[];
$aConfig=$this->getConfig($sPhase);
// loop over hosts and create shell commands for it
......
......@@ -4,15 +4,19 @@
* SHELLCMD PLUGIN :: LOAD
*
* ----------------------------------------------------------------------
* 2022-08-05 axel.hahn@iml.unibe.ch
* 2023-12-13 axel.hahn@unibe.ch minified
* Axel: axel.hahn@unibe.ch
* 2022-08-05 Axel initial version
* 2023-12-13 Axel minified
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class shellcmd_load {
class shellcmd_load
{
/**
* parse output and extract wanted values in section "data"
* @return array
*/
public function parsedata($aResult){
public function parsedata(array $aResult): array
{
$aTmp1 = array_reverse(explode(',', $aResult['output'][0]));
$aResult['data'] = [
'uptime' => (isset($aTmp1[5])
......
......@@ -4,15 +4,19 @@
* SHELLCMD PLUGIN :: Processes
*
* ----------------------------------------------------------------------
* 2022-09-19 axel.hahn@iml.unibe.ch
* 2023-12-13 axel.hahn@unibe.ch minified
* Axel: axel.hahn@unibe.ch
* 2022-09-19 Axel initial version
* 2023-12-13 Axel minified
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class shellcmd_processes {
class shellcmd_processes
{
/**
* parse output and extract wanted values in section "data"
* @return array
*/
public function parsedata($aResult){
public function parsedata(array $aResult): array
{
$aResult['data'] = [
'count' => count($aResult['output']) - 1,
];
......
......@@ -4,15 +4,19 @@
* SHELLCMD PLUGIN :: top
*
* ----------------------------------------------------------------------
* 2023-11-23 axel.hahn@unibe.ch
* 2023-12-13 axel.hahn@unibe.ch minified
* Axel: axel.hahn@unibe.ch
* 2023-11-23 Axel initial version
* 2023-12-13 Axel minified
* 2024-09-02 Axel php8 only; added variable types; short array syntax
*/
class shellcmd_top {
class shellcmd_top
{
/**
* parse output and extract wanted values in section "data"
* @return array
*/
public function parsedata($aResult){
public function parsedata(array $aResult): array
{
$aResult['data'] = [
'count' => count($aResult['output']) - 1,
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment