la-haute-societe / craft-elasticsearch

Bring the power of Elasticsearch to your Craft CMS projects
Other
18 stars 14 forks source link

Indexing with basic auth #39

Open andreas-andersson opened 7 months ago

andreas-andersson commented 7 months ago

Problem: It's common practice to keep a staging or test server for a project and those are sometimes protected by Basic Auth. Currently there is no way to index sites which has basic auth because there is no way of passing settings to the \GuzzleHttp\Client in ElementIndexerService ->getElementIndexableContent()

I have not found a way to work around this. Is there another way?


Suggestion: Add a config option for the \GuzzleHttp\Client

config.php || ./config/elasticsearch.php

return [
    'httpClientOptions' => [
        'connection_timeout' => 10,
        'auth' => ['username', 'password']
    ]
]

/src/services/ElementIndexerService.php

protected function getElementIndexableContent(Element $element)
    {
        // ...
        $options = ElasticsearchPlugin::getInstance()->getSettings()->httpClientOptions;
        $client = new \GuzzleHttp\Client($options);
        // ...

/src/models/SettingsModel.php

class SettingsModel extends Model
{
    // ...
    /** @var array GuzzleHttp\Client options */
    public $httpClientOptions = [];
    // ...
andreas-andersson commented 7 months ago

Let me know if this sounds interesting and I'll submit a PR for it.