Skip to content

Commit

Permalink
fix object factory w/ customer supplied encryption (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee authored and jdpedrie committed Oct 13, 2016
1 parent cc6af0c commit 1c1be26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Storage/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -229,7 +232,9 @@ public function upload($data, array $options = [])
$response['name'],
$this->identity['bucket'],
$response['generation'],
$response
$response,
$encryptionKey,
$encryptionKeySHA256
);
}

Expand Down Expand Up @@ -337,6 +342,7 @@ public function object($name, array $options = [])
$name,
$this->identity['bucket'],
$generation,
null,
$encryptionKey,
$encryptionKeySHA256
);
Expand Down
6 changes: 4 additions & 2 deletions tests/Storage/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1c1be26

Please sign in to comment.