Addressed code review comments · Jsorbito/php-docs-samples@fe97268 · GitHub
Skip to content

Commit fe97268

Browse files
committed
Addressed code review comments
1 parent 3182b93 commit fe97268

10 files changed

Lines changed: 98 additions & 151 deletions

auth/README.md

Lines changed: 3 additions & 4 deletions

auth/app-standard.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ threadsafe: true
55
handlers:
66
- url: /.*
77
script: index.php
8-
9-
env_variables:
10-
GCLOUD_PROJECT: your-project-id

auth/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
"require": {
33
"google/apiclient": "^2.1",
44
"google/cloud-storage": "^1.0",
5-
"paragonie/random_compat": "^2.0",
65
"symfony/console": " ^3.0",
7-
"google/auth":"^0.11"
6+
"google/auth":"^1.0"
87
},
98
"autoload": {
109
"psr-4": {

auth/composer.lock

Lines changed: 30 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth/index.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,30 @@
1818
namespace Google\Cloud\Samples\Auth;
1919

2020
use Google\Auth\Credentials\GCECredentials;
21+
use google\appengine\api\app_identity\AppIdentityService;
2122

22-
// Install composer dependencies with "composer install"
23-
// @see http://getcomposer.org for more information.
2423
require __DIR__ . '/vendor/autoload.php';
2524

26-
print('<pre>');
27-
if (GCECredentials::onGce()) {
28-
printf("Buckets retrieved using the cloud client library:\n");
29-
auth_cloud_explicit_compute_engine(getenv('GCLOUD_PROJECT'));
30-
printf("\n");
31-
printf("Buckets retrieved using the api client:\n");
32-
auth_api_explicit_compute_engine(getenv('GCLOUD_PROJECT'));
33-
} else {
34-
printf("Buckets retrieved using the cloud client library:\n");
35-
auth_cloud_explicit_app_engine(getenv('GCLOUD_PROJECT'));
36-
printf("\n");
37-
printf("Buckets retrieved using the api client:\n");
38-
auth_api_explicit_app_engine(getenv('GCLOUD_PROJECT'));
39-
}
40-
print('</pre>');
25+
$onGce = GCECredentials::onGce();
26+
$projectId = $onGce
27+
? getenv('GCLOUD_PROJECT')
28+
: AppIdentityService::getApplicationId();
29+
?>
30+
31+
<h1>Buckets retrieved using the cloud client library:</h1>
32+
<pre>
33+
<?php if ($onGce): ?>
34+
<?php auth_cloud_explicit_compute_engine($projectId) ?>
35+
<?php else: ?>
36+
<?php auth_cloud_explicit_app_engine($projectId) ?>
37+
<?php endif ?>
38+
</pre>
39+
40+
<h1>Buckets retrieved using the api client:</h1>
41+
<pre>
42+
<?php if ($onGce): ?>
43+
<?php auth_api_explicit_compute_engine($projectId) ?>
44+
<?php else: ?>
45+
<?php auth_api_explicit_app_engine($projectId) ?>
46+
<?php endif ?>
47+
</pre>

auth/src/auth_api_explicit_app_engine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function auth_api_explicit_app_engine($projectId)
3636
{
3737
# Learn more about scopes at https://cloud.google.com/storage/docs/authentication#oauth-scopes
3838
$scope = 'https://www.googleapis.com/auth/devstorage.read_only';
39-
$gae_credentials = new AppIdentityCredentials($scope);
40-
$middleware = new AuthTokenMiddleware($gae_credentials);
39+
$gaeCredentials = new AppIdentityCredentials($scope);
40+
$middleware = new AuthTokenMiddleware($gaeCredentials);
4141
$stack = HandlerStack::create();
4242
$stack->push($middleware);
4343
$http_client = new Client([

auth/src/auth_api_explicit_compute_engine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
function auth_api_explicit_compute_engine($projectId)
3636
{
37-
$gce_credentials = new GCECredentials();
38-
$middleware = new AuthTokenMiddleware($gce_credentials);
37+
$gceCredentials = new GCECredentials();
38+
$middleware = new AuthTokenMiddleware($gceCredentials);
3939
$stack = HandlerStack::create();
4040
$stack->push($middleware);
4141
$http_client = new Client([

auth/src/auth_cloud_explicit_app_engine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ function auth_cloud_explicit_app_engine($projectId)
3131
{
3232
# Learn more about scopes at https://cloud.google.com/storage/docs/authentication#oauth-scopes
3333
$scope = 'https://www.googleapis.com/auth/devstorage.read_only';
34-
$gae_credentials = new AppIdentityCredentials($scope);
34+
$gaeCredentials = new AppIdentityCredentials($scope);
3535
$config = [
3636
'projectId' => $projectId,
37-
'credentialsFetcher' => $gae_credentials,
37+
'credentialsFetcher' => $gaeCredentials,
3838
];
3939
$storage = new StorageClient($config);
4040

auth/src/auth_cloud_explicit_compute_engine.php

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)