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

add proc transport option #302

Merged
merged 1 commit into from
Dec 22, 2015
Merged

Conversation

feymartynov
Copy link
Contributor

A use case for it is setting up a connection to AWS Elasticsearch.

According to elasticsearch-transport's readme one should pass a block to ::ElasticsearchClient#initialize which adds necessary authorization headers to each request. However this can't be done with chewy.

A possible hack as it was discussed in the issue #296 is to assign Thread.current[:chewy_client] somewhere (say, in Rails initializer) with a custom instance. But this would affect only the current thread.

With :proc option it becomes possible to pass a block to Elasticsearch::Constructor.

So an example initializer for AWS tuning looks like this:

require 'faraday_middleware/aws_signers_v4'

Chewy.configuration[:transport_options] = {
  headers: { content_type: 'application/json' },
  proc: -> (f) do
      f.request :aws_signers_v4,
                service_name: 'es',
                region: 'us-east-1',
                credentials: Aws::Credentials.new(
                  ENV['AWS_ACCESS_KEY'],
                  ENV['AWS_SECRET_ACCESS_KEY'])
  end
}

P.S. For the purpose of Content-Type header see issue #271.

pyromaniac added a commit that referenced this pull request Dec 22, 2015
@pyromaniac pyromaniac merged commit 884b89d into toptal:master Dec 22, 2015
@pyromaniac
Copy link
Contributor

Thanks!

@rromanchuk
Copy link
Contributor

rromanchuk commented Mar 11, 2017

o_O am i on an incorrect version? or is there something fundamental i'm not understanding here?

screen shot 2017-03-10 at 6 48 17 pm

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

Successfully merging this pull request may close these issues.

3 participants