From 1c1be261c0d4ed4a0670c1632ee2caf2aa4577c3 Mon Sep 17 00:00:00 2001 From: David Supplee Date: Thu, 13 Oct 2016 13:47:24 -0400 Subject: [PATCH] fix object factory w/ customer supplied encryption (#202) --- src/Storage/Bucket.php | 8 +++++++- tests/Storage/BucketTest.php | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Storage/Bucket.php b/src/Storage/Bucket.php index bbe022572965..87939ed9a023 100644 --- a/src/Storage/Bucket.php +++ b/src/Storage/Bucket.php @@ -217,6 +217,9 @@ public function upload($data, array $options = []) throw new \InvalidArgumentException('A name is required when data is of type string.'); } + $encryptionKey = isset($options['encryptionKey']) ? $options['encryptionKey'] : null; + $encryptionKeySHA256 = isset($options['encryptionKeySHA256']) ? $options['encryptionKeySHA256'] : null; + $response = $this->connection->insertObject( $this->formatEncryptionHeaders($options) + [ 'bucket' => $this->identity['bucket'], @@ -229,7 +232,9 @@ public function upload($data, array $options = []) $response['name'], $this->identity['bucket'], $response['generation'], - $response + $response, + $encryptionKey, + $encryptionKeySHA256 ); } @@ -337,6 +342,7 @@ public function object($name, array $options = []) $name, $this->identity['bucket'], $generation, + null, $encryptionKey, $encryptionKeySHA256 ); diff --git a/tests/Storage/BucketTest.php b/tests/Storage/BucketTest.php index b50146b011f1..4e50e91f8b96 100644 --- a/tests/Storage/BucketTest.php +++ b/tests/Storage/BucketTest.php @@ -121,12 +121,14 @@ public function testGetObject() $this->assertInstanceOf('Google\Cloud\Storage\StorageObject', $bucket->object('peter-venkman.jpg')); } - public function testInstantiateObjectWithGeneration() + public function testInstantiateObjectWithOptions() { $bucket = new Bucket($this->connection->reveal(), 'bucket'); $object = $bucket->object('peter-venkman.jpg', [ - 'generation' => '5' + 'generation' => '5', + 'encryptionKey' => 'abc', + 'encryptionKeySHA256' => '123' ]); $this->assertInstanceOf('Google\Cloud\Storage\StorageObject', $object);