This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off, great work to the creators and or maintainers. I've relied on this project for a few years on numerous projects, it's been awesome, I'm glad that I can contribute here.
The issue started when key_file was allowed to be an array, the code was changed and we ran into the original array_merge issue #57 & #59 that I had created. The error was that array_merge would throw an exception that its given parameters could not be null. The fix was to write an is_array check, and if it failed then it would set $keyFile to an empty array.
While this fixed the array_merge issue, it did not fix the underlying problem, which was that the code, currently, will always return a new StorageClient with a key_file. Even if it is null, as long as the key 'key_file' exists the constructor array, the Google\Cloud\Storage\StorageClient will try to look for it, and it will fail throwing null errors on missing or incorrect data. This prevents and breaks all built-in service accounts from working without explicitly setting a .json file.
Now the key_file parameter (while it may work if a file path is passed into it, not sure) is actually for passing in the config in an array directly (like it says in the laravel-google-cloud-storage readme), and key_file_path is for the file path of the json file that Google\Cloud\Storage\StorageClient->Google\Cloud\Core\ClientTrait::getKeyFile() will read and run a
json_decode(file_get_contents(key_file_path)
on to get an array of parameters.I rewrote createClient() to do the following (in pseudo code below)
`
get from config key_file_path
if is_string(key_file_path) and key_file_path is not empty()
Give us our storage client and tell Google to use our key_file_path file
if that fails
get from config key_file
if is_array(key_file) and key_file_path is not empty()
Give us our storage client and tell Google to use our key_file array as its config
if that fails
Give us our storage client and tell google we don't have any configuration to give it
`
Now that since Google didn't receive any configuration (given key_file_path and key_file are null), it searches on its own (GOOGLE_APPLICATION_CREDENTIALS, well known OS specific files, and built-in service accounts). With this patch, everything works as expected from the README.
That should bring this issue to a close. Sorry if my php-cs-fixer formatted the code base. It was automatic. I updated the readme to reflect the changes in the config, to match the new code, as well as updating the changelog.