Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

(ServiceException) json key is missing the type field #60

Open
ralfiannor opened this issue Apr 25, 2019 · 39 comments
Open

(ServiceException) json key is missing the type field #60

ralfiannor opened this issue Apr 25, 2019 · 39 comments

Comments

@ralfiannor
Copy link

I updated to latest version 2.2.1 and get that if i upload image to bucket.

@nicja nicja self-assigned this Apr 25, 2019
@nicja
Copy link
Contributor

nicja commented Apr 25, 2019

Could you please provide a full stack trace, and the contents of your config file?

@ralfiannor
Copy link
Author

Could you please provide a full stack trace, and the contents of your config file?

I use Google App Engine
Use config in filesystem laravel :
'gcs' => [ 'driver' => 'gcs', 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket 'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below ],

Before update my code work successfull.

ralfiannor added a commit to ralfiannor/laravel-google-cloud-storage that referenced this issue Apr 25, 2019
Fix logic if keyFile is null
@nicja
Copy link
Contributor

nicja commented Apr 25, 2019

The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..

Please can you provide:
1: The full stack trace for the ServiceException
2: The value of env('GOOGLE_CLOUD_KEY_FILE', null)

The only way I can see this working is if env('GOOGLE_CLOUD_KEY_FILE', null) === null

@ralfiannor
Copy link
Author

The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..

Please can you provide:
1: The full stack trace for the ServiceException
2: The value of env('GOOGLE_CLOUD_KEY_FILE', null)

The only way I can see this working is if env('GOOGLE_CLOUD_KEY_FILE', null) === null

Its same with my logic bro. If you learn clean code dont use === null in if argument

@nicja nicja removed their assignment Apr 25, 2019
@alfin-efendy
Copy link

i get same issue, basically my laravel project running on google app yesterday still working fine without use GOOGLE_CLOUD_KEY_FILE but now i get this error.

Screen Shot 2019-04-26 at 13 26 26

@MaggotMouth
Copy link

Can you please update your config and replace

'project_id' => env('GOOGLE_CLOUD_PROJECT_ID')

with

'project_id' => env('GOOGLE_CLOUD_PROJECT')

and let me know if it works for you then

@alfin-efendy
Copy link

i still get same error bro, and how if i use the json key for my google app engine, because i try put my directory of json key in my locahost project and it's work but if i deploy to app engine still get this issue, thanks for your help.

Screen Shot 2019-04-26 at 15 19 40

@nicja
Copy link
Contributor

nicja commented Apr 26, 2019

Can you tell me if env('GOOGLE_CLOUD_KEY_FILE', null) is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks

@alfin-efendy
Copy link

i have solve it with this step :

Screen Shot 2019-04-26 at 16 46 59

@nicja
Copy link
Contributor

nicja commented Apr 26, 2019

@alfin87aa @ralfiannor Are you satisfied with this solution or do you need it to be able to work with a null key_file?

@alfin-efendy
Copy link

@nicja @MaggotMouth for me it's enough, thanks for your help 👍

@ralfiannor
Copy link
Author

ralfiannor commented Apr 27, 2019

Can you tell me if env('GOOGLE_CLOUD_KEY_FILE', null) is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks

Work perfect if i edit your code to handle null. Please, merge my pull request #61 and this issue will solve.
image

@ralfiannor
Copy link
Author

i have solve it with this step :

Screen Shot 2019-04-26 at 16 46 59

Add google credential file in your source project is bad. Dont try it in production.

@matthewgoslett
Copy link
Contributor

i have solve it with this step :

Screen Shot 2019-04-26 at 16 46 59

Add google credential file in your source project is bad. Dont try it in production.

You don't need to put it in your storage folder.
You can just deploy the key with your app to App Engine, then set the key_file to that file (outside of storage); or alternatively, don't set a key_file at all and just set the GOOGLE_APPLICATION_CREDENTIALS env var.

@phroggyy
Copy link

phroggyy commented May 9, 2019

@nicja this issue has wreaked havoc on us today. We need the ability to set 'key_file' => null as per the proposed PR.

I don't actually see why we need to do any array_merge at all though, since the project ID is already in the service key? Commented on that in the PR.

@cjcox17
Copy link

cjcox17 commented May 13, 2019

@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.

@hos-shams
Copy link

I've got a same issue on standard app engine. It doesn't work with GOOGLE_CLOUD_KEY_FILE set to null. As I can recall, it used to work on v2.1.0, but it has "json key is missing the type field" error now.

@EntonoX
Copy link

EntonoX commented Jun 5, 2019

I encountered the same issue today, i see a pull request is awaiting. Can anyone check / approve this?

@nicja
Copy link
Contributor

nicja commented Jun 5, 2019

Hi all, apologies for how long this has been outstanding. Unfortunately I can't test the specific scenarios that are broken. We now have 2 open PRs to fix this issue. I am in favour of #61 as it includes updates to the README. @cjcox17 @EntonoX @ralfiannor @shamsoft can you let me know if this PR solves the issue for you? Thanks!

EDIT: #63 is preferred, not #61

@EntonoX
Copy link

EntonoX commented Jun 5, 2019

@nicja I'm testing #63 right now, I can test #61 as well if this is a preferred PR. i'll report back today.

@nicja
Copy link
Contributor

nicja commented Jun 5, 2019

@EntonoX thank you! Apologies, I meant #63 which has the changes to the README

@EntonoX
Copy link

EntonoX commented Jun 5, 2019

@nicja I tested #63 locally and within GCS docker container. I was not able to get it working without using the service account key as a secret. (So i needed to provide the 'key_file_path' environment variable). Without this environment variable i got a 'insufficient permission' error.

I can not judge if this is a service account rights setting or some other problem. Maybe you or @cjcox17 can provide some details for this?

@matthewgoslett
Copy link
Contributor

🙏

I'm able to replicate this in GKE.
I'm not using a key file. I just want the lib to use the default service account of the instance, which the CredentialsLoader does as fallback.

I was able to hack around it by setting key_file in the config to an empty string. This passes the if (is_string($keyFile)) { check in createClient and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait, it fails their loose if ($config['keyFile']) { check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile(); which is what I want.

@cjcox17
Copy link

cjcox17 commented Jun 21, 2019

I'm using #63 in production without a key_file, I'll setup another instance this weekend to test.

@EntonoX @matthewgoslett Can you provide your filesystem.php config for the GCS disk? I'll use this when I'm testing.

@bredmor
Copy link

bredmor commented Jun 22, 2019

Set up the newest version of this today on a new App Engine instance and ran into the same issue.

I was able to hack around it by setting key_file in the config to an empty string. This passes the if (is_string($keyFile)) { check in createClient and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait, it fails their loose if ($config['keyFile']) { check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile(); which is what I want.

This solution worked for me, thank you @matthewgoslett

@cjcox17
Copy link

cjcox17 commented Jun 25, 2019

@matthewgoslett @bredmor You are experiencing the ongoing issue that the pending pull request fixes. Pull request #63 Works in these cases.

@ EntonoX @nicja I setup another Google Cloud Compute Engine Instance yesterday and verified the the pull request works as intended.

@EntonoX Verify that you're using the newest config file included in the pull request and verify that your instance has the proper permissions on the service account. For testing I simply select "Allow full access to all API's". The README has been updated as well.

Can you post your Laravel config, docker config, and a stack trace?

@nicja If there is a separate issue for Docker, Kubernetes, or Google Cloud App Engine, I think it would make sense to approve the current pull request to fix the current issue and address the other issue separately so people like @matthewgoslett and @bredmor and myself don't continue to run into this issue.

@ralfiannor
Copy link
Author

@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.

it's ok bro.

@ralfiannor ralfiannor reopened this Jul 6, 2019
@alexcaselli
Copy link

I was deploying on GAE flexible environment and i got that error too, my config is like this:
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json

Has been found a solution?

@ralfiannor
Copy link
Author

I was deploying on GAE flexible environment and i got that error too, my config is like this:
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json

Has been found a solution?

Downgrade version until fix version release.

@hussonkevin
Copy link

Hi found the solution... set :
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem

@WouterFlorijn
Copy link

@nicja do you have an update on this issue? I'm getting it as well. Thanks!

@prazian
Copy link

prazian commented Mar 22, 2020

The empty string hack worked for me on the Kubernetes engine in GCP.

@matbour
Copy link

matbour commented Mar 26, 2020

The empty string hack worked for me on the Kubernetes engine in GCP.

I can confirm that it works on my workstation too. However, we really need to ability to set the key_file option to null or to not pass it at all.

@DavidRichardDev
Copy link

Hi found the solution... set :
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem

This solution solved my error.

Tks

@sagikazarmark
Copy link

Is there anything we can do to get this fixed? Do you need any more information? As far as I can tell, there are numerous PRs addressing this issue and the issue itself is quite obvious as well IMHO.

@iansltx
Copy link

iansltx commented Sep 28, 2020

Add my PR to the list of ones fixing this issue.

@alecogt
Copy link

alecogt commented May 13, 2021

Hi found the solution... set :
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem

Setting an empty key worked for me. I added it to the env_variables part of app.yaml:
runtime: php74
...
env_variables:
GOOGLE_APPLICATION_CREDENTIALS: ""
GOOGLE_CLOUD_KEY_FILE: ""
...

@Dov1s
Copy link

Dov1s commented May 21, 2021

Hi found the solution... set :
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem

Setting an empty key worked for me. I added it to the env_variables part of app.yaml:
runtime: php74
...
env_variables:
GOOGLE_APPLICATION_CREDENTIALS: ""
GOOGLE_CLOUD_KEY_FILE: ""
...

Thank you! It worked.

@ocielgarrido
Copy link

Muy Util, descague el json desde ahi y funcionó a la primera muchas gracias

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests