Skip to content

Commit

Permalink
added new env variable for provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bytexr committed Mar 27, 2023
1 parent 7953924 commit 7249a0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ return [
...

'opensearch' => [
// default - this provider will use basic authentication username and password
// aws - this provider will use AWS credentials to authenticate
"provider" => env('OPENSEARCH_PROVIDER', 'default'),
"host" => env('OPENSEARCH_HOST', 'https://localhost:9200'),
"username" => env('OPENSEARCH_USERNAME', 'admin'),
"password" => env('OPENSEARCH_PASSWORD', 'admin'),
"ssl_verification" => env("OPENSEARCH_SSL_VERIFICATION", true),

// Only necessary if project is using AWS OpenSearch
// Only necessary if project is using AWS provider
"aws_access_key" => env('OPENSEARCH_AWS_ACCESS_KEY'),
"aws_secret_key" => env('OPENSEARCH_AWS_SECRET_KEY'),
"aws_region" => env('OPENSEARCH_AWS_REGION', 'eu-west-1'),
Expand Down
23 changes: 8 additions & 15 deletions src/LaravelScoutOpenSearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,21 @@ public function boot(): void

private function createOpenSearchClient(): \OpenSearch\Client
{
if (
(config('scout.opensearch.username') || config('scout.opensearch.password')) &&
(config('scout.opensearch.aws_access_key') || config('scout.opensearch.aws_secret_key'))
) {
throw new OnlyAWSOrBasicAuthCredentials('Your OpenSearch configuration should have onlu AWS or Basic Auth credentials and not both.');
}

if (config('scout.opensearch.username')) {
if (config('scout.opensearch.provider') == "aws") {
return (new ClientBuilder())
->setHosts([config('scout.opensearch.host')])
->setSSLVerification(config('scout.opensearch.ssl_verification', true))
->setBasicAuthentication(config('scout.opensearch.username'), config('scout.opensearch.password'))
->setSigV4CredentialProvider([
'key' => config('scout.opensearch.aws_access_key'),
'secret' => config('scout.opensearch.aws_secret_key'),
])
->setSigV4Region(confiig('scout.opensearch.aws_region'))
->build();
}

return (new ClientBuilder())
->setHosts([config('scout.opensearch.host')])
->setSigV4CredentialProvider([
'key' => config('scout.opensearch.aws_access_key'),
'secret' => config('scout.opensearch.aws_secret_key'),
])
->setSigV4Region(confiig('scout.opensearch.aws_region'))
->setSSLVerification(config('scout.opensearch.ssl_verification', true))
->setBasicAuthentication(config('scout.opensearch.username'), config('scout.opensearch.password'))
->build();
}
}

0 comments on commit 7249a0b

Please sign in to comment.