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

Enable configuration override on each consul api call #179

Merged

Conversation

tionebsalocin
Copy link
Contributor

Using the configs hash target host or token can be different at each call

e.g
value = Diplomat::Kv.get('key/path', token: '000-111-222-333-444', http_addr: 'http://consu01:8500', dc: 'dc1', stale: true)
Diplomat::Kv.put('key/path', value, token: '111-222-333-444-555', http_addr: 'http://consu02:8500', dc: 'dc2', stale: true)

@tionebsalocin tionebsalocin force-pushed the options-everywhere branch 4 times, most recently from 252d422 to 372b832 Compare March 7, 2019 10:09
Copy link
Member

@pierresouchay pierresouchay left a comment

Choose a reason for hiding this comment

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

I think there is a breakage of API right?

def get(meta = nil)
url = ['/v1/catalog/datacenters']
# rubocop:disable AbcSize, CyclomaticComplexity
def get(options = nil)
Copy link
Member

Choose a reason for hiding this comment

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

This is a breakage of API for those using meta to get information about request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed. I've fixed this issue.

Copy link
Member

@pierresouchay pierresouchay left a comment

Choose a reason for hiding this comment

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

Looks good to me.
@tionebsalocin Would it be possible to update a bit documentation in another PR to reflect those changes?

@ShimmerGlass
Copy link

LGTM.

FAR the options / cutom_params parameters in send_{get,put,..}_request could be combined to avoid having too many ways to pass options.


headers = { 'X-Consul-Token': configuration.acl_token } if configuration.acl_token

unless options.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

if options was a empty hash (by default) instead of nil, you could remove that condition

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've set the default as empty hash and removed plenty of corresponding tests

req.body = JSON.dump(data) unless data.nil?
end
end
# rubocop:enable MethodLength, AbcSize, CyclomaticComplexity
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the point of disabling/enabling those metrics. I would suggest to:

  • disable cyclomatic complexity (and abcsize) measurement for which threshold are highly subjective
  • really define what should be the max method length and stick to it.

Copy link
Member

Choose a reason for hiding this comment

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

@tionebsalocin yes, sounds reasonable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've set default realistic values for these

# rubocop:enable MethodLength, AbcSize, CyclomaticComplexity

# rubocop:disable MethodLength, AbcSize, CyclomaticComplexity
def send_put_request(connection, url, options, data, custom_params = nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

OPT: using named arguments would make calls to this method easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll plan this for another review

Diplomat.configuration.acl_token = nil
ev = Diplomat::Event.new(faraday)
Copy link
Contributor

Choose a reason for hiding this comment

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

great change, it makes test easier to read!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

@@ -1,6 +1,7 @@
require 'spec_helper'
require 'json'
require 'base64'
require 'webmock/rspec'
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point, you could put all those requires in spec/spec_helper.rb and require it instead

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. Thanks

Using the configs hash target host or token can be
different at each call
@pierresouchay pierresouchay merged commit ff4e2f8 into WeAreFarmGeek:master Mar 11, 2019
pierresouchay added a commit that referenced this pull request Mar 18, 2019
This release cleanup a lot the existing APIs while preserving ascending compatibility.
It will avoid relying on side effects to configure diplomat and allow to override most
configuration options per API call as implemented in #179.
It is now easy to use one instance of the lib and to perform several calls with different tokens and/or
consistency options for instance.
pierresouchay added a commit that referenced this pull request Mar 18, 2019
This release cleanup a lot the existing APIs while preserving ascending compatibility.
It will avoid relying on side effects to configure diplomat and allow to override most
configuration options per API call as implemented in #179.
It is now easy to use one instance of the lib and to perform several calls with different tokens and/or
consistency options for instance.
@pierresouchay
Copy link
Member

@scalp42 did which version did you use? (there were a few fixes after version 2.1.0...)

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.

5 participants