Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceBuilder option keyFile is type string, but treated as associative array in makeCredentials #296

Closed
ras44 opened this issue Dec 28, 2016 · 4 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@ras44
Copy link

ras44 commented Dec 28, 2016

ServiceBuilder.php describes the config keyFile option with:

     *     @type string $keyFile The contents of the service account
     *           credentials .json file retrieved from the Google Developer's
     *           Console.

Providing the contents of the service account credentials as a string, however, with:

 $builder = new ServiceBuilder([
          'projectId' => $projectId,
          'keyFile' => '<service account credentials here>'
]);

results in CredentialsLoader.php->makeCredentials($scope, array $jsonKey) throwing an error:

array_key_exists() expects parameter 2 to be array, string given

The service account credentials can be converted to an associative array to resolve the issue, however the definition of keyFile as a string in ServiceBuilder.php differs from its treatment in CredentialsLoader.php.

As an aside or possibly separate issue, when CredentialsLoader.php->makeCredentials($scope, array $jsonKey) calls new return new ServiceAccountCredentials($scope, $jsonKey);, /src/Credentials/ServiceAccountCredentials.php treats $jsonKey as potentially being a filename:

        if (is_string($jsonKey)) {
            if (!file_exists($jsonKey)) {
                throw new \InvalidArgumentException('file does not exist');
            }

indicating that if keyFile is provided as a string, it is treated as a filename rather than a string to be converted to an associative array.

@dwsupplee
Copy link
Contributor

Hey @ras44,

This looks like a mistake on our part and the correct type is (as you discovered) array. I've opened a PR to address this, thanks for the thorough report and bringing it to our attention :).

@ras44
Copy link
Author

ras44 commented Dec 28, 2016

Thanks @dwsupplee - it's been a great API to work within

@ras44
Copy link
Author

ras44 commented Dec 28, 2016

@dwsupplee it looks like this issue might also be present in the following files (fyi- I haven't checked each one individually):

vendor/google/cloud/src/BigQuery/BigQueryClient.php
vendor/google/cloud/src/Logging/LoggingClient.php
vendor/google/cloud/src/NaturalLanguage/NaturalLanguageClient.php
vendor/google/cloud/src/PubSub/PubSubClient.php
vendor/google/cloud/src/RequestWrapper.php
vendor/google/cloud/src/ServiceBuilder.php
vendor/google/cloud/src/Storage/StorageClient.php
vendor/google/cloud/src/Vision/VisionClient.php

@jdpedrie
Copy link
Contributor

Hi @ras44,

@dwsupplee's change also updated the documentation in each of those files. We just tagged v0.20.1, so you should see the updated documentation on our docs site in a few minutes.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants