Skip to content

Commit 9801dbe

Browse files
authored
Create EnvironCredentials.php
1 parent 28a8173 commit 9801dbe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/Auth/EnvironCredentials.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Auth;
4+
5+
use YdbPlatform\Ydb\Auth\Implement\AccessTokenAuthentication;
6+
use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
7+
use YdbPlatform\Ydb\Auth\Implement\JwtWithJsonAuthentication;
8+
use YdbPlatform\Ydb\Auth\Implement\MetadataAuthentication;
9+
10+
class EnvironCredentials extends \YdbPlatform\Ydb\Auth\Auth
11+
{
12+
/**
13+
* @var Auth
14+
*/
15+
protected $auth;
16+
public function __construct()
17+
{
18+
if ($jsonfile = getenv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS")){
19+
$this->auth = new JwtWithJsonAuthentication($jsonfile);
20+
} elseif (getenv("YDB_ANONYMOUS_CREDENTIALS") == 1){
21+
$this->auth = new AnonymousAuthentication();
22+
} elseif (getenv("YDB_METADATA_CREDENTIALS") == 1){
23+
$this->auth = new MetadataAuthentication();
24+
} elseif ($token = getenv("YDB_ACCESS_TOKEN_CREDENTIALS")){
25+
$this->auth = new AccessTokenAuthentication($token);
26+
} else {
27+
$this->auth = new MetadataAuthentication();
28+
}
29+
}
30+
31+
public function getTokenInfo(): TokenInfo
32+
{
33+
return $this->auth->getTokenInfo();
34+
}
35+
36+
public function getName(): string
37+
{
38+
return $this->auth->getName();
39+
}
40+
}

0 commit comments

Comments
 (0)