Problem/Motivation

The process to configure a site for integration with Fastly can be done programmatically, except for one of the more important steps: uploading the VCLs to fine-tune the Fastly service behavior for Drupal.

The current process requires logging into the site and manually clicking the upload button.

Proposed resolution

Fastly already exposes the VCL Handler class as a module service, and the upload button in the Fastly Settings form appears to invoke its execute() command directly, passing along a form setting flag on whether to activate the version or not.

So we should be able to extend that behavior out to a Drush command with a similar flag, like:

# Upload VCLs but do not activate the new version
drush fastly:upload-vcls

# Upload VCLs and activate the new version
drush fastly:upload-vcls --activate

Remaining tasks

Create a Merge Request with the proposed change.

Issue fork fastly-3620562

Command icon 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

coolbrewed created an issue. See original summary.

coolbrewed’s picture

Assigned: Unassigned » coolbrewed

coolbrewed’s picture

Update: I've got the suggested changes created as a Merge Request. Check it out and let me know if anything needs tweaking!

To test:

  1. Select a site with a staging Fastly instance that is safe to test against and has the 4.x Fastly module version.
  2. Apply the diff of MR!34 as a patch.
  3. Run the Drush command: drush fastly:upload-vcls (or drush fastly:upload-vcls --activate to immediately activate the new version)
  4. Confirm a new version has been created and the module VCLs have been uploaded as expected.

And as a heads-up for any folks testing in an environment where the Fastly credentials are not already set:

Currently, the Drush command will "terminate abnormally" with the following error:

Error: Call to a member function addError() on null in Drupal\fastly\VclHandler->execute() (line 495 of /var/www/html/web/modules/contrib/fastly/src/VclHandler.php) #0 /var/www/html/web/modules/contrib/fastly/src/Commands/FastlyCommands.php(137): Drupal\fastly\VclHandler->execute()

That error's due to a separate issue about the class's property assignment order (which also has a suggested fix that works great!).