forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Show composer status in web validate. (librenms#8181)
* Show composer status in web validate. Don't duplicate in validate.php * Create variable to check if a group has been completed. No longer skips database checks. Extract a base class. Fix locate_binary and find_executable issues (mostly exposed by lack of db) * Update Validator.php
- Loading branch information
Showing
20 changed files
with
218 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* BaseValidation.php | ||
* | ||
* -Description- | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package LibreNMS | ||
* @link http://librenms.org | ||
* @copyright 2018 Tony Murray | ||
* @author Tony Murray <[email protected]> | ||
*/ | ||
|
||
namespace LibreNMS\Validations; | ||
|
||
use LibreNMS\Interfaces\ValidationGroup; | ||
|
||
abstract class BaseValidation implements ValidationGroup | ||
{ | ||
protected $completed = false; | ||
protected static $RUN_BY_DEFAULT = true; | ||
|
||
/** | ||
* Returns if this test should be run by default or not. | ||
* | ||
* @return bool | ||
*/ | ||
public function isDefault() | ||
{ | ||
return static::$RUN_BY_DEFAULT; | ||
} | ||
|
||
/** | ||
* Returns true if this group has been run | ||
* | ||
* @return bool | ||
*/ | ||
public function isCompleted() | ||
{ | ||
return $this->completed ; | ||
} | ||
|
||
/** | ||
* Mark this group as completed | ||
* | ||
* @return void | ||
*/ | ||
public function markCompleted() | ||
{ | ||
$this->completed = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Dependencies.php | ||
* | ||
* Checks libraries | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @package LibreNMS | ||
* @link http://librenms.org | ||
* @copyright 2018 Tony Murray | ||
* @author Tony Murray <[email protected]> | ||
*/ | ||
|
||
namespace LibreNMS\Validations; | ||
|
||
use LibreNMS\ValidationResult; | ||
use LibreNMS\Validator; | ||
|
||
class Dependencies extends BaseValidation | ||
{ | ||
/** | ||
* Validate this module. | ||
* To return ValidationResults, call ok, warn, fail, or result methods on the $validator | ||
* | ||
* @param Validator $validator | ||
*/ | ||
public function validate(Validator $validator) | ||
{ | ||
$composer_output = trim(shell_exec($validator->getBaseDir() . '/scripts/composer_wrapper.php --version')); | ||
$found = preg_match('/Composer version ([.0-9]+)/', $composer_output, $matches); | ||
|
||
if (!$found) { | ||
$validator->fail("No composer available, please install composer", "https://getcomposer.org/"); | ||
return; | ||
} else { | ||
$validator->ok("Composer Version: " . $matches[1]); | ||
} | ||
|
||
$dep_check = shell_exec($validator->getBaseDir() . '/scripts/composer_wrapper.php install --no-dev --dry-run'); | ||
preg_match_all('/Installing ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_missing); | ||
if (!empty($dep_missing[0])) { | ||
$result = ValidationResult::fail("Missing dependencies!", "composer install --no-dev"); | ||
$result->setList("Dependencies", $dep_missing[1]); | ||
$validator->result($result); | ||
} | ||
preg_match_all('/Updating ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_outdated); | ||
if (!empty($dep_outdated[0])) { | ||
$result = ValidationResult::fail("Outdated dependencies", "composer install --no-dev"); | ||
$result->setList("Dependencies", $dep_outdated[1]); | ||
} | ||
|
||
if (empty($dep_missing[0]) && empty($dep_outdated[0])) { | ||
$validator->ok("Dependencies up-to-date."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.