PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / S3 / Crypto / InstructionFileMetadataStrategy.php
transferito / vendor / aws / aws-sdk-php / src / S3 / Crypto Last commit date
CryptoParamsTrait.php 11 months ago CryptoParamsTraitV2.php 11 months ago HeadersMetadataStrategy.php 11 months ago InstructionFileMetadataStrategy.php 11 months ago S3EncryptionClient.php 11 months ago S3EncryptionClientV2.php 11 months ago S3EncryptionMultipartUploader.php 11 months ago S3EncryptionMultipartUploaderV2.php 11 months ago UserAgentTrait.php 11 months ago
InstructionFileMetadataStrategy.php
91 lines
1 <?php
2 namespace Aws\S3\Crypto;
3
4 use \Aws\Crypto\MetadataStrategyInterface;
5 use \Aws\Crypto\MetadataEnvelope;
6 use \Aws\S3\S3Client;
7
8 /**
9 * Stores and reads encryption MetadataEnvelope information in a file on Amazon
10 * S3.
11 *
12 * A file with the contents of a MetadataEnvelope will be created or read from
13 * alongside the base file on Amazon S3. The provided client will be used for
14 * reading or writing this object. A specified suffix (default of '.instruction'
15 * will be applied to each of the operations involved with the instruction file.
16 *
17 * If there is a failure after an instruction file has been uploaded, it will
18 * not be automatically deleted.
19 */
20 class InstructionFileMetadataStrategy implements MetadataStrategyInterface
21 {
22 const DEFAULT_FILE_SUFFIX = '.instruction';
23
24 private $client;
25 private $suffix;
26
27 /**
28 * @param S3Client $client Client for use in uploading the instruction file.
29 * @param string|null $suffix Optional override suffix for instruction file
30 * object keys.
31 */
32 public function __construct(S3Client $client, $suffix = null)
33 {
34 $this->suffix = empty($suffix)
35 ? self::DEFAULT_FILE_SUFFIX
36 : $suffix;
37 $this->client = $client;
38 }
39
40 /**
41 * Places the information in the MetadataEnvelope to a location on S3.
42 *
43 * @param MetadataEnvelope $envelope Encryption data to save according to
44 * the strategy.
45 * @param array $args Starting arguments for PutObject, used for saving
46 * extra the instruction file.
47 *
48 * @return array Updated arguments for PutObject.
49 */
50 public function save(MetadataEnvelope $envelope, array $args)
51 {
52 $this->client->putObject([
53 'Bucket' => $args['Bucket'],
54 'Key' => $args['Key'] . $this->suffix,
55 'Body' => json_encode($envelope)
56 ]);
57
58 return $args;
59 }
60
61 /**
62 * Uses the strategy's client to retrieve the instruction file from S3 and generates
63 * a MetadataEnvelope from its contents.
64 *
65 * @param array $args Arguments from Command and Result that contains
66 * S3 Object information, relevant headers, and command
67 * configuration.
68 *
69 * @return MetadataEnvelope
70 */
71 public function load(array $args)
72 {
73 $result = $this->client->getObject([
74 'Bucket' => $args['Bucket'],
75 'Key' => $args['Key'] . $this->suffix
76 ]);
77
78 $metadataHeaders = json_decode($result['Body'], true);
79 $envelope = new MetadataEnvelope();
80 $constantValues = MetadataEnvelope::getConstantValues();
81
82 foreach ($constantValues as $constant) {
83 if (!empty($metadataHeaders[$constant])) {
84 $envelope[$constant] = $metadataHeaders[$constant];
85 }
86 }
87
88 return $envelope;
89 }
90 }
91