Retrieving variables bound in the container configuration from environment variables.

This commit is contained in:
Alexey Skobkin 2023-04-01 21:43:05 +03:00
parent 109c95fcdb
commit 5c916a636f
No known key found for this signature in database
GPG key ID: 5D5CEF6F221278E7
4 changed files with 25 additions and 16 deletions

11
.env
View file

@ -38,3 +38,14 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###> symfony/mailer ###
# MAILER_DSN=null://null
###< symfony/mailer ###
# Point tools settings
APP_USER_ID=435
APP_USER_LOGIN=point-tools
APP_POINT_DOMAIN=point.im
APP_POINT_SCHEME=https
APP_POINT_API_DELAY=5000
APP_CRAWLER_SECRET=some_secret_for_crawler_change_it_right_away
# Telegram Bot settings
TELEGRAM_BOT_TOKEN=123:abc

View file

@ -11,21 +11,19 @@ services:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
# TODO: fix retrieval
# Point Tools
$appUserId: 435
$appUserLogin: 'point-tools'
$appUserId: '%env(int:APP_USER_ID)%'
$appUserLogin: 'env(string:APP_USER_LOGIN)'
# Telegram Bot API
$telegramToken: ''
$telegramToken: 'env(string:TELEGRAM_BOT_TOKEN)'
$debugEnabled: '%kernel.debug%'
# Point API
$pointDomain: 'point.im'
$pointScheme: 'https'
$pointApiDelay: 5000
$pointAppUserId: ''
$pointDomain: 'env(string:APP_POINT_DOMAIN)'
$pointScheme: 'env(string:APP_POINT_SCHEME)'
$pointApiDelay: '%env(int:APP_POINT_API_DELAY)%'
$pointApiClient: '@app.point.http_client'
# Crawler API
$crawlerToken: ''
$crawlerSecret: 'env(string:APP_CRAWLER_SECRET)'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name

View file

@ -27,7 +27,7 @@ class UpdateSubscriptionsCommand extends Command
private readonly UserApi $api,
private readonly SubscriptionsManager $subscriptionManager,
private readonly int $pointApiDelay,
private readonly int $pointAppUserId,
private readonly int $appUserId,
) {
parent::__construct();
}
@ -155,9 +155,9 @@ class UpdateSubscriptionsCommand extends Command
} else {
/** @var User $serviceUser */
try {
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->pointAppUserId);
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId);
} catch (\Exception $e) {
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->pointAppUserId]);
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]);
throw $e;
}
@ -166,7 +166,7 @@ class UpdateSubscriptionsCommand extends Command
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
try {
$serviceUser = $this->api->getUserById($this->pointAppUserId);
$serviceUser = $this->api->getUserById($this->appUserId);
} catch (UserNotFoundException $e) {
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
}
@ -175,7 +175,7 @@ class UpdateSubscriptionsCommand extends Command
$this->logger->info('Getting service subscribers');
try {
$usersForUpdate = $this->api->getUserSubscribersById($this->pointAppUserId);
$usersForUpdate = $this->api->getUserSubscribersById($this->appUserId);
} catch (UserNotFoundException $e) {
$this->logger->critical('Service user deleted or API response is invalid');

View file

@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\{Request, Response};
class CrawlerController extends AbstractApiController
{
public function __construct(
private readonly string $crawlerToken,
private readonly string $crawlerSecret,
) {
}
@ -20,7 +20,7 @@ class CrawlerController extends AbstractApiController
{
$remoteToken = $request->request->get('token');
if (!$this->crawlerToken || ($this->crawlerToken !== $remoteToken)) {
if (!$this->crawlerSecret || ($this->crawlerSecret !== $remoteToken)) {
return $this->createErrorResponse(
'Token error. Please check it in crawler and API parameters.',
Response::HTTP_FORBIDDEN,