Compare commits

..

22 Commits

Author SHA1 Message Date
dcherednik b7d24cd749 Merge pull request 'DDB-1753' (#5) from DDB-1753 into master
build (signer) TeamCity build finished Details
Reviewed-on: #5
2025-03-21 13:37:34 +03:00
cherednik a4a12752b8 DDB-1753: fix response
build (signer) TeamCity build finished Details
2025-03-21 13:43:09 +04:00
cherednik 6533368534 DDB-1753: fix response 2025-03-21 13:40:10 +04:00
StSet 82ae1cbdf8 DDB-1753 - доработка формата ответа для сервиса подписания - fix 2025-03-21 12:32:57 +03:00
StSet 6943c9c41f DDB-1753 - доработка формата ответа для сервиса подписания - fix 2025-03-21 12:27:37 +03:00
StSet 52d40c6249 DDB-1753 - доработка формата ответа для сервиса подписания 2025-03-21 12:15:22 +03:00
cherednik 484dd35faa DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] - ПОДПИСАНИЕ КРИПТО ПРО fix nginx
build (signer) TeamCity build finished Details
2025-03-10 16:56:17 +04:00
cherednik 73d6b04a10 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] - ПОДПИСАНИЕ КРИПТО ПРО fix nginx 2025-03-10 16:50:54 +04:00
dcherednik bbe7d1b7fe Merge branch 'master' into DD-3602 2025-03-10 14:23:05 +03:00
cherednik 2dd08fcaac DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-10 13:31:54 +04:00
cherednik cea9bdedaf DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-10 12:29:02 +04:00
cherednik c51d199b51 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 20:00:11 +04:00
cherednik c4c29fa2a7 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 19:56:50 +04:00
cherednik da1232c928 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 19:29:31 +04:00
cherednik eda759e7aa DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 19:19:13 +04:00
cherednik 2c29f7210b DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 19:15:27 +04:00
cherednik 011503b6a0 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 19:08:14 +04:00
cherednik 09ab8eb13c DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 18:42:58 +04:00
cherednik a16b8e45fb DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 18:39:40 +04:00
cherednik 4947b8ea19 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 18:37:38 +04:00
cherednik 6e87f37ad3 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 17:22:36 +04:00
cherednik fd46bbb399 DD-3602: [BACK]. [Доверенность водителю с КЭП] - [реализовать отправку документа через АПИ Диадок] 2025-01-09 17:15:30 +04:00
25 changed files with 594 additions and 288 deletions

579
backend/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,4 +10,5 @@ return [
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
Symfony\UX\Chartjs\ChartjsBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
];

View File

@ -0,0 +1,5 @@
twig_component:
anonymous_template_directory: 'components/'
defaults:
# Namespace & directory for components
App\Twig\Components\: 'components/'

View File

@ -1,5 +1,5 @@
controllers:
controllers_sign_document:
resource:
path: ../src/Controller/
namespace: App\Controller
path: ../src/SignDocument/Controller/
namespace: App\SignDocument\Controller
type: attribute

View File

@ -28,6 +28,6 @@ services:
GuzzleHttp\Client: '@guzzle.http_client'
App\Api\ApiParams:
App\SignDocument\Api\ApiParams:
arguments:
$endPointUrl: '%env(DOT_DOT_URL)%'

View File

View File

@ -0,0 +1,9 @@
<?php
namespace App\Infrastructure\Api\Response;
// Абстрактный респонс - от него наследуются нужные респонсы для стандартизации ответа в ApiHelperTrait -> createNewJsonResponse
abstract class AbstractResponse
{
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Infrastructure\External\Api;
use RuntimeException;
/**
* Враппер бинарных фалов, при создании класса содает новый временный файл,
* при необходимости сохраняет файл под новым именем
@ -23,4 +25,14 @@ class BinaryStringFileResult
$this->tempFileName = sprintf('%s/%s_%s', sys_get_temp_dir(), 'Document', time());
file_put_contents($this->tempFileName, $content);
}
public function remove(): bool
{
if (file_exists($this->tempFileName)) {
unlink($this->tempFileName);
return true;
}
throw new RuntimeException('Temp file not found');
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace App\Infrastructure\Traits;
use App\Infrastructure\Api\Response\AbstractResponse;
use ReflectionClass;
use Symfony\Component\HttpFoundation\JsonResponse;
trait ApiHelperTrait
{
public function createJsonResponse(array $body, string $message = 'OK', int $code = 200): JsonResponse
{
return new JsonResponse([
'message' => $message,
'body' => $body,
], $code);
}
public function createPaginateJsonResponse(array $items, int $limit, int $totalCount): JsonResponse
{
return $this->createJsonResponse(
[
'items' => $items,
'pages' => ceil($totalCount / $limit),
'totalCount' => $totalCount,
]
);
}
public function createJsonResponseFromObject(AbstractResponse $body, string $message = 'OK', int $code = 200): JsonResponse
{
return new JsonResponse([
'message' => $message,
'body' => $this->toArray($body),
], $code);
}
private function toArray(AbstractResponse $body): array
{
$reflect = new ReflectionClass($body);
$props = $reflect->getProperties();
$array = [];
foreach ($props as $prop) {
$prop->setAccessible(true);
$array[$prop->getName()] = $prop->getValue($body);
$prop->setAccessible(false);
}
return $array;
}
}

View File

View File

@ -2,11 +2,10 @@
declare(strict_types=1);
namespace App\Api;
namespace App\SignDocument\Api;
use App\Infrastructure\External\Api\AbstractApi;
use App\Infrastructure\External\Api\BinaryStringFileResult;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
class Api extends AbstractApi

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace App\Api;
namespace App\SignDocument\Api;
class ApiParams
{

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace App\SignDocument\Api\Request;
use App\Infrastructure\Http\RequestDtoInterface;
class DigitalSignatureRequest implements RequestDtoInterface
{
public string $url;
public string $apiToken;
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace App\Api\Request;
namespace App\SignDocument\Api\Request;
use App\Infrastructure\Http\RequestDtoInterface;

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\SignDocument\Api\Response;
use App\Infrastructure\Api\Response\AbstractResponse;
class DigitalSignatureResponse extends AbstractResponse
{
public function __construct(
public string $hash,
public string $content,
)
{
}
}

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace App\SignDocument\Controller;
use App\Infrastructure\Traits\ApiHelperTrait;
use App\SignDocument\Api\Request\DigitalSignatureRequest;
use App\SignDocument\Services\DigitalSignatureService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DigitalSignatureController extends AbstractController
{
use ApiHelperTrait;
public function __construct(
private readonly DigitalSignatureService $digitalSignatureService
){
}
#[Route(path: '/digital/sign', name: 'app.digital.sign', methods: ['POST'])]
public function __invoke(Request $request, DigitalSignatureRequest $digitalSignatureRequest): Response
{
$token = $request->server->get('HTTP_AUTHORIZATION');
return $this->createJsonResponseFromObject(
$this->digitalSignatureService->getSignature($digitalSignatureRequest, $token)
);
}
}

View File

@ -2,15 +2,15 @@
declare(strict_types=1);
namespace App\Controller;
namespace App\SignDocument\Controller;
use App\Api\Request\SignRequest;
use App\SignService;
use App\SignDocument\Api\Request\SignRequest;
use App\SignDocument\Services\SignService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class SignController extends AbstractController
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace App;
namespace App\SignDocument\Services;
class DevSignService
{

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\SignDocument\Services;
use App\Infrastructure\External\Api\BinaryStringFileResult;
use App\SignDocument\Api\Api;
use App\SignDocument\Api\ApiParams;
use App\SignDocument\Api\Request\DigitalSignatureRequest;
use App\SignDocument\Api\Response\DigitalSignatureResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Exception;
use RuntimeException;
class DigitalSignatureService
{
private BinaryStringFileResult $document;
public function __construct(
private readonly Api $api,
private readonly ApiParams $apiParams,
){
}
public function __destruct()
{
$this->document->remove();
}
public function getSignature(DigitalSignatureRequest $request, string $token): DigitalSignatureResponse
{
if ($_ENV['API_TOKEN'] !== $request->apiToken) {
throw new AccessDeniedHttpException('Доступ запрещен');
}
$this->api->apiParams = $this->apiParams;
try {
$this->document = $this->api->download($request->url, $token);
exec(sprintf('cp %s %s.pdf', $this->document->tempFileName, $this->document->tempFileName));
exec(sprintf('cryptcp -sign -detached -der %s.pdf', $this->document->tempFileName));
$response = base64_encode(file_get_contents($this->document->tempFileName . '.pdf.sgn'));
return new DigitalSignatureResponse(
hash: $response,
content: base64_encode(file_get_contents(sprintf('%s.pdf', $this->document->tempFileName)))
);
} catch (Exception $e) {
throw new RuntimeException($e->getMessage());
}
}
}

View File

@ -3,7 +3,7 @@
declare(strict_types=1);
namespace App;
namespace App\SignDocument\Services;
class ProdSignService

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\SignDocument\Services;
use App\Infrastructure\External\Api\BinaryStringFileResult;
class RemoveExistingDocumentService
{
public function removeExistingDocument(BinaryStringFileResult $document): void
{
if (file_exists($document->tempFileName)) {
unlink($document->tempFileName);
}
}
}

View File

@ -2,27 +2,24 @@
declare(strict_types=1);
namespace App;
namespace App\SignDocument\Services;
use App\Api\Api;
use App\Api\ApiParams;
use App\Api\Request\SignRequest;
use App\Infrastructure\External\Api\BinaryStringFileResult;
use App\SignDocument\Api\Api;
use App\SignDocument\Api\ApiParams;
use App\SignDocument\Api\Request\SignRequest;
use Exception;
use RuntimeException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class SignService
{
private DevSignService $devSignService;
private ProdSignService $prodSignService;
public function __construct(
private Api $api,
private ApiParams $apiParams
private readonly Api $api,
private readonly ApiParams $apiParams,
private readonly DevSignService $devSignService,
private readonly ProdSignService $prodSignService,
private readonly RemoveExistingDocumentService $removeExistingDocumentService,
){
$this->devSignService = new DevSignService();
$this->prodSignService = new ProdSignService();
}
public function signDocument(SignRequest $request,string $token): array
{
@ -39,7 +36,7 @@ class SignService
$response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $request->batch);
$this->removeExistingDocument($document);
$this->removeExistingDocumentService->removeExistingDocument($document);
return $response;
} catch (Exception $e) {
@ -54,11 +51,4 @@ class SignService
'prod' => $this->prodSignService->sign($documentUrl),
};
}
private function removeExistingDocument(BinaryStringFileResult $document): void
{
if (file_exists($document->tempFileName)) {
unlink($document->tempFileName);
}
}
}

View File

@ -176,6 +176,18 @@
"symfony/ux-chartjs": {
"version": "v2.19.3"
},
"symfony/ux-twig-component": {
"version": "2.22",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.13",
"ref": "67814b5f9794798b885cec9d3f48631424449a01"
},
"files": [
"config/packages/twig_component.yaml"
]
},
"symfony/validator": {
"version": "6.2",
"recipe": {

View File

@ -5,14 +5,16 @@ server {
root /usr/src/signer/public;
location ~* \.php$ {
try_files $uri $uri/ /index.php last;
fastcgi_split_path_info (.+?\.php)(/.*)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass signer:9000;
try_files $uri =404;
fastcgi_index index.php;
}
location ~* .php/ {