← All changes
|
includes/sdk/google/google/cloud-storage/src/Bucket.php
+181
-60
1.1.0
→
1.4.1
View file →
| @@ -14,28 +14,27 @@ | ||
| 14 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | 15 | * See the License for the specific language governing permissions and |
| 16 | 16 | * limitations under the License. |
| 17 | 17 | */ |
| 18 | -namespace Dudlewebs\WPMCS\Google\Cloud\Storage; | |
| 18 | +namespace Dudlewebs\WPMCS\GCP\Google\Cloud\Storage; | |
| 19 | 19 | |
| 20 | -use Dudlewebs\WPMCS\Google\Cloud\Core\ArrayTrait; | |
| 21 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Exception\GoogleException; | |
| 22 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Exception\NotFoundException; | |
| 23 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Exception\ServiceException; | |
| 24 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Iam\Iam; | |
| 25 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Iterator\ItemIterator; | |
| 26 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Iterator\PageIterator; | |
| 27 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Timestamp; | |
| 28 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Upload\ResumableUploader; | |
| 29 | -use Dudlewebs\WPMCS\Google\Cloud\Core\Upload\StreamableUploader; | |
| 30 | -use Dudlewebs\WPMCS\Google\Cloud\PubSub\Topic; | |
| 31 | -use Dudlewebs\WPMCS\Google\Cloud\Storage\Connection\ConnectionInterface; | |
| 32 | -use Dudlewebs\WPMCS\Google\Cloud\Storage\Connection\IamBucket; | |
| 33 | -use Dudlewebs\WPMCS\Google\Cloud\Storage\SigningHelper; | |
| 34 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface; | |
| 35 | -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\MimeType; | |
| 36 | -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils; | |
| 37 | -use Dudlewebs\WPMCS\Psr\Http\Message\StreamInterface; | |
| 20 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\ArrayTrait; | |
| 21 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Exception\GoogleException; | |
| 22 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Exception\NotFoundException; | |
| 23 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Exception\ServiceException; | |
| 24 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Iam\Iam; | |
| 25 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Iterator\ItemIterator; | |
| 26 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Iterator\PageIterator; | |
| 27 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Timestamp; | |
| 28 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Upload\ResumableUploader; | |
| 29 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Upload\StreamableUploader; | |
| 30 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\PubSub\Topic; | |
| 31 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Storage\Connection\ConnectionInterface; | |
| 32 | +use Dudlewebs\WPMCS\GCP\Google\Cloud\Storage\Connection\IamBucket; | |
| 33 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface; | |
| 34 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\MimeType; | |
| 35 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils; | |
| 36 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\StreamInterface; | |
| 38 | 37 | /** |
| 39 | 38 | * Buckets are the basic containers that hold your data. Everything that you |
| 40 | 39 | * store in Google Cloud Storage must be contained in a bucket. |
| 41 | 40 | * |
| @@ -53,9 +52,9 @@ | ||
| 53 | 52 | use ArrayTrait; |
| 54 | 53 | use EncryptionTrait; |
| 55 | 54 | const NOTIFICATION_TEMPLATE = '//pubsub.googleapis.com/%s'; |
| 56 | 55 | const TOPIC_TEMPLATE = 'projects/%s/topics/%s'; |
| 57 | - const TOPIC_REGEX = '/projects\/[^\/]*\/topics\/(.*)/'; | |
| 56 | + const TOPIC_REGEX = '/projects\\/[^\\/]*\\/topics\\/(.*)/'; | |
| 58 | 57 | /** |
| 59 | 58 | * @var Acl ACL for the bucket. |
| 60 | 59 | */ |
| 61 | 60 | private $acl; |
| @@ -227,12 +226,10 @@ | ||
| 227 | 226 | * upstream server, the upload will be rejected. Available options |
| 228 | 227 | * are `true`, `false`, `md5` and `crc32`. If true, either md5 or |
| 229 | 228 | * crc32c will be chosen based on your platform. If false, no |
| 230 | 229 | * validation hash will be sent. Choose either `md5` or `crc32` to |
| 231 | - * force a hash method regardless of performance implications. In | |
| 232 | - * PHP versions earlier than 7.4, performance will be very | |
| 233 | - * adversely impacted by using crc32c unless you install the | |
| 234 | - * `crc32c` PHP extension. **Defaults to** `true`. | |
| 230 | + * force a hash method regardless of performance implications. | |
| 231 | + * **Defaults to** `true`. | |
| 235 | 232 | * @type int $chunkSize If provided the upload will be done in chunks. |
| 236 | 233 | * The size must be in multiples of 262144 bytes. With chunking |
| 237 | 234 | * you have increased reliability at the risk of higher overhead. |
| 238 | 235 | * It is recommended to not use chunking. |
| @@ -330,12 +327,10 @@ | ||
| 330 | 327 | * upstream server, the upload will be rejected. Available options |
| 331 | 328 | * are `true`, `false`, `md5` and `crc32`. If true, either md5 or |
| 332 | 329 | * crc32c will be chosen based on your platform. If false, no |
| 333 | 330 | * validation hash will be sent. Choose either `md5` or `crc32` to |
| 334 | - * force a hash method regardless of performance implications. In | |
| 335 | - * PHP versions earlier than 7.4, performance will be very | |
| 336 | - * adversely impacted by using crc32c unless you install the | |
| 337 | - * `crc32c` PHP extension. **Defaults to** `true`.ß | |
| 331 | + * force a hash method regardless of performance implications. | |
| 332 | + * **Defaults to** `true`. | |
| 338 | 333 | * @type string $predefinedAcl Predefined ACL to apply to the object. |
| 339 | 334 | * Acceptable values include, `"authenticatedRead"`, |
| 340 | 335 | * `"bucketOwnerFullControl"`, `"bucketOwnerRead"`, `"private"`, |
| 341 | 336 | * `"projectPrivate"`, and `"publicRead"`. |
| @@ -367,9 +362,9 @@ | ||
| 367 | 362 | } |
| 368 | 363 | $encryptionKey = $options['encryptionKey'] ?? null; |
| 369 | 364 | $encryptionKeySHA256 = $options['encryptionKeySHA256'] ?? null; |
| 370 | 365 | $promise = $this->connection->insertObject($this->formatEncryptionHeaders($options) + $this->identity + ['data' => $data, 'resumable' => \false])->uploadAsync(); |
| 371 | - return $promise->then(function (array $response) use ($encryptionKey, $encryptionKeySHA256) { | |
| 366 | + return $promise->then(function (array $response) use($encryptionKey, $encryptionKeySHA256) { | |
| 372 | 367 | return new StorageObject($this->connection, $response['name'], $this->identity['bucket'], $response['generation'], $response, $encryptionKey, $encryptionKeySHA256); |
| 373 | 368 | }); |
| 374 | 369 | } |
| 375 | 370 | /** |
| @@ -525,8 +520,11 @@ | ||
| 525 | 520 | * customer-supplied encryption key. This value will be calculated |
| 526 | 521 | * from the `encryptionKey` on your behalf if not provided, but |
| 527 | 522 | * for best performance it is recommended to pass in a cached |
| 528 | 523 | * version of the already calculated SHA. |
| 524 | + * @type boolean $softDeleted If true, returns the metadata of the | |
| 525 | + * soft-deleted object. If true, generation must also be specified, | |
| 526 | + * and alt=media cannot be specified. | |
| 529 | 527 | * } |
| 530 | 528 | * @return StorageObject |
| 531 | 529 | */ |
| 532 | 530 | public function object($name, array $options = []) |
| @@ -533,11 +531,49 @@ | ||
| 533 | 531 | { |
| 534 | 532 | $generation = $options['generation'] ?? null; |
| 535 | 533 | $encryptionKey = $options['encryptionKey'] ?? null; |
| 536 | 534 | $encryptionKeySHA256 = $options['encryptionKeySHA256'] ?? null; |
| 537 | - return new StorageObject($this->connection, $name, $this->identity['bucket'], $generation, array_filter(['requesterProjectId' => $this->identity['userProject']]), $encryptionKey, $encryptionKeySHA256); | |
| 535 | + return new StorageObject($this->connection, $name, $this->identity['bucket'], $generation, \array_filter(['requesterProjectId' => $this->identity['userProject']]), $encryptionKey, $encryptionKeySHA256); | |
| 538 | 536 | } |
| 539 | 537 | /** |
| 538 | + * Restores an object. | |
| 539 | + * | |
| 540 | + * Example: | |
| 541 | + * ``` | |
| 542 | + * $object = $bucket->restore('file.txt'); | |
| 543 | + * ``` | |
| 544 | + * | |
| 545 | + * @param string $name The name of the object to restore. | |
| 546 | + * @param string $generation Request a specific generation of the object. | |
| 547 | + * @param array $options [optional] { | |
| 548 | + * Configuration Options. | |
| 549 | + * | |
| 550 | + * @type string $restoreToken Must be specified when getting a soft-deleted object from | |
| 551 | + * an HNS-enabled bucket that has a name and generation conflict with another object in the same bucket. | |
| 552 | + * @type string $ifGenerationMatch Makes the operation conditional on whether | |
| 553 | + * the object's current generation matches the given value. | |
| 554 | + * @type string $ifGenerationNotMatch Makes the operation conditional on whether | |
| 555 | + * the object's current generation matches the given value. | |
| 556 | + * @type string $ifMetagenerationMatch If set, only restores | |
| 557 | + * if its metageneration matches this value. | |
| 558 | + * @type string $ifMetagenerationNotMatch If set, only restores | |
| 559 | + * if its metageneration does not match this value. | |
| 560 | + * } | |
| 561 | + * @return StorageObject | |
| 562 | + */ | |
| 563 | + public function restore($name, $generation, array $options = []) | |
| 564 | + { | |
| 565 | + $res = $this->connection->restoreObject(['bucket' => $this->identity['bucket'], 'generation' => $generation, 'object' => $name] + $options); | |
| 566 | + return new StorageObject( | |
| 567 | + $this->connection, | |
| 568 | + $name, | |
| 569 | + $this->identity['bucket'], | |
| 570 | + $res['generation'], | |
| 571 | + // restored object will have a new generation | |
| 572 | + $res + \array_filter(['requesterProjectId' => $this->identity['userProject']]) | |
| 573 | + ); | |
| 574 | + } | |
| 575 | + /** | |
| 540 | 576 | * Fetches all objects in the bucket. |
| 541 | 577 | * |
| 542 | 578 | * Example: |
| 543 | 579 | * ``` |
| @@ -582,15 +618,15 @@ | ||
| 582 | 618 | * @type string $matchGlob A glob pattern to filter results. The string |
| 583 | 619 | * value must be UTF-8 encoded. See: |
| 584 | 620 | * https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob |
| 585 | 621 | * } |
| 586 | - * @return ObjectIterator<StorageObject> | |
| 622 | + * @return ObjectIterator | |
| 587 | 623 | */ |
| 588 | 624 | public function objects(array $options = []) |
| 589 | 625 | { |
| 590 | 626 | $resultLimit = $this->pluck('resultLimit', $options, \false); |
| 591 | 627 | return new ObjectIterator(new ObjectPageIterator(function (array $object) { |
| 592 | - return new StorageObject($this->connection, $object['name'], $this->identity['bucket'], isset($object['generation']) ? $object['generation'] : null, $object + array_filter(['requesterProjectId' => $this->identity['userProject']])); | |
| 628 | + return new StorageObject($this->connection, $object['name'], $this->identity['bucket'], isset($object['generation']) ? $object['generation'] : null, $object + \array_filter(['requesterProjectId' => $this->identity['userProject']])); | |
| 593 | 629 | }, [$this->connection, 'listObjects'], $options + $this->identity, ['resultLimit' => $resultLimit])); |
| 594 | 630 | } |
| 595 | 631 | /** |
| 596 | 632 | * Create a Cloud PubSub notification. |
| @@ -741,8 +777,9 @@ | ||
| 741 | 777 | */ |
| 742 | 778 | public function notifications(array $options = []) |
| 743 | 779 | { |
| 744 | 780 | $resultLimit = $this->pluck('resultLimit', $options, \false); |
| 781 | + /** @var ItemIterator<Notification> */ | |
| 745 | 782 | return new ItemIterator(new PageIterator(function (array $notification) { |
| 746 | 783 | return new Notification($this->connection, $notification['id'], $this->identity['bucket'], $notification + ['requesterProjectId' => $this->identity['userProject']]); |
| 747 | 784 | }, [$this->connection, 'listNotifications'], $options + $this->identity, ['resultLimit' => $resultLimit])); |
| 748 | 785 | } |
| @@ -933,12 +970,12 @@ | ||
| 933 | 970 | * @throws \InvalidArgumentException |
| 934 | 971 | */ |
| 935 | 972 | public function compose(array $sourceObjects, $name, array $options = []) |
| 936 | 973 | { |
| 937 | - if (count($sourceObjects) < 2) { | |
| 974 | + if (\count($sourceObjects) < 2) { | |
| 938 | 975 | throw new \InvalidArgumentException('Must provide at least two objects to compose.'); |
| 939 | 976 | } |
| 940 | - $options += ['destinationBucket' => $this->name(), 'destinationObject' => $name, 'destinationPredefinedAcl' => isset($options['predefinedAcl']) ? $options['predefinedAcl'] : null, 'destination' => isset($options['metadata']) ? $options['metadata'] : null, 'userProject' => $this->identity['userProject'], 'sourceObjects' => array_map(function ($sourceObject) { | |
| 977 | + $options += ['destinationBucket' => $this->name(), 'destinationObject' => $name, 'destinationPredefinedAcl' => isset($options['predefinedAcl']) ? $options['predefinedAcl'] : null, 'destination' => isset($options['metadata']) ? $options['metadata'] : null, 'userProject' => $this->identity['userProject'], 'sourceObjects' => \array_map(function ($sourceObject) { | |
| 941 | 978 | $name = null; |
| 942 | 979 | $generation = null; |
| 943 | 980 | if ($sourceObject instanceof StorageObject) { |
| 944 | 981 | $name = $sourceObject->name(); |
| @@ -943,9 +980,9 @@ | ||
| 943 | 980 | if ($sourceObject instanceof StorageObject) { |
| 944 | 981 | $name = $sourceObject->name(); |
| 945 | 982 | $generation = $sourceObject->identity()['generation'] ?? null; |
| 946 | 983 | } |
| 947 | - return array_filter(['name' => $name ?: $sourceObject, 'generation' => $generation]); | |
| 984 | + return \array_filter(['name' => $name ?: $sourceObject, 'generation' => $generation]); | |
| 948 | 985 | }, $sourceObjects)]; |
| 949 | 986 | if (!isset($options['destination']['contentType'])) { |
| 950 | 987 | $options['destination']['contentType'] = MimeType::fromFilename($name); |
| 951 | 988 | } |
| @@ -953,10 +990,10 @@ | ||
| 953 | 990 | throw new \InvalidArgumentException('A content type could not be detected and must be provided manually.'); |
| 954 | 991 | } |
| 955 | 992 | unset($options['metadata']); |
| 956 | 993 | unset($options['predefinedAcl']); |
| 957 | - $response = $this->connection->composeObject(array_filter($options)); | |
| 958 | - return new StorageObject($this->connection, $response['name'], $this->identity['bucket'], $response['generation'], $response + array_filter(['requesterProjectId' => $this->identity['userProject']])); | |
| 994 | + $response = $this->connection->composeObject(\array_filter($options)); | |
| 995 | + return new StorageObject($this->connection, $response['name'], $this->identity['bucket'], $response['generation'], $response + \array_filter(['requesterProjectId' => $this->identity['userProject']])); | |
| 959 | 996 | } |
| 960 | 997 | /** |
| 961 | 998 | * Retrieves the bucket's details. If no bucket data is cached a network |
| 962 | 999 | * request will be made to retrieve it. |
| @@ -971,8 +1008,11 @@ | ||
| 971 | 1008 | * |
| 972 | 1009 | * @param array $options [optional] { |
| 973 | 1010 | * Configuration options. |
| 974 | 1011 | * |
| 1012 | + * @type string $generation If present, selects a specific soft-deleted | |
| 1013 | + * version of this bucket instead of the live version. | |
| 1014 | + * This parameter is required if softDeleted is set to true. | |
| 975 | 1015 | * @type string $ifMetagenerationMatch Makes the return of the bucket |
| 976 | 1016 | * metadata conditional on whether the bucket's current |
| 977 | 1017 | * metageneration matches the given value. |
| 978 | 1018 | * @type string $ifMetagenerationNotMatch Makes the return of the bucket |
| @@ -979,8 +1019,10 @@ | ||
| 979 | 1019 | * metadata conditional on whether the bucket's current |
| 980 | 1020 | * metageneration does not match the given value. |
| 981 | 1021 | * @type string $projection Determines which properties to return. May |
| 982 | 1022 | * be either `"full"` or `"noAcl"`. |
| 1023 | + * @type bool $softDeleted If true, returns the soft-deleted bucket. | |
| 1024 | + * This parameter is required if generation is specified. | |
| 983 | 1025 | * } |
| 984 | 1026 | * @return array |
| 985 | 1027 | */ |
| 986 | 1028 | public function info(array $options = []) |
| @@ -1001,8 +1043,11 @@ | ||
| 1001 | 1043 | * |
| 1002 | 1044 | * @param array $options [optional] { |
| 1003 | 1045 | * Configuration options. |
| 1004 | 1046 | * |
| 1047 | + * @type string $generation If present, selects a specific soft-deleted | |
| 1048 | + * version of this bucket instead of the live version. | |
| 1049 | + * This parameter is required if softDeleted is set to true. | |
| 1005 | 1050 | * @type string $ifMetagenerationMatch Makes the return of the bucket |
| 1006 | 1051 | * metadata conditional on whether the bucket's current |
| 1007 | 1052 | * metageneration matches the given value. |
| 1008 | 1053 | * @type string $ifMetagenerationNotMatch Makes the return of the bucket |
| @@ -1009,8 +1054,10 @@ | ||
| 1009 | 1054 | * metadata conditional on whether the bucket's current |
| 1010 | 1055 | * metageneration does not match the given value. |
| 1011 | 1056 | * @type string $projection Determines which properties to return. May |
| 1012 | 1057 | * be either `"full"` or `"noAcl"`. |
| 1058 | + * @type bool $softDeleted If true, returns the soft-deleted bucket. | |
| 1059 | + * This parameter is required if generation is specified. | |
| 1013 | 1060 | * } |
| 1014 | 1061 | * @return array |
| 1015 | 1062 | */ |
| 1016 | 1063 | public function reload(array $options = []) |
| @@ -1270,16 +1317,52 @@ | ||
| 1270 | 1317 | * multiple spaces within values will be collapsed to a single |
| 1271 | 1318 | * space, and line breaks will be replaced by an empty string. |
| 1272 | 1319 | * V2 Signed URLs may not provide `x-goog-encryption-key` or |
| 1273 | 1320 | * `x-goog-encryption-key-sha256` headers. |
| 1274 | - * @type array $keyFile Keyfile data to use in place of the keyfile with | |
| 1275 | - * which the client was constructed. If `$options.keyFilePath` is | |
| 1276 | - * set, this option is ignored. | |
| 1277 | - * @type string $keyFilePath A path to a valid keyfile to use in place | |
| 1278 | - * of the keyfile with which the client was constructed. | |
| 1279 | - * @type string|array $scopes One or more authentication scopes to be | |
| 1280 | - * used with a key file. This option is ignored unless | |
| 1281 | - * `$options.keyFile` or `$options.keyFilePath` is set. | |
| 1321 | + * @type FetchAuthTokenInterface $credentialsFetcher A credentials | |
| 1322 | + * fetcher instance. | |
| 1323 | + * @type array $keyFile [DEPRECATED] | |
| 1324 | + * This option is being deprecated because of a potential security risk. | |
| 1325 | + * This option does not validate the credential configuration. The security | |
| 1326 | + * risk occurs when a credential configuration is accepted from a source | |
| 1327 | + * that is not under your control and used without validation on your side. | |
| 1328 | + * If you know that you will be loading credential configurations of a | |
| 1329 | + * specific type, it is recommended to create the credentials directly and | |
| 1330 | + * configure them using the `credentialsFetcher` option instead. | |
| 1331 | + * ``` | |
| 1332 | + * use Google\Auth\Credentials\ServiceAccountCredentials; | |
| 1333 | + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json); | |
| 1334 | + * ``` | |
| 1335 | + * This will ensure that an unexpected credential type with potential for | |
| 1336 | + * malicious intent is not loaded unintentionally. You might still have to do | |
| 1337 | + * validation for certain credential types. | |
| 1338 | + * If you are loading your credential configuration from an untrusted source and have | |
| 1339 | + * not mitigated the risks (e.g. by validating the configuration yourself), make | |
| 1340 | + * these changes as soon as possible to prevent security risks to your environment. | |
| 1341 | + * Regardless of the method used, it is always your responsibility to validate | |
| 1342 | + * configurations received from external sources. | |
| 1343 | + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials | |
| 1344 | + * @type string $keyFilePath [DEPRECATED] | |
| 1345 | + * This option is being deprecated because of a potential security risk. | |
| 1346 | + * This option does not validate the credential configuration. The security | |
| 1347 | + * risk occurs when a credential configuration is accepted from a source | |
| 1348 | + * that is not under your control and used without validation on your side. | |
| 1349 | + * If you know that you will be loading credential configurations of a | |
| 1350 | + * specific type, it is recommended to create the credentials directly and | |
| 1351 | + * configure them using the `credentialsFetcher` option instead. | |
| 1352 | + * ``` | |
| 1353 | + * use Google\Auth\Credentials\ServiceAccountCredentials; | |
| 1354 | + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json); | |
| 1355 | + * ``` | |
| 1356 | + * This will ensure that an unexpected credential type with potential for | |
| 1357 | + * malicious intent is not loaded unintentionally. You might still have to do | |
| 1358 | + * validation for certain credential types. | |
| 1359 | + * If you are loading your credential configuration from an untrusted source and have | |
| 1360 | + * not mitigated the risks (e.g. by validating the configuration yourself), make | |
| 1361 | + * these changes as soon as possible to prevent security risks to your environment. | |
| 1362 | + * Regardless of the method used, it is always your responsibility to validate | |
| 1363 | + * configurations received from external sources. | |
| 1364 | + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials | |
| 1282 | 1365 | * @type array $queryParams Additional query parameters to be included |
| 1283 | 1366 | * as part of the signed URL query string. For allowed values, |
| 1284 | 1367 | * see [Reference Headers](https://cloud.google.com/storage/docs/xml-api/reference-headers#query). |
| 1285 | 1368 | * @type string $version One of "v2" or "v4". *Defaults to** `"v2"`. |
| @@ -1294,9 +1377,9 @@ | ||
| 1294 | 1377 | public function signedUrl($expires, array $options = []) |
| 1295 | 1378 | { |
| 1296 | 1379 | // May be overridden for testing. |
| 1297 | 1380 | $signingHelper = $this->pluck('helper', $options, \false) ?: SigningHelper::getHelper(); |
| 1298 | - $resource = sprintf('/%s', $this->identity['bucket']); | |
| 1381 | + $resource = \sprintf('/%s', $this->identity['bucket']); | |
| 1299 | 1382 | return $signingHelper->sign($this->connection, $expires, $resource, null, $options); |
| 1300 | 1383 | } |
| 1301 | 1384 | /** |
| 1302 | 1385 | * Create a signed upload policy for uploading objects. |
| @@ -1351,14 +1434,52 @@ | ||
| 1351 | 1434 | * `x-goog-signature`, `file`, `policy` or fields with an |
| 1352 | 1435 | * `x-ignore` prefix), given as key/value pairs. |
| 1353 | 1436 | * @type bool $forceOpenssl If true, OpenSSL will be used regardless of |
| 1354 | 1437 | * whether phpseclib is available. **Defaults to** `false`. |
| 1355 | - * @type array $keyFile Keyfile data to use in place of the keyfile with | |
| 1356 | - * which the client was constructed. If `$options.keyFilePath` is | |
| 1357 | - * set, this option is ignored. | |
| 1358 | - * @type string $keyFilePath A path to a valid Keyfile to use in place | |
| 1359 | - * of the keyfile with which the client was constructed. | |
| 1360 | - * @type string $scheme Either `http` or `https`. Only used if a custom | |
| 1438 | + * @type FetchAuthTokenInterface $credentialsFetcher A credentials | |
| 1439 | + * fetcher instance. | |
| 1440 | + * @type array $keyFile [DEPRECATED] | |
| 1441 | + * This option is being deprecated because of a potential security risk. | |
| 1442 | + * This option does not validate the credential configuration. The security | |
| 1443 | + * risk occurs when a credential configuration is accepted from a source | |
| 1444 | + * that is not under your control and used without validation on your side. | |
| 1445 | + * If you know that you will be loading credential configurations of a | |
| 1446 | + * specific type, it is recommended to create the credentials directly and | |
| 1447 | + * configure them using the `credentialsFetcher` option instead. | |
| 1448 | + * ``` | |
| 1449 | + * use Google\Auth\Credentials\ServiceAccountCredentials; | |
| 1450 | + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json); | |
| 1451 | + * ``` | |
| 1452 | + * This will ensure that an unexpected credential type with potential for | |
| 1453 | + * malicious intent is not loaded unintentionally. You might still have to do | |
| 1454 | + * validation for certain credential types. | |
| 1455 | + * If you are loading your credential configuration from an untrusted source and have | |
| 1456 | + * not mitigated the risks (e.g. by validating the configuration yourself), make | |
| 1457 | + * these changes as soon as possible to prevent security risks to your environment. | |
| 1458 | + * Regardless of the method used, it is always your responsibility to validate | |
| 1459 | + * configurations received from external sources. | |
| 1460 | + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials | |
| 1461 | + * @type string $keyFilePath [DEPRECATED] | |
| 1462 | + * This option is being deprecated because of a potential security risk. | |
| 1463 | + * This option does not validate the credential configuration. The security | |
| 1464 | + * risk occurs when a credential configuration is accepted from a source | |
| 1465 | + * that is not under your control and used without validation on your side. | |
| 1466 | + * If you know that you will be loading credential configurations of a | |
| 1467 | + * specific type, it is recommended to create the credentials directly and | |
| 1468 | + * configure them using the `credentialsFetcher` option instead. | |
| 1469 | + * ``` | |
| 1470 | + * use Google\Auth\Credentials\ServiceAccountCredentials; | |
| 1471 | + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json); | |
| 1472 | + * ``` | |
| 1473 | + * This will ensure that an unexpected credential type with potential for | |
| 1474 | + * malicious intent is not loaded unintentionally. You might still have to do | |
| 1475 | + * validation for certain credential types. | |
| 1476 | + * If you are loading your credential configuration from an untrusted source and have | |
| 1477 | + * not mitigated the risks (e.g. by validating the configuration yourself), make | |
| 1478 | + * these changes as soon as possible to prevent security risks to your environment. | |
| 1479 | + * Regardless of the method used, it is always your responsibility to validate | |
| 1480 | + * configurations received from external sources. | |
| 1481 | + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials | |
| 1361 | 1482 | * hostname is provided via `$options.bucketBoundHostname`. If a |
| 1362 | 1483 | * custom bucketBoundHostname is provided, **defaults to** `http`. |
| 1363 | 1484 | * In all other cases, **defaults to** `https`. |
| 1364 | 1485 | * @type string|array $scopes One or more authentication scopes to be |
| @@ -1374,9 +1495,9 @@ | ||
| 1374 | 1495 | public function generateSignedPostPolicyV4($objectName, $expires, array $options = []) |
| 1375 | 1496 | { |
| 1376 | 1497 | // May be overridden for testing. |
| 1377 | 1498 | $signingHelper = $this->pluck('helper', $options, \false) ?: SigningHelper::getHelper(); |
| 1378 | - $resource = sprintf('/%s/%s', $this->identity['bucket'], $objectName); | |
| 1499 | + $resource = \sprintf('/%s/%s', $this->identity['bucket'], $objectName); | |
| 1379 | 1500 | return $signingHelper->v4PostPolicy($this->connection, $expires, $resource, $options); |
| 1380 | 1501 | } |
| 1381 | 1502 | /** |
| 1382 | 1503 | * Determines if an object name is required. |
| @@ -1385,9 +1506,9 @@ | ||
| 1385 | 1506 | * @return bool |
| 1386 | 1507 | */ |
| 1387 | 1508 | private function isObjectNameRequired($data) |
| 1388 | 1509 | { |
| 1389 | - return is_string($data) || is_null($data); | |
| 1510 | + return \is_string($data) || \is_null($data); | |
| 1390 | 1511 | } |
| 1391 | 1512 | /** |
| 1392 | 1513 | * Return a topic name in its fully qualified format. |
| 1393 | 1514 | * |
| @@ -1398,18 +1519,18 @@ | ||
| 1398 | 1519 | */ |
| 1399 | 1520 | private function getFormattedTopic($topic) |
| 1400 | 1521 | { |
| 1401 | 1522 | if ($topic instanceof Topic) { |
| 1402 | - return sprintf(self::NOTIFICATION_TEMPLATE, $topic->name()); | |
| 1523 | + return \sprintf(self::NOTIFICATION_TEMPLATE, $topic->name()); | |
| 1403 | 1524 | } |
| 1404 | - if (!is_string($topic)) { | |
| 1405 | - throw new \InvalidArgumentException('$topic may only be a string or instance of Google\Cloud\PubSub\Topic'); | |
| 1525 | + if (!\is_string($topic)) { | |
| 1526 | + throw new \InvalidArgumentException('Dudlewebs\\WPMCS\\GCP\\$topic may only be a string or instance of Google\\Cloud\\PubSub\\Topic'); | |
| 1406 | 1527 | } |
| 1407 | - if (preg_match('/projects\/[^\/]*\/topics\/(.*)/', $topic) === 1) { | |
| 1408 | - return sprintf(self::NOTIFICATION_TEMPLATE, $topic); | |
| 1528 | + if (\preg_match('/projects\\/[^\\/]*\\/topics\\/(.*)/', $topic) === 1) { | |
| 1529 | + return \sprintf(self::NOTIFICATION_TEMPLATE, $topic); | |
| 1409 | 1530 | } |
| 1410 | 1531 | if (!$this->projectId) { |
| 1411 | 1532 | throw new GoogleException('No project ID was provided, ' . 'and we were unable to detect a default project ID.'); |
| 1412 | 1533 | } |
| 1413 | - return sprintf(self::NOTIFICATION_TEMPLATE, sprintf(self::TOPIC_TEMPLATE, $this->projectId, $topic)); | |
| 1534 | + return \sprintf(self::NOTIFICATION_TEMPLATE, \sprintf(self::TOPIC_TEMPLATE, $this->projectId, $topic)); | |
| 1414 | 1535 | } |
| 1415 | 1536 | } |