Cache
6 months ago
CredentialSource
6 months ago
Credentials
6 months ago
HttpHandler
6 months ago
Middleware
6 months ago
AccessToken.php
6 months ago
ApplicationDefaultCredentials.php
6 months ago
CacheTrait.php
6 months ago
CredentialsLoader.php
6 months ago
ExternalAccountCredentialSourceInterface.php
6 months ago
FetchAuthTokenCache.php
6 months ago
FetchAuthTokenInterface.php
6 months ago
GCECache.php
6 months ago
GetQuotaProjectInterface.php
6 months ago
GetUniverseDomainInterface.php
6 months ago
Iam.php
6 months ago
IamSignerTrait.php
6 months ago
OAuth2.php
6 months ago
ProjectIdProviderInterface.php
6 months ago
ServiceAccountSignerTrait.php
6 months ago
SignBlobInterface.php
6 months ago
UpdateMetadataInterface.php
6 months ago
UpdateMetadataTrait.php
6 months ago
GCECache.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2020 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | namespace WPMailSMTP\Vendor\Google\Auth; |
| 19 | |
| 20 | use WPMailSMTP\Vendor\Google\Auth\Credentials\GCECredentials; |
| 21 | use WPMailSMTP\Vendor\Psr\Cache\CacheItemPoolInterface; |
| 22 | /** |
| 23 | * A class to implement caching for calls to GCECredentials::onGce. This class |
| 24 | * is used automatically when you pass a `Psr\Cache\CacheItemPoolInterface` |
| 25 | * cache object to `ApplicationDefaultCredentials::getCredentials`. |
| 26 | * |
| 27 | * ``` |
| 28 | * $sysvCache = new Google\Auth\SysvCacheItemPool(); |
| 29 | * $creds = Google\Auth\ApplicationDefaultCredentials::getCredentials( |
| 30 | * $scope, |
| 31 | * null, |
| 32 | * null, |
| 33 | * $sysvCache |
| 34 | * ); |
| 35 | * ``` |
| 36 | */ |
| 37 | class GCECache |
| 38 | { |
| 39 | const GCE_CACHE_KEY = 'google_auth_on_gce_cache'; |
| 40 | use CacheTrait; |
| 41 | /** |
| 42 | * @param array<mixed> $cacheConfig Configuration for the cache |
| 43 | * @param CacheItemPoolInterface $cache |
| 44 | */ |
| 45 | public function __construct(?array $cacheConfig = null, ?CacheItemPoolInterface $cache = null) |
| 46 | { |
| 47 | $this->cache = $cache; |
| 48 | $this->cacheConfig = \array_merge(['lifetime' => 1500, 'prefix' => ''], (array) $cacheConfig); |
| 49 | } |
| 50 | /** |
| 51 | * Caches the result of onGce so the metadata server is not called multiple |
| 52 | * times. |
| 53 | * |
| 54 | * @param callable $httpHandler callback which delivers psr7 request |
| 55 | * @return bool True if this a GCEInstance, false otherwise |
| 56 | */ |
| 57 | public function onGce(?callable $httpHandler = null) |
| 58 | { |
| 59 | if (\is_null($this->cache)) { |
| 60 | return GCECredentials::onGce($httpHandler); |
| 61 | } |
| 62 | $cacheKey = self::GCE_CACHE_KEY; |
| 63 | $onGce = $this->getCachedValue($cacheKey); |
| 64 | if (\is_null($onGce)) { |
| 65 | $onGce = GCECredentials::onGce($httpHandler); |
| 66 | $this->setCachedValue($cacheKey, $onGce); |
| 67 | } |
| 68 | return $onGce; |
| 69 | } |
| 70 | } |
| 71 |