Oops, we created https://www.drupal.org/project/bunnycdn but luckily we saw your module before we started any big work.
We have a need for a "Purge whole zone" functionality. Fairly simple concept:
- Separate admin screen to input bunnycdn API key and zone(s)
- Extra button on the Drupal "Performance" screen, next to Clear caches, that says "Purge bunnyCDN", that fully clears the zones through API call.
Are you ok with adding this to your module, and if we add it to this issue + prove it works/is tested, would you be willing to create a new minor release with it... in a reasonable timeframe?
Additional question. We need front end and back end zones (for decoupled sites) and want to have two textfields for two zones:
- "Drupal" - "The CDN used for accessing Drupal."
- "Frontend" - "An optional second CDN zone that is used for the frontend. This is useful when the frontend is served from another domain, e.g. for decoupled projects."
Is this fine for you to have in the standard module? There's no real added complication, just some field that people can leave empty. As far as I can tell now, the single "Purge bunnyCDN" button will just purge 1 or 2 zones depending on whether 1 or 2 zones are configured.
| Comment | File | Size | Author |
|---|
Issue fork bunny_cdn-3414571
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
roderikComment #3
dieterholvoet commentedThis should already be (mostly) possible with the Purger module integration:
/admin/config/development/performance/purgeand add two Bunny CDN purgers, one for the frontend and one for the backend.Currently, the API key is taken from the
BUNNY_API_KEYenv variable and the pull zone ID is taken from theBUNNY_PULL_ZONE_IDenv variable. We should make these part of the purger configuration.About the extra button on the Performance screen: this would be a good candidate for a more abstract module (not specific to Bunny CDN) that adds buttons for every configured purger that has the ability to do full invalidations.
Comment #4
dieterholvoet commentedI added purger settings with API key, pull zone & base URL properties. Can you test if this works for you? Until the Performance screen button is implemented, you can use add a Drush p:invalidate processor and run
drush p:invalidate everything.Comment #6
junkunczHello @DieterHolvoet
Thank you for your nice contribution first.
I was doing some testing and it works quite good, except one thing which is maybe(?) my environment issue I'm not sure: when I want to purge the pull zone with
ddev drush p:invalidate everything -y(parameters are already added via the config form of course) I'm getting an error which relates to Guzzle I guessBunny purge request failed. Status code 400: Client error: `POST https://api.bunny.net/pullzone//purgeCache` resulted in a `400 Bad Request` response: {"Message":"The request is invalid."}.However I can complete the request with a Postman call. Looks like Guzzle wants to send the request "twice" for some reason, I've attached the log (AccessKey was sanitised because of privacy)
I've found a ticket which relates to this error: https://github.com/guzzle/guzzle/issues/1432
As far as I understand when the response code is 204 and the content body is empty it throws and exception.
Could you please check it on your side as well? I'm using a strandard drupal install with Drupal core 10.2 in ddev.
Thanks!
Comment #7
junkunczIgnore the error above, it was a configuration issue (used the same zone id twice).
The module does its jobb very well. Regarding the "Purge bunnyCDN" button I agree it's more abstract and there is already a working patch for that in Purge module: https://www.drupal.org/project/purge/issues/2853613
I've discovered only two things that should be added/changes I guess:
- add purge module as a dependency to module.info.yml
- "BunnyPurger" class should implement "PurgerInterface"
Looking forward you feedback.
Comment #8
junkunczComment #9
junkunczComment #10
junkunczComment #11
junkunczAdding these changes in patch format, you can quickly apply if you agree of course.
Comment #12
dieterholvoet commentedI decided not to do that since it's not strictly necessary. The 'setting the CDN-Tag header required by Bunny CDN for tag based purging' part of the module doesn't need the Purge module, so I though I'd keep it optional. The project description already instructs to install the Purge module if necessary.
The
BunnyPurgerclass extendsPurgerBaseand that class already implementsPurgerInterface.Comment #13
junkunczI see, okay. Good to go from my side
Comment #14
roderik@DieterHolvoet thanks a lot for your very fast feedback and code!
I guess we had our steps for implementing functionality, backward: "first do a simple purge-all button, then check more refined purger module integration later" -- while in fact the purger module can also facilitate the former :-)
Comment #15
dieterholvoet commentedComment #16
dieterholvoet commentedYou're welcome! I still had this as a TODO in the back of my head anyway :)
Comment #18
dieterholvoet commentedComment #19
roderikAddendum:
I see your point. We may just do a quick internal glue module, kick its tires, and release later if fit.
The irony is that env variables are quite nice for multi environment hosting... and I'm not really seeing a good way to marry these with config entities.
Combined with #3415864: Exception when enabling 1.1.0 (dependency on purge)... is there maybe a case to be made to store the configs in 'common' configuration that is overridable by a settings(.local).php which can define local bunnycdn purger config (that may be fed in by
$_ENV['whatever-local-key']?Maybe even one setting named 'bunny_cdn.purger_settings' or somesuch, keyed by the purger id?
Note it's possible that I'm talking nonsense and am completely unaware of the fact that it's possible to define config entities in settings.php.... But I don't... think so?
Comment #20
roderikMaybe I'm talking nonsense though.
I'm essentially making a case against the existence of PurgerSettingsBase... It's "not your fault" that that's implemented as a config entity...
(Yes, this is just live thoughts coming into my head...)
Comment #21
dieterholvoet commentedYou can easily override config values with .env variables in settings.php. You do have to create and configure the purger through the UI first, but afterwards you can remove any sensitive values from config and override them in your settings.php. Example:
Comment #22
roderikThank you. I'm still semi regularly amazed by how much common knowledge I lack.
(I had tried web searches, and to trace loadMultiple() for a point where config entities were overridden by settings.php contents, but couldn't find this fact.)