1
0
Fork 0

Skip all network-based checks (#7641)

* Skip all network-based checks

Change the warnings in diagnose to a friendly messages when allow_url_fopen is disabled.

Issue: #7622
pull/7762/head
Ahammar Yassine 2018-10-31 16:32:02 +00:00 committed by Jordi Boggiano
parent 0ee0138bed
commit da94e4b619
1 changed files with 61 additions and 4 deletions

View File

@ -119,8 +119,9 @@ EOT
$io->write('Checking github.com rate limit: ', false); $io->write('Checking github.com rate limit: ', false);
try { try {
$rate = $this->getGithubRateLimit('github.com'); $rate = $this->getGithubRateLimit('github.com');
$this->outputResult(true); if (!is_array($rate)) {
if (10 > $rate['remaining']) { $this->outputResult($rate);
} elseif (10 > $rate['remaining']) {
$io->writeError('<warning>WARNING</warning>'); $io->writeError('<warning>WARNING</warning>');
$io->writeError(sprintf( $io->writeError(sprintf(
'<comment>Github has a rate limit on their API. ' '<comment>Github has a rate limit on their API. '
@ -131,6 +132,8 @@ EOT
$rate['remaining'], $rate['remaining'],
$rate['limit'] $rate['limit']
)); ));
} else {
$this->outputResult(true);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if ($e instanceof TransportException && $e->getCode() === 401) { if ($e instanceof TransportException && $e->getCode() === 401) {
@ -207,6 +210,11 @@ EOT
private function checkHttp($proto, Config $config) private function checkHttp($proto, Config $config)
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
$disableTls = false; $disableTls = false;
$result = array(); $result = array();
if ($proto === 'https' && $config->get('disable-tls') === true) { if ($proto === 'https' && $config->get('disable-tls') === true) {
@ -238,6 +246,11 @@ EOT
private function checkHttpProxy() private function checkHttpProxy()
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
$protocol = extension_loaded('openssl') ? 'https' : 'http'; $protocol = extension_loaded('openssl') ? 'https' : 'http';
try { try {
$json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://repo.packagist.org/packages.json', false), true); $json = json_decode($this->rfs->getContents('packagist.org', $protocol . '://repo.packagist.org/packages.json', false), true);
@ -265,6 +278,11 @@ EOT
*/ */
private function checkHttpProxyFullUriRequestParam() private function checkHttpProxyFullUriRequestParam()
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
$url = 'http://repo.packagist.org/packages.json'; $url = 'http://repo.packagist.org/packages.json';
try { try {
$this->rfs->getContents('packagist.org', $url, false); $this->rfs->getContents('packagist.org', $url, false);
@ -290,6 +308,11 @@ EOT
*/ */
private function checkHttpsProxyFullUriRequestParam() private function checkHttpsProxyFullUriRequestParam()
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
if (!extension_loaded('openssl')) { if (!extension_loaded('openssl')) {
return 'You need the openssl extension installed for this check'; return 'You need the openssl extension installed for this check';
} }
@ -312,6 +335,11 @@ EOT
private function checkGithubOauth($domain, $token) private function checkGithubOauth($domain, $token)
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic'); $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
try { try {
$url = $domain === 'github.com' ? 'https://api.'.$domain.'/' : 'https://'.$domain.'/api/v3/'; $url = $domain === 'github.com' ? 'https://api.'.$domain.'/' : 'https://'.$domain.'/api/v3/';
@ -332,10 +360,15 @@ EOT
* @param string $domain * @param string $domain
* @param string $token * @param string $token
* @throws TransportException * @throws TransportException
* @return array * @return array|string
*/ */
private function getGithubRateLimit($domain, $token = null) private function getGithubRateLimit($domain, $token = null)
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
if ($token) { if ($token) {
$this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic'); $this->getIO()->setAuthentication($domain, $token, 'x-oauth-basic');
} }
@ -390,6 +423,11 @@ EOT
private function checkVersion($config) private function checkVersion($config)
{ {
$result = $this->checkConnectivity();
if ($result !== true) {
return $result;
}
$versionsUtil = new Versions($config, $this->rfs); $versionsUtil = new Versions($config, $this->rfs);
$latest = $versionsUtil->getLatest(); $latest = $versionsUtil->getLatest();
@ -413,6 +451,7 @@ EOT
} }
$hadError = false; $hadError = false;
$hadWarning = false;
if ($result instanceof \Exception) { if ($result instanceof \Exception) {
$result = '<error>['.get_class($result).'] '.$result->getMessage().'</error>'; $result = '<error>['.get_class($result).'] '.$result->getMessage().'</error>';
} }
@ -427,6 +466,8 @@ EOT
foreach ($result as $message) { foreach ($result as $message) {
if (false !== strpos($message, '<error>')) { if (false !== strpos($message, '<error>')) {
$hadError = true; $hadError = true;
} elseif (false !== strpos($message, '<warning>')) {
$hadWarning = true;
} }
} }
} }
@ -434,7 +475,7 @@ EOT
if ($hadError) { if ($hadError) {
$io->write('<error>FAIL</error>'); $io->write('<error>FAIL</error>');
$this->exitCode = 2; $this->exitCode = 2;
} else { } elseif ($hadWarning) {
$io->write('<warning>WARNING</warning>'); $io->write('<warning>WARNING</warning>');
$this->exitCode = 1; $this->exitCode = 1;
} }
@ -668,4 +709,20 @@ EOT
return !$warnings && !$errors ? true : $output; return !$warnings && !$errors ? true : $output;
} }
/**
* Check if allow_url_fopen is ON
*
* @return bool|string
*/
private function checkConnectivity()
{
if (!ini_get('allow_url_fopen')) {
$result = '<info>Skipped because allow_url_fopen is missing.</info>';
return $result;
}
return true;
}
} }