google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

[Translate] Warning when using ADC + API Key

Open clundin25 opened this issue 1 year ago • 7 comments

Moving forward API key will have preference over ADC.

I believe this error message is unnecessary and possibly confusing for API key users.

Should it be removed?

https://github.com/googleapis/google-cloud-java/blob/f16bc31f2e0e9e3febab45a214e48688d46b49eb/java-translate/google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateOptions.java#L166

clundin25 avatar Aug 01 '24 23:08 clundin25

@clundin25 Thanks for reporting this issue! I agree we should remove this warning. In addition, is the current authentication order correct? In which explicitly set Credentials has preference over API keys.

Also moving this issue back to google-cloud-java as this is a handwritten layer on top of GAPIC(We do have a few of them in the mono repo).

blakeli0 avatar Aug 05 '24 15:08 blakeli0

I think the order should be:

    // 1. explicitly set API key
    // 2. explicitly set credentials

It's less clear to me what the ENV variable order should be.

clundin25 avatar Aug 05 '24 16:08 clundin25

@clundin25 Would there be any problem if we change the order? The comment seems to indicate that the backend is expecting this specific order to avoid conflict.

blakeli0 avatar Aug 05 '24 19:08 blakeli0

I don't think the issue is the order, rather that both the api key and credential are in the same request. If they are not source from the same project, the request will fail.

So as long as the code chooses only one, it should not be a problem.

clundin25 avatar Aug 05 '24 20:08 clundin25

Is Java the only language that flags an error if the two credentials are from a different project? What do other languages do in this situation-- and what order do they use? The last thing we need is different behavior depending on language. This should be spec'ed out somewhere.

piaxc avatar Aug 06 '24 22:08 piaxc

Is Java the only language that flags an error if the two credentials are from a different project?

This enforced from the server so it should not work for any language.

What do other languages do in this situation-- and what order do they use?

I think only Python and Go support API keys for GAPIC, and neither support the env variable.

I believe only this library and Ruby reference the "GOOGLE_API_KEY" ENV variable. PHP does seem to use it in a test case.

https://github.com/search?q=org%3Agoogleapis+GOOGLE_API_KEY+-lang%3Amarkdown+-lang%3Ayaml&type=code

clundin25 avatar Aug 06 '24 22:08 clundin25

only this library

Yes, this specific code is in handwritten only for this library. Other GAPIC libraries do not support API keys through client settings yet. We documented authenticating through headers in our README.

blakeli0 avatar Aug 07 '24 14:08 blakeli0

fixed with PR

ldetmer avatar Dec 06 '24 14:12 ldetmer