mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-13 19:33:09 +09:00
changes
This commit is contained in:
85
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/Authentication.php
vendored
Normal file
85
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/Authentication.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Github\HttpClient\Plugin;
|
||||
|
||||
use Github\Client;
|
||||
use Github\Exception\RuntimeException;
|
||||
use Http\Client\Common\Plugin;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Add authentication to the request.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class Authentication implements Plugin
|
||||
{
|
||||
private $tokenOrLogin;
|
||||
private $password;
|
||||
private $method;
|
||||
|
||||
public function __construct($tokenOrLogin, $password, $method)
|
||||
{
|
||||
$this->tokenOrLogin = $tokenOrLogin;
|
||||
$this->password = $password;
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleRequest(RequestInterface $request, callable $next, callable $first)
|
||||
{
|
||||
switch ($this->method) {
|
||||
case Client::AUTH_HTTP_PASSWORD:
|
||||
$request = $request->withHeader(
|
||||
'Authorization',
|
||||
sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password))
|
||||
);
|
||||
break;
|
||||
|
||||
case Client::AUTH_HTTP_TOKEN:
|
||||
$request = $request->withHeader('Authorization', sprintf('token %s', $this->tokenOrLogin));
|
||||
break;
|
||||
|
||||
case Client::AUTH_URL_CLIENT_ID:
|
||||
$uri = $request->getUri();
|
||||
$query = $uri->getQuery();
|
||||
|
||||
$parameters = [
|
||||
'client_id' => $this->tokenOrLogin,
|
||||
'client_secret' => $this->password,
|
||||
];
|
||||
|
||||
$query .= empty($query) ? '' : '&';
|
||||
$query .= utf8_encode(http_build_query($parameters, '', '&'));
|
||||
|
||||
$uri = $uri->withQuery($query);
|
||||
$request = $request->withUri($uri);
|
||||
break;
|
||||
|
||||
case Client::AUTH_URL_TOKEN:
|
||||
$uri = $request->getUri();
|
||||
$query = $uri->getQuery();
|
||||
|
||||
$parameters = ['access_token' => $this->tokenOrLogin];
|
||||
|
||||
$query .= empty($query) ? '' : '&';
|
||||
$query .= utf8_encode(http_build_query($parameters, '', '&'));
|
||||
|
||||
$uri = $uri->withQuery($query);
|
||||
$request = $request->withUri($uri);
|
||||
break;
|
||||
|
||||
case Client::AUTH_JWT:
|
||||
$request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->tokenOrLogin));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException(sprintf('%s not yet implemented', $this->method));
|
||||
break;
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
90
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
vendored
Normal file
90
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Github\HttpClient\Plugin;
|
||||
|
||||
use Github\Exception\ApiLimitExceedException;
|
||||
use Github\Exception\ErrorException;
|
||||
use Github\Exception\RuntimeException;
|
||||
use Github\Exception\TwoFactorAuthenticationRequiredException;
|
||||
use Github\Exception\ValidationFailedException;
|
||||
use Github\HttpClient\Message\ResponseMediator;
|
||||
use Http\Client\Common\Plugin;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class GithubExceptionThrower implements Plugin
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleRequest(RequestInterface $request, callable $next, callable $first)
|
||||
{
|
||||
return $next($request)->then(function (ResponseInterface $response) use ($request) {
|
||||
if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// If error:
|
||||
$remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining');
|
||||
if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) {
|
||||
$limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit');
|
||||
$reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset');
|
||||
|
||||
throw new ApiLimitExceedException($limit, $reset);
|
||||
}
|
||||
|
||||
if (401 === $response->getStatusCode()) {
|
||||
if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) {
|
||||
$type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9);
|
||||
|
||||
throw new TwoFactorAuthenticationRequiredException($type);
|
||||
}
|
||||
}
|
||||
|
||||
$content = ResponseMediator::getContent($response);
|
||||
if (is_array($content) && isset($content['message'])) {
|
||||
if (400 == $response->getStatusCode()) {
|
||||
throw new ErrorException($content['message'], 400);
|
||||
} elseif (422 == $response->getStatusCode() && isset($content['errors'])) {
|
||||
$errors = [];
|
||||
foreach ($content['errors'] as $error) {
|
||||
switch ($error['code']) {
|
||||
case 'missing':
|
||||
$errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']);
|
||||
break;
|
||||
|
||||
case 'missing_field':
|
||||
$errors[] = sprintf('Field "%s" is missing, for resource "%s"', $error['field'], $error['resource']);
|
||||
break;
|
||||
|
||||
case 'invalid':
|
||||
if (isset($error['message'])) {
|
||||
$errors[] = sprintf('Field "%s" is invalid, for resource "%s": "%s"', $error['field'], $error['resource'], $error['message']);
|
||||
} else {
|
||||
$errors[] = sprintf('Field "%s" is invalid, for resource "%s"', $error['field'], $error['resource']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'already_exists':
|
||||
$errors[] = sprintf('Field "%s" already exists, for resource "%s"', $error['field'], $error['resource']);
|
||||
break;
|
||||
|
||||
default:
|
||||
$errors[] = $error['message'];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
throw new ValidationFailedException('Validation Failed: '.implode(', ', $errors), 422);
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode());
|
||||
});
|
||||
}
|
||||
}
|
||||
38
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/History.php
vendored
Normal file
38
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/History.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Github\HttpClient\Plugin;
|
||||
|
||||
use Http\Client\Common\Plugin\Journal;
|
||||
use Http\Client\Exception;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* A plugin to remember the last response.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class History implements Journal
|
||||
{
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
private $lastResponse;
|
||||
|
||||
/**
|
||||
* @return ResponseInterface|null
|
||||
*/
|
||||
public function getLastResponse()
|
||||
{
|
||||
return $this->lastResponse;
|
||||
}
|
||||
|
||||
public function addSuccess(RequestInterface $request, ResponseInterface $response)
|
||||
{
|
||||
$this->lastResponse = $response;
|
||||
}
|
||||
|
||||
public function addFailure(RequestInterface $request, Exception $exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
38
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/PathPrepend.php
vendored
Normal file
38
vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/PathPrepend.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Github\HttpClient\Plugin;
|
||||
|
||||
use Http\Client\Common\Plugin;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Prepend the URI with a string.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class PathPrepend implements Plugin
|
||||
{
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleRequest(RequestInterface $request, callable $next, callable $first)
|
||||
{
|
||||
$currentPath = $request->getUri()->getPath();
|
||||
if (strpos($currentPath, $this->path) !== 0) {
|
||||
$uri = $request->getUri()->withPath($this->path.$currentPath);
|
||||
$request = $request->withUri($uri);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user