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

Send Guzzle configuration options through from the config file #43

Closed
jamie-s-white opened this issue Oct 4, 2023 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@jamie-s-white
Copy link

Please provide a clear and concise description of your feature request, including:

  • What the problem is and what you would like to have happen.

I would like to be able to configure Guzzle from the config file.

A perfect example of this type of implementation can be found with Feed Me:

https://docs.craftcms.com/feed-me/v4/get-started/configuration.html#example-requestoptions

This way, I can set an auth element with username and password (for example).

  • Any alternative solutions or features you have considered.
@jamie-s-white jamie-s-white added the enhancement New feature or request label Oct 4, 2023
@bencroker
Copy link
Collaborator

Do you need to configure Guzzle requests for Sherlock only? If not, then you should already be able to do this by configuring the Guzzle component, see https://craftcms.com/docs/4.x/config/#guzzle

@jamie-s-white
Copy link
Author

I didn't know about this, so this is a big help, thank you!

However, we were looking to configure domain specific variables, such as username and password, so the global settings don't help here.

For now, I have edited line 140 of:

/vendor/putyourlightson/craft-sherlock/src/services/TestsService.php

To add the configuration we need to perform a single run, and then I will reinstall the plugin to remove my "patch".

@bencroker
Copy link
Collaborator

bencroker commented Oct 7, 2023

I added a TestsService::EVENT_BEFORE_RUN_TESTS event that you should be able to use to override the Guzzle client via a custom module/plugin.

use Craft;
use putyourlightson\sherlock\events\RunTestsEvent;
use putyourlightson\sherlock\services\TestsService;
use yii\base\Event;

Event::on(TestsService::class, TestsService::EVENT_BEFORE_RUN_TESTS,
    function(RunTestsEvent $event) {
        if (Craft::$app->sites->currentSite->id === 1) {
            $event->client = Craft::createGuzzleClient([
                'auth' => ['username', 'password'],
                'timeout' => 10,
            ]);
        }
    }
);

You can test this by running composer require "putyourlightson/craft-sherlock:dev-develop as 4.4.0".

@jamie-s-white
Copy link
Author

Excellent, thank you very much!

I don't suppose there is any chance of this also being rolled out for the Craft 3 version of the plugin, is there?

I understand if you are just adding new features to the Craft 4 version, and thank you for this, it will be a big help.

@bencroker
Copy link
Collaborator

bencroker commented Oct 9, 2023

Released in version 4.4.0. Unfortunately, Sherlock 3 (for Craft 3) is only getting bug fixes and security updates but no new features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants