Skip to content

Commit

Permalink
Provide project ID in storage connection (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Sep 20, 2017
1 parent 7f73556 commit fa7977f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Storage/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class Rest implements ConnectionInterface
const UPLOAD_URI = 'https://www.googleapis.com/upload/storage/v1/b/{bucket}/o{?query*}';
const DOWNLOAD_URI = 'https://www.googleapis.com/storage/v1/b/{bucket}/o/{object}{?query*}';

/**
* @var string
*/
private $projectId;

/**
* @param array $config
*/
Expand All @@ -58,6 +63,16 @@ public function __construct(array $config = [])
$config['serviceDefinitionPath'],
self::BASE_URI
));

$this->projectId = $this->pluck('projectId', $config, false);
}

/**
* @return string
*/
public function projectId()
{
return $this->projectId;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Storage/StorageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function __construct(array $config = [])
$config['scopes'] = [self::FULL_CONTROL_SCOPE];
}

$this->connection = new Rest($this->configureAuthentication($config));
$this->connection = new Rest($this->configureAuthentication($config) + [
'projectId' => $this->projectId
]);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/Storage/Connection/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public function methodProvider()
];
}

public function testProjectId()
{
$rest = new Rest(['projectId' => 'foo']);
$this->assertEquals('foo', $rest->projectId());
}

public function testProjectIdNull()
{
$rest = new Rest();
$this->assertNull($rest->projectId());
}

public function testDownloadObject()
{
$actualRequest = null;
Expand Down

0 comments on commit fa7977f

Please sign in to comment.