mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-27 20:11:34 +03:00
Registered middleware generating request ID
This commit is contained in:
parent
f53fa5c90f
commit
bb231e668b
5 changed files with 40 additions and 12 deletions
|
@ -45,8 +45,10 @@
|
||||||
"nikolaposa/monolog-factory": "^3.0",
|
"nikolaposa/monolog-factory": "^3.0",
|
||||||
"ocramius/proxy-manager": "^2.7.0",
|
"ocramius/proxy-manager": "^2.7.0",
|
||||||
"phly/phly-event-dispatcher": "^1.0",
|
"phly/phly-event-dispatcher": "^1.0",
|
||||||
|
"php-middleware/request-id": "^4.0",
|
||||||
"predis/predis": "^1.1",
|
"predis/predis": "^1.1",
|
||||||
"pugx/shortid-php": "^0.5",
|
"pugx/shortid-php": "^0.5",
|
||||||
|
"ramsey/uuid": "^3.9",
|
||||||
"shlinkio/shlink-common": "^2.7.0",
|
"shlinkio/shlink-common": "^2.7.0",
|
||||||
"shlinkio/shlink-event-dispatcher": "^1.3",
|
"shlinkio/shlink-event-dispatcher": "^1.3",
|
||||||
"shlinkio/shlink-installer": "^4.2.0",
|
"shlinkio/shlink-installer": "^4.2.0",
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Shlinkio\Shlink;
|
||||||
use Laminas\Stratigility\Middleware\ErrorHandler;
|
use Laminas\Stratigility\Middleware\ErrorHandler;
|
||||||
use Mezzio;
|
use Mezzio;
|
||||||
use Mezzio\ProblemDetails;
|
use Mezzio\ProblemDetails;
|
||||||
|
use PhpMiddleware\RequestId\RequestIdMiddleware;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ return [
|
||||||
'path' => '/rest',
|
'path' => '/rest',
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
Rest\Middleware\CrossDomainMiddleware::class,
|
Rest\Middleware\CrossDomainMiddleware::class,
|
||||||
|
RequestIdMiddleware::class,
|
||||||
ProblemDetails\ProblemDetailsMiddleware::class,
|
ProblemDetails\ProblemDetailsMiddleware::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
33
config/autoload/request_id.global.php
Normal file
33
config/autoload/request_id.global.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||||
|
use Laminas\ServiceManager\Factory\InvokableFactory;
|
||||||
|
use PhpMiddleware\RequestId;
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
'request_id' => [
|
||||||
|
'allow_override' => true,
|
||||||
|
'header_name' => 'X-Request-Id',
|
||||||
|
],
|
||||||
|
|
||||||
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
RequestId\Generator\RamseyUuid4StaticGenerator::class => InvokableFactory::class,
|
||||||
|
RequestId\RequestIdProviderFactory::class => ConfigAbstractFactory::class,
|
||||||
|
RequestId\RequestIdMiddleware::class => ConfigAbstractFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
ConfigAbstractFactory::class => [
|
||||||
|
RequestId\RequestIdProviderFactory::class => [
|
||||||
|
RequestId\Generator\RamseyUuid4StaticGenerator::class,
|
||||||
|
'config.request_id.allow_override',
|
||||||
|
'config.request_id.header_name',
|
||||||
|
],
|
||||||
|
RequestId\RequestIdMiddleware::class => [RequestId\RequestIdProviderFactory::class],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
|
@ -5,14 +5,11 @@ declare(strict_types=1);
|
||||||
namespace Shlinkio\Shlink\Core\Options;
|
namespace Shlinkio\Shlink\Core\Options;
|
||||||
|
|
||||||
use Laminas\Stdlib\AbstractOptions;
|
use Laminas\Stdlib\AbstractOptions;
|
||||||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class AppOptions extends AbstractOptions
|
class AppOptions extends AbstractOptions
|
||||||
{
|
{
|
||||||
use StringUtilsTrait;
|
|
||||||
|
|
||||||
private string $name = '';
|
private string $name = '';
|
||||||
private string $version = '1.0';
|
private string $version = '1.0';
|
||||||
private ?string $disableTrackParam = null;
|
private ?string $disableTrackParam = null;
|
||||||
|
|
|
@ -5,20 +5,18 @@ declare(strict_types=1);
|
||||||
namespace Shlinkio\Shlink\Rest\Entity;
|
namespace Shlinkio\Shlink\Rest\Entity;
|
||||||
|
|
||||||
use Cake\Chronos\Chronos;
|
use Cake\Chronos\Chronos;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
|
||||||
|
|
||||||
class ApiKey extends AbstractEntity
|
class ApiKey extends AbstractEntity
|
||||||
{
|
{
|
||||||
use StringUtilsTrait;
|
|
||||||
|
|
||||||
private string $key;
|
private string $key;
|
||||||
private ?Chronos $expirationDate;
|
private ?Chronos $expirationDate;
|
||||||
private bool $enabled;
|
private bool $enabled;
|
||||||
|
|
||||||
public function __construct(?Chronos $expirationDate = null)
|
public function __construct(?Chronos $expirationDate = null)
|
||||||
{
|
{
|
||||||
$this->key = $this->generateV4Uuid();
|
$this->key = Uuid::uuid4()->toString();
|
||||||
$this->expirationDate = $expirationDate;
|
$this->expirationDate = $expirationDate;
|
||||||
$this->enabled = true;
|
$this->enabled = true;
|
||||||
}
|
}
|
||||||
|
@ -30,11 +28,7 @@ class ApiKey extends AbstractEntity
|
||||||
|
|
||||||
public function isExpired(): bool
|
public function isExpired(): bool
|
||||||
{
|
{
|
||||||
if ($this->expirationDate === null) {
|
return $this->expirationDate !== null && $this->expirationDate->lt(Chronos::now());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->expirationDate->lt(Chronos::now());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEnabled(): bool
|
public function isEnabled(): bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue