You've already forked Traefik-Redis-Api
Nothing to see here, move along
This commit is contained in:
@@ -71,21 +71,4 @@ class RoutesController extends Controller
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(['message' => 'Router deleted successfully']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function patch(ServerRequest $request): ResponseInterface
|
||||
{
|
||||
$name = $request->getAttribute('id');
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
try {
|
||||
RedisClient::patchEntity($name, $data, EntityEnum::ROUTER, $this->protocolEnumFromRequest($request));
|
||||
} catch (\InvalidArgumentException) {
|
||||
return JsonResponseFactory::createJsonResponse(['error' => 'Router not found'], 404);
|
||||
}
|
||||
|
||||
return JsonResponseFactory::createJsonResponse(['message' => 'Router updated successfully']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,6 @@ class Server
|
||||
$router->get('/', RoutesController::class . '::get');
|
||||
$router->get('/{id}', RoutesController::class . '::get');
|
||||
$router->post('/{id}', RoutesController::class . '::post');
|
||||
$router->patch('/{id}', RoutesController::class . '::patch');
|
||||
$router->delete('/{id}', RoutesController::class . '::delete');
|
||||
});
|
||||
|
||||
|
||||
@@ -41,66 +41,6 @@ class RedisClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @param EntityEnum $entity
|
||||
* @param ProtocolEnum $type
|
||||
* @return 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";
|
||||
|
||||
$keys = Redis::keys($checkKey . '/*');
|
||||
if (empty($keys)) {
|
||||
throw new \InvalidArgumentException("The key $checkKey does not exist.");
|
||||
}
|
||||
|
||||
$cleanedUpKeys = [];
|
||||
|
||||
foreach ($collection as $key => $value) {
|
||||
// regex if key matches [key].[digit]
|
||||
if (preg_match('/\.[0-9]+$/', $key)) {
|
||||
$arrayKey = preg_replace('/\.[0-9]+$/', '', $key);
|
||||
|
||||
if (in_array($arrayKey, $cleanedUpKeys)) {
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() .
|
||||
'/' .
|
||||
$entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// key is an array, delete keys under array
|
||||
$arrayKeys = Redis::keys($checkKey . '/' . str_replace('.', '/', $arrayKey) . '/*');
|
||||
foreach ($arrayKeys as $k) {
|
||||
Redis::del($k);
|
||||
}
|
||||
|
||||
$cleanedUpKeys[] = $arrayKey;
|
||||
}
|
||||
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() . '/' . $entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param EntityEnum $entity
|
||||
|
||||
Reference in New Issue
Block a user