- added minimal SDE dump (EVE Online: Citadel)
- #147 improved CREST API error logging (WIP) - improved SSO controller (removed access_token from public endpoints)
This commit is contained in:
@@ -22,7 +22,7 @@ DB_PASS =
|
||||
|
||||
; EVE-Online CCP Database export
|
||||
DB_CCP_DNS = mysql:host=localhost;port=3306;dbname=
|
||||
DB_CCP_NAME = eve_parallax_min
|
||||
DB_CCP_NAME = eve_citadel_min
|
||||
DB_CCP_USER = root
|
||||
DB_CCP_PASS =
|
||||
|
||||
|
||||
@@ -479,19 +479,19 @@ class Sso extends Api\User{
|
||||
protected function getEndpoints($accessToken = '', $additionalOptions = []){
|
||||
$crestUrl = self::getCrestEndpoint();
|
||||
$additionalOptions['contentType'] = 'application/vnd.ccp.eve.Api-v3+json';
|
||||
$endpoint = $this->getEndpoint($accessToken, $crestUrl, $additionalOptions);
|
||||
$endpoint = $this->getEndpoint($crestUrl, $accessToken, $additionalOptions);
|
||||
|
||||
return $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a specific endpoint by its $resourceUrl
|
||||
* @param string $accessToken CREST access token
|
||||
* @param string $resourceUrl endpoint API url
|
||||
* @param string $accessToken CREST access token
|
||||
* @param array $additionalOptions optional request options (pathfinder specific)
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function getEndpoint($accessToken, $resourceUrl, $additionalOptions = []){
|
||||
protected function getEndpoint($resourceUrl, $accessToken = '', $additionalOptions = []){
|
||||
$resourceUrlParts = parse_url($resourceUrl);
|
||||
$endpoint = null;
|
||||
|
||||
@@ -501,12 +501,16 @@ class Sso extends Api\User{
|
||||
'method' => 'GET',
|
||||
'user_agent' => $this->getUserAgent(),
|
||||
'header' => [
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'Host: login.eveonline.com',
|
||||
'Host: ' . $resourceUrlParts['host']
|
||||
]
|
||||
];
|
||||
|
||||
// some endpoints don´t require an "access_token" (e.g. public crest data)
|
||||
if( !empty($accessToken) ){
|
||||
$requestOptions['header'][] = 'Authorization: Bearer ' . $accessToken;
|
||||
}
|
||||
|
||||
// if specific contentType is required -> add it to request header
|
||||
// CREST versioning can be done by calling different "Accept:" Headers
|
||||
if( isset($additionalOptions['contentType']) ){
|
||||
@@ -538,13 +542,13 @@ class Sso extends Api\User{
|
||||
/**
|
||||
* recursively walk down the CREST API tree by a given $path array
|
||||
* -> return "leaf" endpoint
|
||||
* @param $accessToken
|
||||
* @param $endpoint
|
||||
* @param $accessToken
|
||||
* @param array $path
|
||||
* @param array $additionalOptions
|
||||
* @return null
|
||||
*/
|
||||
protected function walkEndpoint($accessToken, $endpoint, $path = [], $additionalOptions = []){
|
||||
protected function walkEndpoint($endpoint, $accessToken, $path = [], $additionalOptions = []){
|
||||
$targetEndpoint = null;
|
||||
|
||||
if( !empty($path) ){
|
||||
@@ -552,8 +556,8 @@ class Sso extends Api\User{
|
||||
if(isset($endpoint[$newNode])){
|
||||
$currentEndpoint = $endpoint[$newNode];
|
||||
if(isset($currentEndpoint['href'])){
|
||||
$newEndpoint = $this->getEndpoint($accessToken, $currentEndpoint['href'], $additionalOptions);
|
||||
$targetEndpoint = $this->walkEndpoint($accessToken, $newEndpoint, $path, $additionalOptions);
|
||||
$newEndpoint = $this->getEndpoint($currentEndpoint['href'], $accessToken, $additionalOptions);
|
||||
$targetEndpoint = $this->walkEndpoint($newEndpoint, $accessToken, $path, $additionalOptions);
|
||||
}else{
|
||||
// leaf found
|
||||
$targetEndpoint = $currentEndpoint;
|
||||
@@ -579,7 +583,7 @@ class Sso extends Api\User{
|
||||
$endpoints = $this->getEndpoints($accessToken, $additionalOptions);
|
||||
$characterData = (object) [];
|
||||
|
||||
$endpoint = $this->walkEndpoint($accessToken, $endpoints, [
|
||||
$endpoint = $this->walkEndpoint($endpoints, $accessToken, [
|
||||
'decode',
|
||||
'character'
|
||||
], $additionalOptions);
|
||||
@@ -615,7 +619,7 @@ class Sso extends Api\User{
|
||||
if( !$this->getF3()->exists($cacheKey) ){
|
||||
$endpoints = $this->getEndpoints($accessToken, $additionalOptions);
|
||||
|
||||
$endpoint = $this->walkEndpoint($accessToken, $endpoints, [
|
||||
$endpoint = $this->walkEndpoint($endpoints, $accessToken, [
|
||||
'decode',
|
||||
'character',
|
||||
'location'
|
||||
@@ -711,18 +715,18 @@ class Sso extends Api\User{
|
||||
'eve' => 0
|
||||
];
|
||||
|
||||
$endpoint = $this->walkEndpoint('', $endpoints, ['serverName']);
|
||||
$endpoint = $this->walkEndpoint($endpoints, '', ['serverName']);
|
||||
if( !empty($endpoint) ){
|
||||
$data->crestOffline = false;
|
||||
$data->serverName = (string) $endpoint;
|
||||
}
|
||||
$endpoint = $this->walkEndpoint('', $endpoints, ['serviceStatus']);
|
||||
$endpoint = $this->walkEndpoint($endpoints, '', ['serviceStatus']);
|
||||
if( !empty($endpoint) ){
|
||||
$data->crestOffline = false;
|
||||
$data->serviceStatus = (new Mapper\CrestServiceStatus($endpoint))->getData();
|
||||
}
|
||||
|
||||
$endpoint = $this->walkEndpoint('', $endpoints, ['userCounts']);
|
||||
$endpoint = $this->walkEndpoint($endpoints, '', ['userCounts']);
|
||||
if( !empty($endpoint) ){
|
||||
$data->crestOffline = false;
|
||||
$data->userCounts = (new Mapper\CrestUserCounts($endpoint))->getData();
|
||||
|
||||
@@ -12,10 +12,7 @@ use controller\LogController;
|
||||
|
||||
class Web extends \Web {
|
||||
|
||||
const ERROR_DEFAULT_MSG = 'method: \'%s\', url: \'%s\'';
|
||||
const ERROR_STATUS_UNKNOWN = 'HTTP response - unknown HTTP status: \'%s\'. url: \'%s\'';
|
||||
const ERROR_TIMEOUT = 'Request timeout \'%ss\'. url: \'%s\'';
|
||||
|
||||
const ERROR_STATUS_LOG = 'HTTP %s: \'%s\' | url: %s \'%s\'%s';
|
||||
|
||||
/**
|
||||
* end of line
|
||||
@@ -28,7 +25,7 @@ class Web extends \Web {
|
||||
* @param array $headers
|
||||
* @return int
|
||||
*/
|
||||
protected function getStatuscodeFromHeaders($headers = []){
|
||||
protected function getStatusCodeFromHeaders($headers = []){
|
||||
$statusCode = 0;
|
||||
|
||||
if(
|
||||
@@ -103,7 +100,7 @@ class Web extends \Web {
|
||||
if( !$f3->exists( $hash = $this->getCacheKey($url, $options) ) ){
|
||||
$result = parent::request($url, $options);
|
||||
$result['timeout'] = false;
|
||||
$statusCode = $this->getStatuscodeFromHeaders( $result['headers'] );
|
||||
$statusCode = $this->getStatusCodeFromHeaders( $result['headers'] );
|
||||
|
||||
switch($statusCode){
|
||||
case 200:
|
||||
@@ -117,40 +114,62 @@ class Web extends \Web {
|
||||
$f3->set($hash, $result, $ttl);
|
||||
}
|
||||
break;
|
||||
case 401:
|
||||
case 415:
|
||||
// unauthorized
|
||||
$errorMsg = $this->getErrorMessageFromJsonResponse(
|
||||
$statusCode,
|
||||
$options['method'],
|
||||
$url,
|
||||
json_decode($result['body'])
|
||||
);
|
||||
LogController::getLogger('error')->write($errorMsg);
|
||||
break;
|
||||
case 500:
|
||||
case 501:
|
||||
case 502:
|
||||
case 503:
|
||||
case 505:
|
||||
$f3->error($statusCode, $this->getErrorMessageFromJsonResponse(
|
||||
$errorMsg = $this->getErrorMessageFromJsonResponse(
|
||||
$statusCode,
|
||||
$options['method'],
|
||||
$url,
|
||||
json_decode($result['body'])
|
||||
));
|
||||
);
|
||||
LogController::getLogger('error')->write($errorMsg);
|
||||
|
||||
// trigger error
|
||||
$f3->error($statusCode, $errorMsg);
|
||||
break;
|
||||
case 504:
|
||||
case 0:
|
||||
// timeout -> response should not be cached
|
||||
$result['timeout'] = true;
|
||||
|
||||
if($additionalOptions['suppressTimeoutErrors'] !== true){
|
||||
// set error...
|
||||
$f3->error(504, $this->getErrorMessageFromJsonResponse(
|
||||
$options['method'],
|
||||
$url
|
||||
));
|
||||
}
|
||||
$errorMsg = $this->getErrorMessageFromJsonResponse(
|
||||
504,
|
||||
$options['method'],
|
||||
$url,
|
||||
json_decode($result['body'])
|
||||
);
|
||||
|
||||
// log error
|
||||
LogController::getLogger('error')->write(
|
||||
sprintf(self::ERROR_TIMEOUT, $options['timeout'], $url)
|
||||
);
|
||||
LogController::getLogger('error')->write($errorMsg);
|
||||
|
||||
if($additionalOptions['suppressTimeoutErrors'] !== true){
|
||||
// trigger error
|
||||
$f3->error(504, $errorMsg);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// unknown status
|
||||
LogController::getLogger('error')->write(
|
||||
sprintf(self::ERROR_STATUS_UNKNOWN, $statusCode, $url)
|
||||
$errorMsg = $this->getErrorMessageFromJsonResponse(
|
||||
$statusCode,
|
||||
$options['method'],
|
||||
$url
|
||||
);
|
||||
|
||||
LogController::getLogger('error')->write($errorMsg);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
@@ -162,19 +181,25 @@ class Web extends \Web {
|
||||
|
||||
/**
|
||||
* get error message from response object
|
||||
* @param $method
|
||||
* @param $url
|
||||
* @param int $code
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param null|\stdClass $responseBody
|
||||
* @return string
|
||||
*/
|
||||
protected function getErrorMessageFromJsonResponse($method, $url, $responseBody = null){
|
||||
protected function getErrorMessageFromJsonResponse($code, $method, $url, $responseBody = null){
|
||||
if( empty($responseBody->message) ){
|
||||
$message = sprintf(self::ERROR_DEFAULT_MSG, $method, $url);
|
||||
$message = @constant('Base::HTTP_' . $code);
|
||||
}else{
|
||||
$message = $responseBody->message . ', url: \'' . $url . '\'';
|
||||
$message = $responseBody->message;
|
||||
}
|
||||
|
||||
return $message;
|
||||
$body = '';
|
||||
if( !is_null($responseBody) ){
|
||||
$body = ' | body: ' . print_r($responseBody, true);
|
||||
}
|
||||
|
||||
return sprintf(self::ERROR_STATUS_LOG, $code, $message, $method, $url, $body);
|
||||
}
|
||||
|
||||
}
|
||||
BIN
export/sql/eve_citadel_min.sql.zip
Normal file
BIN
export/sql/eve_citadel_min.sql.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user