You've already forked Traefik-Redis-Api
This is not a commit
This commit is contained in:
@@ -10,7 +10,6 @@ use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
abstract class Controller implements ControllerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ServerRequest $request
|
||||
* @return ResponseInterface
|
||||
@@ -44,4 +43,4 @@ abstract class Controller implements ControllerInterface
|
||||
{
|
||||
throw new NotFoundException("not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ interface ControllerInterface
|
||||
* Handle the request and return a response.
|
||||
*
|
||||
* @param ServerRequest $request The request data.
|
||||
* @return mixed The response data.
|
||||
* @return ResponseInterface The response data.
|
||||
*/
|
||||
public function get(ServerRequest $request): ResponseInterface;
|
||||
|
||||
@@ -21,7 +21,7 @@ interface ControllerInterface
|
||||
* Handle the request and return a response.
|
||||
*
|
||||
* @param ServerRequest $request The request data.
|
||||
* @return mixed The response data.
|
||||
* @return ResponseInterface The response data.
|
||||
*/
|
||||
public function post(ServerRequest $request): ResponseInterface;
|
||||
|
||||
@@ -29,7 +29,7 @@ interface ControllerInterface
|
||||
* Handle the request and return a response.
|
||||
*
|
||||
* @param ServerRequest $request The request data.
|
||||
* @return mixed The response data.
|
||||
* @return ResponseInterface The response data.
|
||||
*/
|
||||
public function delete(ServerRequest $request): ResponseInterface;
|
||||
|
||||
@@ -37,7 +37,7 @@ interface ControllerInterface
|
||||
* Handle the request and return a response.
|
||||
*
|
||||
* @param ServerRequest $request The request data.
|
||||
* @return mixed The response data.
|
||||
* @return ResponseInterface The response data.
|
||||
*/
|
||||
public function patch(ServerRequest $request): ResponseInterface;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient;
|
||||
|
||||
class MiddlewaresController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
@@ -60,4 +59,4 @@ class MiddlewaresController extends Controller
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(['message' => 'Middleware deleted successfully']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient;
|
||||
|
||||
class RoutesController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
@@ -78,4 +77,4 @@ class RoutesController extends Controller
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(['message' => 'Router updated successfully']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use Siteworxpro\App\Traefik\RedisClient;
|
||||
|
||||
class ServicesController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
@@ -60,4 +59,4 @@ class ServicesController extends Controller
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(['message' => 'Service deleted successfully']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ use Predis\Response\Status;
|
||||
*/
|
||||
class Redis extends Facade
|
||||
{
|
||||
|
||||
public static function getFacadeRoot(): Client
|
||||
{
|
||||
if (self::$resolvedInstance !== null) {
|
||||
@@ -50,4 +49,4 @@ class Redis extends Facade
|
||||
{
|
||||
return Client::class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ enum EntityEnum
|
||||
self::MIDDLEWARE => 'middlewares',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ enum ProtocolEnum
|
||||
self::UDP => 'udp',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,23 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return void
|
||||
*/
|
||||
public static function createOrReplace(string $name, array $data, EntityEnum $entity, ProtocolEnum $type = ProtocolEnum::HTTP): void
|
||||
{
|
||||
public static function createOrReplace(
|
||||
string $name,
|
||||
array $data,
|
||||
EntityEnum $entity,
|
||||
ProtocolEnum $type = ProtocolEnum::HTTP
|
||||
): void {
|
||||
self::deleteAllKeys($name, $entity, $type);
|
||||
|
||||
$collection = self::flattenToDotArray($data);
|
||||
|
||||
foreach ($collection as $key => $value) {
|
||||
$redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key);
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() . '/' .
|
||||
$entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
}
|
||||
}
|
||||
@@ -39,8 +48,12 @@ class RedisClient
|
||||
* @param ProtocolEnum $type
|
||||
* @return void
|
||||
*/
|
||||
public static function patchEntity(string $name, array $data, EntityEnum $entity, ProtocolEnum $type = ProtocolEnum::HTTP): void
|
||||
{
|
||||
public static function patchEntity(
|
||||
string $name,
|
||||
array $data,
|
||||
EntityEnum $entity,
|
||||
ProtocolEnum $type = ProtocolEnum::HTTP
|
||||
): void {
|
||||
$collection = self::flattenToDotArray($data);
|
||||
|
||||
$checkKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name";
|
||||
@@ -58,7 +71,13 @@ class RedisClient
|
||||
$arrayKey = preg_replace('/\.[0-9]+$/', '', $key);
|
||||
|
||||
if (in_array($arrayKey, $cleanedUpKeys)) {
|
||||
$redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key);
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() .
|
||||
'/' .
|
||||
$entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
|
||||
continue;
|
||||
@@ -73,7 +92,11 @@ class RedisClient
|
||||
$cleanedUpKeys[] = $arrayKey;
|
||||
}
|
||||
|
||||
$redisKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name/" . str_replace('.', '/', $key);
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() . '/' . $entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
}
|
||||
}
|
||||
@@ -84,8 +107,11 @@ class RedisClient
|
||||
* @param ProtocolEnum $protocol
|
||||
* @return bool
|
||||
*/
|
||||
public static function deleteAllKeys(string $name, EntityEnum $entity, ProtocolEnum $protocol = ProtocolEnum::HTTP): bool
|
||||
{
|
||||
public static function deleteAllKeys(
|
||||
string $name,
|
||||
EntityEnum $entity,
|
||||
ProtocolEnum $protocol = ProtocolEnum::HTTP
|
||||
): bool {
|
||||
$pattern = 'traefik/' . $protocol->getValue() . '/' . $entity->getValue() . "/$name/*";
|
||||
|
||||
foreach (new Keyspace(Redis::getFacadeRoot(), $pattern) as $key) {
|
||||
@@ -214,4 +240,4 @@ class RedisClient
|
||||
|
||||
return $collection->dot()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user