Skip to content

Commit

Permalink
ref: LocalHelper is using TokenStore
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Oct 16, 2023
1 parent 9f791cd commit 455a5de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
21 changes: 6 additions & 15 deletions EMS/client-helper-bundle/src/Helper/Local/LocalHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
use EMS\ClientHelperBundle\Helper\Environment\Environment;
use EMS\ClientHelperBundle\Helper\Environment\EnvironmentApi;
use EMS\ClientHelperBundle\Helper\Local\Status\Status;
use EMS\CommonBundle\Common\Standard\Hash;
use EMS\CommonBundle\Common\CoreApi\TokenStore;
use EMS\CommonBundle\Contracts\CoreApi\CoreApiInterface;
use EMS\CommonBundle\Contracts\CoreApi\Exception\NotAuthenticatedExceptionInterface;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;

Expand All @@ -25,7 +23,7 @@ final class LocalHelper
private readonly ClientRequest $clientRequest;

public function __construct(
private readonly CacheItemPoolInterface $cache,
private readonly TokenStore $tokenStore,
ClientRequestManager $clientRequestManager,
private readonly ContentTypeHelper $contentTypeHelper,
private readonly Builders $builders,
Expand All @@ -40,10 +38,9 @@ public function api(Environment $environment): CoreApiInterface
{
$coreApi = $this->environmentApi->api($environment);
$coreApi->setLogger($this->logger);

$cacheToken = $this->apiCacheToken($coreApi);
if ($cacheToken->isHit()) {
$coreApi->setToken($cacheToken->get());
$token = $this->tokenStore->getToken($coreApi->getBaseUrl());
if (null !== $token) {
$coreApi->setToken($token);
}

return $coreApi;
Expand Down Expand Up @@ -71,8 +68,7 @@ public function login(Environment $environment, string $username, string $passwo
{
$coreApi = $this->environmentApi->login($environment, $username, $password);
$coreApi->setLogger($this->logger);

$this->cache->save($this->apiCacheToken($coreApi)->set($coreApi->getToken()));
$this->tokenStore->saveToken($coreApi->getBaseUrl(), $coreApi->getToken());

return $coreApi;
}
Expand Down Expand Up @@ -124,11 +120,6 @@ public function statuses(Environment $environment): array
];
}

private function apiCacheToken(CoreApiInterface $coreApi): CacheItemInterface
{
return $this->cache->getItem(Hash::string($coreApi->getBaseUrl(), 'token_'));
}

private function statusRouting(Environment $environment, Settings $settings): Status
{
$status = new Status('Routing');
Expand Down
4 changes: 2 additions & 2 deletions EMS/client-helper-bundle/src/Resources/config/local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<argument>%emsch.local.path%</argument>
</service>
<service id="emsch.helper.local" class="EMS\ClientHelperBundle\Helper\Local\LocalHelper">
<argument type="service" id="Psr\Cache\CacheItemPoolInterface" />
<argument type="service" id="ems_common.core_api.token_store" />
<argument type="service" id="emsch.manager.client_request" />
<argument type="service" id="emsch.helper_content_type" />
<argument type="service" id="emsch.helper.builders" />
Expand Down Expand Up @@ -44,4 +44,4 @@
<tag name="console.command" command="emsch:local:folder-upload"/>
</service>
</services>
</container>
</container>

0 comments on commit 455a5de

Please sign in to comment.