Skip to content

Commit 0c1aad0

Browse files
committed
backend http datasources forwarder and http ingest
1 parent e707cf3 commit 0c1aad0

File tree

17 files changed

+348
-8
lines changed

17 files changed

+348
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
/docs/graphs/*.bkp
1717
/sentinel-kit_server_frontend/node_modules/*
1818
/sentinel-kit_server_frontend/package-lock.json
19+
/sentinel-kit_server_backend/composer.lock
1920
/sentinel-kit_server_backend/migrations/*
2021
/sentinel-kit_server_backend/var/*
2122
/sentinel-kit_server_backend/vendor/*
2223
/sentinel-kit_server_backend/public/bundles/
2324
/sentinel-kit_server_backend/config/secrets/prod/prod.decrypt.private.php
2425
/sentinel-kit_server_backend/config/config/jwt/*.pem
25-
/sentinel-kit_server_backend/package-lock.json
26+
/sentinel-kit_server_backend/package-lock.json

config/docker-config/Dockerfile.backend

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ RUN apk add --no-cache libpng-dev libjpeg-turbo-dev libwebp-dev libxpm-dev freet
88
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-xpm && \
99
docker-php-ext-install gd
1010

11+
COPY config/docker-config/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
12+
1113
RUN curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.alpine.sh' | bash && \
1214
apk add symfony-cli
1315

config/docker-config/uploads.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
memory_limit = 4096M
2+
post_max_size = 4096M
3+
upload_max_filesize = 4096M
4+
max_execution_time = 300

config/fluentbit_server/logs-http.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Listen 0.0.0.0
44
Port 24224
55
Tag http.logs
6+
Buffer_Max_Size 128MB
67

78
[FILTER]
89
Name parser

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ services:
2828
environment:
2929
- JWT_PASSPHRASE=${BACKEND_JWT_PASSPHRASE}
3030
- DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@sentinel-kit-db-mysql:3306/${MYSQL_DATABASE}?serverVersion=9.4.0&charset=utf8
31+
- DEFAULT_URI=https://${SENTINELKIT_BACKEND_HOSTNAME}
3132
- DATAMONITOR_SERVER_TOKEN=${SENTINELKIT_DATAMONITOR_SERVER_TOKEN}
3233
- CORS_ALLOW_ORIGIN=https://${SENTINELKIT_FRONTEND_HOSTNAME}
34+
- FLUENTBIT_SERVER_URL=http://sentinel-kit-server-fluentbit:24224
3335
volumes:
3436
- ./config/docker-config/backend-entrypoint.sh:/usr/local/bin/backend-entrypoint.sh:ro
3537
- ./sentinel-kit_server_backend:/var/www/html:delegated

sentinel-kit_server_backend/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ APP_SECRET=
2222
###> symfony/routing ###
2323
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
2424
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
25-
DEFAULT_URI=http://localhost
25+
DEFAULT_URI=https://localhost
2626
###< symfony/routing ###
2727

2828
###> doctrine/doctrine-bundle ###

sentinel-kit_server_backend/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"symfony/expression-language": "7.3.*",
2626
"symfony/flex": "^2",
2727
"symfony/framework-bundle": "7.3.*",
28+
"symfony/http-client": "7.3.*",
2829
"symfony/property-access": "7.3.*",
2930
"symfony/property-info": "7.3.*",
3031
"symfony/runtime": "7.3.*",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace App\Command;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputArgument;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Console\Style\SymfonyStyle;
11+
use Doctrine\ORM\EntityManagerInterface;
12+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
13+
use App\Entity\Datasource;
14+
15+
16+
#[AsCommand(
17+
name: 'app:datasource:create',
18+
description: 'Create a new ingest datasource in the backend application',
19+
)]
20+
class DatasourceCreateCommand extends Command
21+
{
22+
private $entityManager;
23+
private $urlGenerator;
24+
25+
public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator)
26+
{
27+
parent::__construct();
28+
$this->entityManager = $entityManager;
29+
$this->urlGenerator = $urlGenerator;
30+
}
31+
32+
protected function configure(): void
33+
{
34+
$this
35+
->addArgument('name', InputArgument::REQUIRED, 'Name of the datasource')
36+
->addArgument('index', InputArgument::REQUIRED, 'Target index in Elasticsearch')
37+
->addArgument('validFrom', InputArgument::OPTIONAL, '(optional) Valid from (YYYY-MM-DD)')
38+
->addArgument('validTo', InputArgument::OPTIONAL, '(optional) Valid to (YYYY-MM-DD)');
39+
}
40+
41+
protected function execute(InputInterface $input, OutputInterface $output): int
42+
{
43+
$io = new SymfonyStyle($input, $output);
44+
$name = $input->getArgument('name');
45+
$index = $input->getArgument('index');
46+
$validFrom = $input->getArgument('validFrom');
47+
$validTo = $input->getArgument('validTo');
48+
49+
$validFromDate = null;
50+
$validToDate = null;
51+
52+
if ($validFrom) {
53+
try{
54+
$validFromDate = new \DateTime($validFrom);
55+
}catch (\Exception $e){
56+
$io->error('Invalid date format for validFrom. Please use YYYY-MM-DD.');
57+
return Command::FAILURE;
58+
}
59+
}
60+
61+
if ($validTo) {
62+
try {
63+
$validToDate = new \DateTime($validTo);
64+
}catch (\Exception $e){
65+
$io->error('Invalid date format for validTo. Please use YYYY-MM-DD.');
66+
return Command::FAILURE;
67+
}
68+
}
69+
70+
$existingDatasource = $this->entityManager->getRepository(Datasource::class)->findOneBy(['name' => $name]);
71+
72+
if ($existingDatasource) {
73+
$io->error(sprintf('Datasource "%s" already exists.', $name));
74+
return Command::FAILURE;
75+
}
76+
77+
$datasource = new Datasource();
78+
$output->writeln(sprintf('%s - %s', $name, $index));
79+
$datasource->setName($name);
80+
$datasource->setTargetIndex($index);
81+
$datasource->setValidFrom($validFromDate);
82+
$datasource->setValidTo($validToDate);
83+
84+
try {
85+
$this->entityManager->persist($datasource);
86+
$this->entityManager->flush();
87+
} catch (\Exception $e) {
88+
$io->error('An error occurred while creating the datasource: ' . $e->getMessage());
89+
return Command::FAILURE;
90+
}
91+
92+
$io->success(sprintf('Datasource "%s" created successfully', $name));
93+
$io->writeln(sprintf('Valid from %s', $validFrom ? $validFromDate->format('Y-m-d') : 'N/A'));
94+
$io->writeln(sprintf('Valid to %s', $validTo ? $validToDate->format('Y-m-d') : 'N/A'));
95+
$io->writeln(sprintf('Ingest key (header X-Ingest-Key): %s', $datasource->getIngestKey()));
96+
$io->writeln(sprintf('Forwarder URL: %s', $this->urlGenerator->generate('app_ingest_json', [], UrlGeneratorInterface::ABSOLUTE_URL)));
97+
98+
return Command::SUCCESS;
99+
}
100+
}

sentinel-kit_server_backend/src/Command/UsersCreateCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
9-
use Symfony\Component\Console\Input\InputOption;
109
use Symfony\Component\Console\Output\OutputInterface;
1110
use Symfony\Component\Console\Style\SymfonyStyle;
1211
use Doctrine\ORM\EntityManagerInterface;

sentinel-kit_server_backend/src/Command/UsersDeleteCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
9-
use Symfony\Component\Console\Input\InputOption;
109
use Symfony\Component\Console\Output\OutputInterface;
1110
use Symfony\Component\Console\Style\SymfonyStyle;
1211
use Doctrine\ORM\EntityManagerInterface;

0 commit comments

Comments
 (0)