diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index 16f17943838b3d8d6733d8ffd1ab0242a3849633..1624350bd2b0fecc6a33b6c0e264e1e096c93707 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -3362,6 +3362,17 @@ class project extends base { . $TmpRolloutPlugin->renderFormdata4Project() . '</div>' ; + + // generate form firlds for each phase + foreach(array_keys($this->getPhases()) as $sMyPhase){ + $aRollout[$sMyPhase].='' + . '<div id="'.$sMyDivId.'-'.$sMyPhase.'" class="'.$sMyDivClass.' '.$sMyDivClassActive.'"' + . ($bActive ? '' : 'style="display: none;"' ) + . '>' + . $TmpRolloutPlugin->renderFormdata4Phase($sMyPhase) + . '</div>' + ; + } } catch (Exception $ex) { } @@ -3370,17 +3381,8 @@ class project extends base { 'label' => "not found: " . $sMyClassname, 'checked' => false, 'disabled' => "disabled", - 'onclick' => '$(\'.'.$sMyDivClass.'\').hide(); $(\'.' . $sMyDivClassActive . '\').show();', ); - $aRollout['project-config'].='' - . '<div id="'.$sMyDivId.'" class="'.$sMyDivClass.' '.$sMyDivClassActive.'"' - . ($bActive ? '' : 'style="display: none;"' ) - . '>' - . 'id="'.$sMyDivId.'" class="'.$sMyDivClass.'"<br>' - // . 'Plugin content' - . ':-/' - . '</div>' - ; + } } @@ -3688,7 +3690,7 @@ class project extends base { 'value' => '' . '<hr>' .'<label class="col-sm-2">'.t('deploy-rollout-plugin-config') .'</label>' - .'<div class="col-sm-10">'. $aRollout['project-config'].'</div>' + .'<div class="col-sm-10">'. $aRollout['project-config'].'<hr>PREVIEW:'.$aRollout['preview'].'</div>' ), // -------------------------------------------------- 'input' . $i++ => array( diff --git a/public_html/deployment/classes/rollout_base.class.php b/public_html/deployment/classes/rollout_base.class.php index 0165097d45395941de3c5847e04947ea67bc73b7..b9954de72ed93b577e8d69e07f4f70f9838351bd 100644 --- a/public_html/deployment/classes/rollout_base.class.php +++ b/public_html/deployment/classes/rollout_base.class.php @@ -54,9 +54,11 @@ class rollout_base implements iRolloutplugin{ */ protected $_aCfgProject = false; - + protected $_sNamePrefix4Project=false; // set in constructor + protected $_sNamePrefix4Phase=false; // set in constructor + // --------------------------------------------------------------- - // METHODS + // CONSTRUCTOR // --------------------------------------------------------------- /** @@ -74,7 +76,10 @@ class rollout_base implements iRolloutplugin{ // set current plugin id - taken from plugin directory name above $oReflection=new ReflectionClass($this); $this->_sPluginId=basename(dirname($oReflection->getFileName())); - + + $this->_sNamePrefix4Project='plugins[rollout]['.$this->getId().']'; + $this->_sNamePrefix4Phase='[plugins][rollout]['.$this->getId().']'; + // ----- init language if (isset($aParams['lang'])){ $this->setLang($aParams['lang']); @@ -98,11 +103,24 @@ class rollout_base implements iRolloutplugin{ return true; } + // --------------------------------------------------------------- + // FORM HELPER + // --------------------------------------------------------------- + /** + * render a form by given form elementes + * @param array $aFormdata array of form elements + * @param string $sKey part of the identifier used in id of the input field + * @return string + */ protected function _renderForm($aFormdata, $sKey){ + static $i; + if (!isset($i)){ + $i=0; + } + $sReturn=''; $sKeyPrefix=$this->getId().'_'.$sKey; - $i=0; $oForm = new formgen($aForms); foreach ($aFormdata as $elementData) { @@ -112,6 +130,75 @@ class rollout_base implements iRolloutplugin{ return $sReturn; } + /** + * render form fields for global plugin variables + * @param string $sPrefixName prefix in the name attribute to store the data in the right structure + * @param string $sPhase optional: render global vars in a phase; if no phase was set it renders form fields for project based settings + * @return string + */ + protected function _renderFormGlobalVars($sPrefixName, $sPhase=false){ + $sReturn=''; + $aInfos=$this->getPluginInfos(); + if(!isset($aInfos['vars']['global'])){ + return ''; + } + $sKey=($sPhase ? 'phase_'.$sPhase : 'project'); + + // helper vars: directly set values in the settings .. without merge of overrides + /* + $aGlobalValues=$this->_aCfgGlobal; + $aPrjValues=$this->_aCfgProject['deploy']['plugins']['rollout'][$this->getId()]; + $aPhaseValues=($sPhase ? $this->_aCfgProject[$sPhase]['plugins']['rollout'][$this->getId()] : false); + */ + + // set defaults - to be used in placeholder attribute + // no phase = project level - take global defaults of ci config + // on a phase - fetch merged cofig data of project + $aDefaultValues=($sPhase ? $this->getConfig() : $this->_aCfgGlobal); + + // set defaults - to be used in value attribute + $aValues=($sPhase + ? $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()] + : $this->_aCfgProject['plugins']['rollout'][$this->getId()] + ); + + /* + $aDefaultValues=($sPhase ? $this->_aCfgProject['deploy']['plugins']['rollout'][$this->getId()] : $this->_aCfgGlobal); + + // $aValues=$this->getConfig($sPhase); + $aValues=($sPhase ? $this->_aCfgProject['deploy']['plugins']['rollout'][$this->getId()] : $this->_aCfgGlobal); + * + */ + $aFormdata=array(); + + // create form fields + $aFormdata[]=array('type' => 'markup','value' => '<br>'.$this->_t('section-override-global-vars').':'); + $sMiss=''; + foreach ($aInfos['vars']['global'] as $sVarname=>$aVarinfos){ + if (!isset($this->_aCfgGlobal[$sVarname])){ + $sMiss.='- plugin var was not set in global CI config: plugins -> rollout -> '.$this->getId().' -> "'.$sVarname.'".<br>'; + } + if($aVarinfos['type']=="text"){ + $aFormdata[]=array( + 'type' => 'text', + 'name' => $sPrefixName.'['.$sVarname.']', + 'label' => $this->_t('formlabel-'.$sVarname), + 'value' => (isset($aValues[$sVarname]) ? $aValues[$sVarname] : ''), + // 'required' => 'required', + 'validate' => 'isastring', + // 'size' => 25, + // 'placeholder' => (isset($this->_aCfgGlobal[$sVarname]) ? $this->_aCfgGlobal[$sVarname] : '') . ' | '.$aDefaultValues[$sVarname], + 'placeholder' => (isset($aDefaultValues[$sVarname]) ? $aDefaultValues[$sVarname] : 'N.A.'), + ); + } else { + $sMiss.='- plugin var "'.$sVarname.'" does not have type text. It cannot be rendered so far.<br>'; + } + } + + return $this->_renderForm($aFormdata, $sKey) + . ($sMiss ? '<pre>WARNINGS:<br>'.$sMiss.'</pre>' : '') + ; + } /** * get a translated text from lang_XX.json in plugin dir; * If the key is missed it returns "[KEY :: LANG]" @@ -127,6 +214,9 @@ class rollout_base implements iRolloutplugin{ ; } + // --------------------------------------------------------------- + // PUBLIC METHODS + // --------------------------------------------------------------- /** * set language for output of formdata and other texts. @@ -210,6 +300,24 @@ class rollout_base implements iRolloutplugin{ */ $this->_aCfgProject['plugins']['rollout'][$this->_sPluginId]=array('INFO'=>'created'); } + + // unset empty project values to get global values + + foreach ($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId] as $sVarname=>$value){ + if ($value===''){ + unset($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId][$sVarname]); + } + } + foreach (array_keys($this->_aCfgProject['phases']) as $sMyPhase){ + if (isset($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()])){ + foreach($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()] as $sVarname=>$value){ + if ($value===''){ + unset($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()][$sVarname]); + } + } + } + } + // TODO: return $this->_aCfgProject; } @@ -225,9 +333,9 @@ class rollout_base implements iRolloutplugin{ */ public function getConfig($sPhase=false){ - return ($sPhase && isset($this->_aCfgProject['phases']['plugins']['rollout'][$this->_sPluginId])) - ? array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->_sPluginId], $this->_aCfgProject['phases']['plugins']['rollout'][$this->_sPluginId]) - : array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->_sPluginId]) + return ($sPhase && isset($this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()])) + ? array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->getId()], $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()]) + : array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->getId()]) ; } @@ -279,5 +387,7 @@ class rollout_base implements iRolloutplugin{ public function renderFormdata4Project() { return ''; } - + public function renderFormdata4Phase($sMyPhase){ + return ''; + } } diff --git a/public_html/deployment/plugins/rollout/ssh/info.json b/public_html/deployment/plugins/rollout/ssh/info.json index 7aaf679104cb84dbc13d1227bd195418302b350b..0cb751883e767004967a04304fb4f80176180ade 100644 --- a/public_html/deployment/plugins/rollout/ssh/info.json +++ b/public_html/deployment/plugins/rollout/ssh/info.json @@ -8,7 +8,28 @@ "license": "GNU GPL 3.0", "vars": { - "global": {}, + "global": { + "user": { + "type": "text", + "default": "remoteuser" + }, + "command": { + "type": "text", + "default": "/opt/somewhere/install.sh" + }, + "privatekey": { + "type": "text", + "default": "" + }, + "addkeycommand": { + "type": "text", + "default": "" + }, + "testcommand": { + "type": "text", + "default": "sudo echo OK" + } + }, "project": {}, "phase": {} } diff --git a/public_html/deployment/plugins/rollout/ssh/lang_de.json b/public_html/deployment/plugins/rollout/ssh/lang_de.json index 477f41da3ffd9a7a185c58c4903a1f119ba6cdf1..dc69ecd0e76164fe74e849b1093bcd6ae4f6b4ee 100644 --- a/public_html/deployment/plugins/rollout/ssh/lang_de.json +++ b/public_html/deployment/plugins/rollout/ssh/lang_de.json @@ -2,13 +2,16 @@ "plugin_name": "SSH", "description": "Ein SSH Kommando auf einem Zielsystem starten.", - "user": "SSH User", + "section-required": "Erforderliche Angaben", "section-optional": "optionale Angaben", "section-commands": "Kommandos", - "privatekey": "Dateiname des Privatekeys", - "addkeycommand": "Hinzufügen in die known_hosts", - "command": "Kommando", - "testcommand": "Test-Remote-Kommando", - "project___": "" + + "formlabel-user": "SSH User", + "formlabel-command": "Kommando", + "formlabel-privatekey": "Dateiname des Privatekeys", + "formlabel-addkeycommand": "Hinzufügen in die known_hosts", + "formlabel-testcommand": "Test-Remote-Kommando", + + "endoffile": "" } \ No newline at end of file diff --git a/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php b/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php index a054a59db1e79d743a50e6c89fbe8e52d2be893f..0891a6d63172a5f891158da77ff1cdb9b3c6bbee 100644 --- a/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php +++ b/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php @@ -1,4 +1,5 @@ <?php + /** * * Rollout plugin - default @@ -12,7 +13,7 @@ class rollout_ssh extends rollout_base { /** * check requirements if the plugin could work */ - public function checkRequirements(){ + public function checkRequirements() { // no specific checks needed ... always true return true; } @@ -20,84 +21,104 @@ class rollout_ssh extends rollout_base { /** * check access to a deploy target */ - public function checkConnectionToTarget(){ + public function checkConnectionToTarget() { // do nothing ... always true return true; } - + /** * form fields for project settings * @return type */ - public function renderFormdata4Project() { - $sReturn=''; - $i=0; - - $sNamePrefix='plugins[rollout]['.$this->getId().']'; - $aValues=$this->getConfig(); + public function renderFormdata4Project() { + /* + $sReturn=''; + $i=0; + + $sNamePrefix='plugins[rollout]['.$this->getId().']'; + $aValues=$this->getConfig(); - $aFormdata=array( - array('type' => 'markup','value' => '<br>'.$this->_t('section-required').':'), - array( - 'type' => 'text', - 'name' => $sNamePrefix.'[user]', - 'label' => $this->_t('user'), - 'value' => $aValues['user'], - // 'required' => 'required', - 'validate' => 'isastring', - 'size' => 25, - 'placeholder' => $this->_aCfgGlobal['user'], - ), - array( - 'type' => 'text', - 'name' => $sNamePrefix.'[command]', - 'label' => $this->_t('command'), - 'value' => $aValues['command'], - // 'required' => 'required', - 'validate' => 'isastring', - // 'size' => 100, - 'placeholder' => $this->_aCfgGlobal['command'], - ), - array('type' => 'markup','value' => '<br><br>'.$this->_t('section-optional').':'), - array( - 'type' => 'text', - 'name' => $sNamePrefix.'[privatekey]', - 'label' => $this->_t('privatekey'), - 'value' => $aValues['privatekey'], - // 'required' => 'required', - 'validate' => 'isastring', - // 'size' => 100, - 'placeholder' => $this->_aCfgGlobal['privatekey'], - ), - array('type' => 'markup','value' => '<br><br>'.$this->_t('section-commands').':'), - array( - 'type' => 'text', - 'name' => $sNamePrefix.'[addkeycommand]', - 'label' => $this->_t('addkeycommand'), - 'value' => $aValues['addkeycommand'], - // 'required' => 'required', - 'validate' => 'isastring', - // 'size' => 100, - 'placeholder' => $this->_aCfgGlobal['addkeycommand'], - ), - array( - 'type' => 'text', - 'name' => $sNamePrefix.'[testcommand]', - 'label' => $this->_t('testcommand'), - 'value' => $aValues['testcommand'], - // 'required' => 'required', - 'validate' => 'isastring', - // 'size' => 100, - 'placeholder' => $this->_aCfgGlobal['testcommand'], - ), - ); + $aFormdata=array( + array('type' => 'markup','value' => '<br>'.$this->_t('section-required').':'), + array( + 'type' => 'text', + 'name' => $sNamePrefix.'[user]', + 'label' => $this->_t('user'), + 'value' => $aValues['user'], + // 'required' => 'required', + 'validate' => 'isastring', + 'size' => 25, + 'placeholder' => $this->_aCfgGlobal['user'], + ), + array( + 'type' => 'text', + 'name' => $sNamePrefix.'[command]', + 'label' => $this->_t('command'), + 'value' => $aValues['command'], + // 'required' => 'required', + 'validate' => 'isastring', + // 'size' => 100, + 'placeholder' => $this->_aCfgGlobal['command'], + ), + array('type' => 'markup','value' => '<br><br>'.$this->_t('section-optional').':'), + array( + 'type' => 'text', + 'name' => $sNamePrefix.'[privatekey]', + 'label' => $this->_t('privatekey'), + 'value' => $aValues['privatekey'], + // 'required' => 'required', + 'validate' => 'isastring', + // 'size' => 100, + 'placeholder' => $this->_aCfgGlobal['privatekey'], + ), + array('type' => 'markup','value' => '<br><br>'.$this->_t('section-commands').':'), + array( + 'type' => 'text', + 'name' => $sNamePrefix.'[addkeycommand]', + 'label' => $this->_t('addkeycommand'), + 'value' => $aValues['addkeycommand'], + // 'required' => 'required', + 'validate' => 'isastring', + // 'size' => 100, + 'placeholder' => $this->_aCfgGlobal['addkeycommand'], + ), + array( + 'type' => 'text', + 'name' => $sNamePrefix.'[testcommand]', + 'label' => $this->_t('testcommand'), + 'value' => $aValues['testcommand'], + // 'required' => 'required', + 'validate' => 'isastring', + // 'size' => 100, + 'placeholder' => $this->_aCfgGlobal['testcommand'], + ), + ); + * + */ - return 'WIP: config for plugin ['.$this->getId().']<br><br>' - . $this->_renderForm($aFormdata, 'project') + return 'WIP: project based setup for plugin [' . $this->getId() . ']<br>' + . $this->_renderFormGlobalVars($this->_sNamePrefix4Project, false) + // . $this->_renderForm($aFormdata, 'project') // .$sReturn - // .'<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = '.print_r($this->_aCfgGlobal, 1).'</pre>' - // .'<pre>DEBUG: PROJECT settings - $this->getConfig() = '.print_r($aValues, 1).'</pre>' - // .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>' - ; + . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>' + . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>' + // .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>' + ; + } + + /** + * form fields for project settings + * @return type + */ + public function renderFormdata4Phase($sMyPhase) { + return 'WIP: pase based setup for plugin [' . $this->getId() . '] in phase '.$sMyPhase.'<br>' + . $this->_renderFormGlobalVars('phases['.$sMyPhase.']'.$this->_sNamePrefix4Phase, $sMyPhase) + // . $this->_renderForm($aFormdata, 'project') + // .$sReturn + . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>' + . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>' + . '<pre>DEBUG: PHASE settings - $this->getConfig("'.$sMyPhase.'") = ' . print_r($this->getConfig($sMyPhase), 1) . '</pre>' + ; } + }