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

[9.x] Prevents booting providers when running env:decrypt #44654

Merged
merged 14 commits into from
Oct 20, 2022

Conversation

joedixon
Copy link
Contributor

@joedixon joedixon commented Oct 19, 2022

This PR fixes an issue with the env:decrypt command which can occur when a service provider relies on the presence of a value in the environment file.

For example, the Pusher broadcast driver relies on the API token set in the environment and that token doesn't exist until the environment file is decrypted. However, when running the command, the BroadcastServiceProvider is booted which attempts to instantiate Pusher and an exception is thrown.

This PR aims to resolve that issue by omitting \Illuminate\Foundation\Bootstrap\BootProviders::class from the kernel bootstrappers only when invoking the env:decrypt command.

This functionality has been added to both the handle and call methods.

As part of this, I have also added the option to decrypt a file to a different path.

php artisan env:decrypt --path=/tmp

Running the command above would result decrypting a file called .env.encrypted to /tmp/.env

Of course, you may combine this with the other options:

php artisan env:decrypt --env=production --filename=.env --path=/tmp

The above command will decrypt .env.production.encrypted to /tmp/.env

@morloderex
Copy link
Contributor

Any reason you didn't opt-in for making the BroadcastServiceProvider a deferred provider?

https://laravel.com/docs/9.x/providers#deferred-providers

@joedixon
Copy link
Contributor Author

There are a couple of reasons for that:

  1. BroadcastServiceProvider is just one example where this issue can arise. Making it deferred doesn't resolve the issue for user providers which rely on environment values.
  2. I don't actually think deferring it would resolve the issue as it's immediately used when registering the broadcast channels

@joedixon joedixon marked this pull request as ready for review October 20, 2022 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants