Google-cloud-php: Client library is attempting to connect to www.googleapis.com

Created on 2 Nov 2017  Â·  9Comments  Â·  Source: googleapis/google-cloud-php

Without an internet connection (due to traveling, limited Internet), any request to the local datastore emulator will fail because the google-cloud-php client library is attempting to contact www.googleapis.com.

I spoke to the datastore emulator team, and they confirmed they designed the Cloud Datastore Emulator to be usable without an internet connection. They requested I file this as a bug in the google-cloud-php client library.

Using version ^0.40.0 for google/cloud

Simple query produces the following without an internet connection:

PHP Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: cURL error 6: Could not resolve host: www.googleapis.com (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Core/RequestWrapper.php:253
Stack trace:

0 /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Core/RequestWrapper.php(158): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(Google\Cloud\Core\Exception\ServiceException))

1 /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Core/RestTrait.php(95): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)

2 /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Datastore/Connection/Rest.php(105): Google\Cloud\Datastore\Connection\Rest->send('projects', 'runQuery', Array)

3 /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Core/Iterator/PageIteratorTrait.php(233): Google\Cloud\Datastore\Connection\Rest->runQuery(Array)

4 /home/dev/source/composer- in /home/dev/source/composer-google-cloud/vendor/google/cloud/src/Core/RequestWrapper.php on line 253

Confirmed I can directly access the emulator via curl without an Internet connection:

$ curl http://192.168.56.1:8081/
Ok

datastore p2 bug

Most helpful comment

@dwsupplee setting 'shouldSignRequest' to false did the trick. Thank you! I agree this should be the default behavior for when the emulator is in use. Also thanks to @jdpedrie @wsh @bshaffer for being on top of this bug report.

All 9 comments

Hi @lukasgit,

Can you confirm a couple things?

Firstly, did you start the emulator with the automatic environment variable configuration?

In the Command Line:

$(gcloud beta emulators datastore env-init)

If so, check to be sure the env var is set as expected:

echo $DATASTORE_EMULATOR_HOST

You should see a hostname or IP and port 8081, generally.

If this works, try in a PHP script:

<?php
echo getenv('DATASTORE_EMULATOR_HOST');

Run this in the same context as your application (i.e. if you run your app from the command line, run this script at the command line. If in a web server, run in the web server).

If you see the expected value at the CLI but not in your PHP script, you can manually set the environment variable in your PHP application, so long as you make sure to remove it when you go back to using the real service!

putenv('DATASTORE_EMULATOR_HOST=<emulator-host>:<emulator-port>');

If none of that works, please let us know!

@lukasgit, it looks like this is because the library is still attempting to sign requests even though it is working through the emulator. To temporarily work around this, you should be able to pass in the following flag to your datastore client:

$ds = new DatastoreClient([
    'shouldSignRequest' => false
]);

We need to make this default behavior for whenever an emulator is in use. Thanks for the report!

@dwsupplee thanks for your fast response. I was about to say that @lukasgit had in fact done what @jdpedrie has asked. cc @bshaffer

@dwsupplee setting 'shouldSignRequest' to false did the trick. Thank you! I agree this should be the default behavior for when the emulator is in use. Also thanks to @jdpedrie @wsh @bshaffer for being on top of this bug report.

yay!

Let’s keep this open to track the bug fix. 😃

In the google-cloud-java and google-cloud-python libraries, I believe we go a step further and allow the emulator to be used without providing a credential at all (i.e. we don't call into the Application Default Credentials library). Is that a possibility here?

@eddavisson, yes that certainly would be something we can consider here as well :)

@eddavisson, that would be ideal and highly recommended for people
evaluating. When we were evaluating Google Datastore, having to create a
credential just for testing was confusing because it goes agains the
Datastore documentation and required us to create a live credential for
testing a local emulator.

On Mon, Nov 6, 2017 at 9:13 AM, David Supplee notifications@github.com
wrote:

@eddavisson https://github.com/eddavisson, yes that certainly would be
something we can consider here as well :)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/GoogleCloudPlatform/google-cloud-php/issues/726#issuecomment-342218353,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJ0KD11veOJLJUjm27JD6mZIVl4D9kJmks5szz4lgaJpZM4QQGUP
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

castaneai picture castaneai  Â·  4Comments

dwsupplee picture dwsupplee  Â·  7Comments

ruschoni02 picture ruschoni02  Â·  6Comments

castaneai picture castaneai  Â·  7Comments

mjniuz picture mjniuz  Â·  6Comments