Skip to content

Commit 9c4a281

Browse files
author
Илья
committed
Refactor StaticAuthentication.php
1 parent a832a64 commit 9c4a281

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/Auth/Implement/StaticAuthentication.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
use YdbPlatform\Ydb\Auth\Auth;
66
use YdbPlatform\Ydb\Auth\TokenInfo;
7+
use YdbPlatform\Ydb\Auth\UseConfigInterface;
78
use YdbPlatform\Ydb\AuthService;
9+
use YdbPlatform\Ydb\Ydb;
810

9-
class StaticAuthentication extends Auth
11+
class StaticAuthentication extends Auth implements UseConfigInterface
1012
{
1113
protected $user;
1214
protected $password;
1315
protected $token;
1416
/**
15-
* @var AuthService
17+
* @var Ydb
1618
*/
17-
protected $auth;
19+
protected $ydb;
1820

1921
public function __construct(string $user, string $password)
2022
{
@@ -24,7 +26,7 @@ public function __construct(string $user, string $password)
2426

2527
public function getTokenInfo(): TokenInfo
2628
{
27-
$this->token = $this->auth->getToken($this->user, $this->password);
29+
$this->token = $this->ydb->auth()->getToken($this->user, $this->password);
2830
$expiresIn = 12*60*60;
2931
$ratio = $this->getRefreshTokenRatio();
3032

@@ -36,7 +38,10 @@ public function getName(): string
3638
return "Static";
3739
}
3840

39-
public function setAuthService(AuthService $auth){
40-
$this->auth = $auth;
41+
public function setYdbConnectionConfig(array $config)
42+
{
43+
unset($config['credentials']);
44+
$config['credentials'] = new AccessTokenAuthentication('');
45+
$this->ydb = new Ydb($config, $this->logger);
4146
}
4247
}

src/Auth/UseConfigInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Auth;
4+
5+
interface UseConfigInterface
6+
{
7+
public function setYdbConnectionConfig(array $config);
8+
}

src/Ydb.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Psr\Log\LoggerInterface;
7+
use YdbPlatform\Ydb\Auth\UseConfigInterface;
78
use YdbPlatform\Ydb\Exceptions\NonRetryableException;
89
use YdbPlatform\Ydb\Exceptions\RetryableException;
910
use YdbPlatform\Ydb\Exceptions\Ydb\BadSessionException;
@@ -117,8 +118,8 @@ public function __construct($config = [], LoggerInterface $logger = null)
117118
if(isset($config['credentials'])){
118119
$this->iam_config['credentials'] = $config['credentials'];
119120
$this->iam_config['credentials']->setLogger($this->logger());
120-
if (method_exists($this->iam_config['credentials'], "setAuthService")){
121-
$this->iam_config['credentials']->setAuthService($this->auth());
121+
if ($this->iam_config['credentials'] instanceof UseConfigInterface){
122+
$this->iam_config['credentials']->setYdbConnectionConfig($config);
122123
}
123124
}
124125

0 commit comments

Comments
 (0)