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

Allow Faraday init params to be passed to HTTP adaptor #288

Merged
merged 5 commits into from
Mar 14, 2017

Conversation

heavydawson
Copy link
Contributor

This pull introduces/changes:

  • Restores the ability to pass Faraday request init params to allow things like over-riding the initial connection and request timeout values
    A new key called :faraday_opts is available for use in the options array passed to the HTTP adaptor

Example usage:
adaptor ||= Neo4j::Core::CypherSession::Adaptors::HTTP.new("http://"
"#{@user}:"
"#{@password}@"
"#{@host}:"
"#{@http_port}",
faraday_opts: {initialize: { request: { open_timeout: 2, timeout: 600 }} })

Pings:
@cheerfulstoic
@subvertallchris

@coveralls
Copy link

coveralls commented Mar 11, 2017

Coverage Status

Coverage decreased (-2.1%) to 90.268% when pulling 62ad69c on heavydawson:master into 73bf469 on neo4jrb:master.

Copy link
Contributor

@cheerfulstoic cheerfulstoic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thank you so much! A few items of feedback to look over which I don't think will be hard to change. Happy to discuss!

@@ -16,7 +16,7 @@ def initialize(url, options = {})
end

def connect
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request))
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request), @options[:faraday_opts] = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: faraday_options would be better, I think

Also, did you mean to do @options[:faraday_opts] ||= {} here? Otherwise it's going to always set / pass through an empty Hash. You could also do @options.fetch(:faraday_options, {})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. That was some post-implementation cleanup I thought was correct, so thanks for spotting

self.url = url
@user = user
@password = password
@user_agent_string = user_agent_string
@faraday = wrap_connection_failed! { faraday_connection }
init_params = params[:initialize] && params.delete(:initialize) if params.key?(:initialize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is what the previous code did, but I don't like the delete because it modifies the Hash that we were given. I'd be happy with just the following if it works:

@faraday = wrap_connection_failed! { faraday_connection(params.fetch(:initialize, {})) }

Honestly since we're passing in a hash with the key of :faraday_options above, I don't know why we need the extra :initialize key underneath. I would actually probably just rename params to faraday_options and pass it through.

Separately we're going to need to make the Rails integration like this work:

config.neo4j.session.options = {initialize: { ssl: { verify: true }}}

But I think that we could simply pass down the values of initialize from the railtie in the neo4j gem into here as well as also supporting:

config.neo4j.session.options = {faraday_options: { ssl: { verify: true }}}

And probably raising a deprecation warning about how initialize should be replaced with faraday_options

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (apart from rails-related config changes)

@@ -144,12 +144,13 @@ def get(path, body = '', options = {})

private

def faraday_connection
def faraday_connection(params = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're in the place where we're creating the Faraday connection, I would probably just call this variable options to match with the naming of faraday_options. Also, I've seen a general pattern of using options as the hash of optional arguments at the end of a Ruby function. When I see params I think of Rails' controller parameters (that may just be my preference, but I think it's a trend)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage decreased (-2.2%) to 90.235% when pulling 0b42d54 on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage increased (+0.001%) to 92.4% when pulling 424843a on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

6 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-61.5%) to 30.893% when pulling 817261e on heavydawson:master into 73bf469 on neo4jrb:master.

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage increased (+0.005%) to 92.403% when pulling 2b8c741 on heavydawson:master into 73bf469 on neo4jrb:master.

Copy link
Contributor Author

@heavydawson heavydawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes apart from rails specific change made. Rubocop was complaining about the basic auth assignment, so I re-factored that section to keep it happy.

@cheerfulstoic cheerfulstoic merged commit b492670 into neo4jrb:master Mar 14, 2017
cheerfulstoic pushed a commit that referenced this pull request Mar 14, 2017
* Allow Faraday init params to be passed to HTTP adaptor

* Update http.rb

* Fix failing tests

* Fix failing rubocop issues

* Fix silly C&P error

(cherry picked from commit b492670)
@cheerfulstoic
Copy link
Contributor

Thanks so much @heavydawson !

I merged and then made some changes of my own, mainly refactoring. The biggest functional change that I made was to pass the options directly through to Faraday without the initialize key because I think we can put in (deprecated) support for that key in the railtie. You can see it all in the version of the file in the 7.0.x branch here:

https://github.com/neo4jrb/neo4j-core/blob/7.0.x/lib/neo4j/core/cypher_session/adaptors/http.rb

Could you give it a final try to make sure it works for you since I removed the initialize key? You can do this in your Gemfile:

gem 'neo4j-core', github: 'neo4jrb/neo4j-core', branch: '7.0.x'

If that works I'll release a patch version. Thanks again!

cheerfulstoic added a commit that referenced this pull request Mar 14, 2017
@cheerfulstoic
Copy link
Contributor

Also, I decided since there was no ability to configure Faraday in 8.0.x, that it wasn't a big deal to not deprecate initialize. I made changes to the Setup and Upgrade Guides to reflect this.

@cheerfulstoic
Copy link
Contributor

Hey @heavydawson !

I actually changed this from faraday_options to faraday_configurator since that allows you to configure everything (like faraday adaptors as was requested in #274)

http://neo4jrb.readthedocs.io/en/8.0.x/Setup.html#configuring-faraday

The change is available starting with version 7.0.8 of neo4j-core

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