1010use YandexCloud \Ydb \Jwt \Signer \Sha256 ;
1111use YandexCloud \Ydb \Contracts \IamTokenContract ;
1212
13+ use function filter_var ;
14+
1315class Iam implements IamTokenContract
1416{
1517 use Traits \LoggerTrait;
@@ -95,7 +97,6 @@ public function newToken()
9597 else if ($ this ->config ('private_key ' ))
9698 {
9799 $ token = $ this ->getJwtToken ();
98-
99100 $ request_data = [
100101 'jwt ' => $ token ->toString (),
101102 ];
@@ -159,6 +160,10 @@ public function newToken()
159160 */
160161 public function getCredentials ()
161162 {
163+ if ($ this ->config ('insecure ' )) {
164+ return ChannelCredentials::createInsecure ();
165+ }
166+
162167 $ root_pem_file = $ this ->config ('root_cert_file ' );
163168
164169 if ($ root_pem_file && is_file ($ root_pem_file ))
@@ -180,7 +185,14 @@ protected function initConfig()
180185 $ this ->config ['temp_dir ' ] = sys_get_temp_dir ();
181186 }
182187
183- if (!empty ($ this ->config ['use_metadata ' ]))
188+ $ this ->config ['insecure ' ] = (isset ($ this ->config ['insecure ' ]) && filter_var ($ this ->config ['insecure ' ], \FILTER_VALIDATE_BOOLEAN ));
189+ $ this ->config ['anonymous ' ] = (isset ($ this ->config ['anonymous ' ]) && filter_var ($ this ->config ['anonymous ' ], \FILTER_VALIDATE_BOOLEAN ));
190+
191+ if ($ this ->config ['anonymous ' ])
192+ {
193+ $ this ->logger ()->info ('YDB: Authentication method: Anonymous ' );
194+ }
195+ else if (!empty ($ this ->config ['use_metadata ' ]))
184196 {
185197 $ this ->logger ()->info ('YDB: Authentication method: Metadata URL ' );
186198 }
0 commit comments