Skip to content

Commit fe97268

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

10 files changed

+98
-151
lines changed

auth/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ methods will work on any Google Cloud API.
1919
$ cd php-docs-samples/auth
2020
```
2121
4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
22-
Run `php composer.phar install` (if composer is installed locally) or `composer install`
22+
Run `php composer.phar install --no-dev` (if composer is installed locally) or `composer install --no-dev`
2323
(if composer is installed globally).
2424
5. Run `php auth.php`. The following commands are available and work on command line:
2525
```
@@ -41,9 +41,8 @@ method only works on App Engine Standard.
4141
7. You can test the samples that use Compute Engine / App Engine credentials by
4242
deploying to either App Engine Flexible (which allows usage of Compute Engine
4343
credentials since App Engine Flexible apps run on Compute Engine instances) or
44-
App Engine Standard. If you are deploying to App Engine Standard, first open
45-
`app-standard.yaml` and set the value of `GCLOUD_PROJECT` to your project ID.
46-
Run either `gcloud app deploy app-standard.yaml` or `gcloud app deploy app-flex.yaml`.
44+
App Engine Standard. Run either `gcloud app deploy app-standard.yaml` or
45+
`gcloud app deploy app-flex.yaml`.
4746

4847
8. Run `php auth.php COMMAND --help` to print information about the usage of each command.
4948

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('
');
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('');
25+
$onGce = GCECredentials::onGce();
26+
$projectId = $onGce
27+
? getenv('GCLOUD_PROJECT')
28+
: AppIdentityService::getApplicationId();
29+
?>
30+
31+

Buckets retrieved using the cloud client library:

32+
33+
if ($onGce): ?>
34+
auth_cloud_explicit_compute_engine($projectId) ?>
35+
else: ?>
36+
auth_cloud_explicit_app_engine($projectId) ?>
37+
endif ?>
38+
39+
40+

Buckets retrieved using the api client:

41+
42+
if ($onGce): ?>
43+
auth_api_explicit_compute_engine($projectId) ?>
44+
else: ?>
45+
auth_api_explicit_app_engine($projectId) ?>
46+
endif ?>
47+

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
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
function auth_cloud_explicit_compute_engine($projectId)
3131
{
32-
$gce_credentials = new GCECredentials();
32+
$gceCredentials = new GCECredentials();
3333
$config = [
3434
'projectId' => $projectId,
35-
'credentialsFetcher' => $gce_credentials,
35+
'credentialsFetcher' => $gceCredentials,
3636
];
3737
$storage = new StorageClient($config);
3838

0 commit comments

Comments
 (0)