-
Notifications
You must be signed in to change notification settings - Fork 192
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
Replaced getenv/putenv with $_ENV
and unset
#429
Conversation
808a700
to
444a468
Compare
444a468
to
b6ece9b
Compare
$_ENV
and unset
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
@DracoBlue thanks for making this PR. I want to check once whether there was any reason for using |
$_ENV
and unset
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DracoBlue Sorry for the confusing bot message, your previous PR title was correct, and it was just giving a warning to us (the administrators) in case we merged with the commit message instead of the PR title, which was in the incorrect format. I fixed this in #430, so this message will no longer happen.
As for this PR, unfortunately, the changes here break existing implementations. If someone is setting their credentials using putenv
(as we've instructed them to do), this library would no longer work as expected. This is unacceptable.
I can see three options:
- Wait to make these changes in a v2 version
- Check
getenv
first and_ENV
second. (This seems like it would cause even more issues) - Provide a way (similar to symphony's
usePutenv
function, perhaps even use an environment variable as a flag 😛) to use the threadsafe version, e.g.:
$_ENV['GOOGLE_AUTH_USE_PUTENV']=false
$_ENV['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/credentials.json'';
There are some other implications of switching from getenv
/putenv
that aren't discussed in this PR, along with the implications of these functions not being threadsafe. Do you have any links to discussions of the implications?
Thanks for your reply! You are right.
I added some more threads related to this to the initial post.
I think so, too.
I guess for this to be interesting enough to implement, I would suggest I am supplying a test case (I don't have a proper one, yet!) which suffers from the getenv/putenv threadsafety issue - and then we can think about a way to make it possible for those using the frameworks possible to supply the credentials variable in a safe way. |
I've moved this into a feature request here: #432
Yes! If you have one, or find one, please update the above issue! I'm closing this for now since we will not be using this implementation. |
The current version of google auth library php uses getenv/putenv to read and set environment variables in php. But the function putenv is not threadsafe, which made libraries (Dotenv https://github.com/symfony/dotenv/blob/6.2/Dotenv.php#L61 and phpdotenv https://github.com/vlucas/phpdotenv#putenv-and-getenv) to disable putenv support by default. Frameworks like symfony (deprecated in 4.3 symfony/symfony#31062 and removed in 5.0) and also in laravel there was a similiar solution to not use it anymore directly (vlucas/phpdotenv#76).
Thus here is a pull request to change all the ocurences of:
getenv($variable)
toarray_key_exists($variable, $_ENV) ? $_ENV[$variable] : false
putenv($variable)
tounset($_ENV[$variable])
putenv($variable . "=")
to$_ENV[$variable]=''
putenv($variable . "=" . $value)
to$_ENV[$variable]=$value
Threads about this: