diff --git a/config/packages/lexik_jwt_authentication.yaml b/config/packages/lexik_jwt_authentication.yaml index c813308..88ae582 100644 --- a/config/packages/lexik_jwt_authentication.yaml +++ b/config/packages/lexik_jwt_authentication.yaml @@ -2,6 +2,7 @@ lexik_jwt_authentication: secret_key: '%env(resolve:JWT_SECRET_KEY)%' public_key: '%env(resolve:JWT_PUBLIC_KEY)%' pass_phrase: '%env(JWT_PASSPHRASE)%' + token_ttl: 86400 # 1 day api_platform: check_path: /auth/login username_path: username diff --git a/src/Controller/OgRepository/Image/TransferIsGlobalAction.php b/src/Controller/OgRepository/Image/TransferIsGlobalAction.php new file mode 100644 index 0000000..57b7cfb --- /dev/null +++ b/src/Controller/OgRepository/Image/TransferIsGlobalAction.php @@ -0,0 +1,84 @@ +entityManager->getRepository(ImageImageRepository::class)->findOneBy(['image' => $image, 'repository' => $repository]); + $content = $this->createRequest('GET', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/'.$imageImageRepository->getImageFullsum()); + + $this->logger->info('Image already exists', ['image' => $imageImageRepository->getImage()->getName(), 'repository' => $repository->getIp()]); + continue; + } catch ( \Exception $e) { + + } + + /* @var Image $image */ + $image = $imageImageRepository->getImage(); + + if (!$imageImageRepository->getImageFullsum()) { + throw new ValidatorException('Fullsum is required'); + } + + $params = [ + 'json' => [ + 'image' => $image->getName().'.img', + 'repo_ip' => $image->getClient()->getRepository()->getIp(), + 'user' => 'opengnsys', + ] + ]; + + $this->logger->info('Importing image', ['image' => $image->getName(), 'repository' => $repository->getIp()]); + + $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params); + + if (!isset($content['job_id'])) { + throw new ValidatorException('Job ID not found'); + } + + $inputData = [ + 'imageName' => $image->getName(), + 'imageUuid' => $image->getUuid(), + 'imageImageRepositoryUuid' => $imageImageRepository->getUuid(), + 'repositoryUuid' => $repository->getUuid(), + ]; + + $this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + + $imageImageRepository->setStatus(ImageStatus::TRANSFERRING); + $this->entityManager->persist($image); + $this->entityManager->flush(); + } + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index ccb203d..e2033c7 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -10,24 +10,31 @@ use ApiPlatform\Metadata\Put; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\Validator\ValidatorInterface; use App\Controller\OgAgent\CreateImageAction; +use App\Controller\OgRepository\Image\TransferAction; +use App\Controller\OgRepository\Image\TransferIsGlobalAction; use App\Dto\Input\ImageInput; use App\Dto\Input\ImageRepositoryInput; use App\Dto\Output\ImageOutput; use App\Entity\ImageImageRepository; use App\Repository\ImageRepository; +use App\Repository\ImageRepositoryRepository as ImageRepositoryRepository; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; readonly class ImageProcessor implements ProcessorInterface { public function __construct( - private ImageRepository $imageRepository, - private ValidatorInterface $validator, - private CreateImageAction $createImageActionController + private ImageRepositoryRepository $imageRepositoryRepository, + private ImageRepository $imageRepository, + private ValidatorInterface $validator, + private CreateImageAction $createImageActionController, + private TransferIsGlobalAction $transferActionController ) { } /** * @throws \Exception + * @throws TransportExceptionInterface */ public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput|null { @@ -43,6 +50,7 @@ readonly class ImageProcessor implements ProcessorInterface /** * @throws \Exception + * @throws TransportExceptionInterface */ private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput { @@ -60,6 +68,11 @@ readonly class ImageProcessor implements ProcessorInterface if ($data->source !== 'input') { $response = $this->createImageActionController->__invoke($image); + } else { + if ($data->isGlobal === true) { + $repositories = $this->imageRepositoryRepository->findAll(); + $this->transferActionController->__invoke($repositories, $image); + } } $this->imageRepository->save($image);