-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: client identification headers #224
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ def http_headers | |
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'UNLEASH-INSTANCEID' => self.instance_id, | ||
'UNLEASH-APPNAME' => self.app_name, | ||
'X-UNLEASH-APPNAME' => self.app_name, | ||
'X-UNLEASH-CONNECTION-ID' => @connection_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we want this one to be private internal detail of each SDK |
||
'X-UNLEASH-SDK' => "unleash-ruby@#{Unleash::VERSION}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. common naming convention across SDKs |
||
'Unleash-Client-Spec' => CLIENT_SPECIFICATION_VERSION | ||
}.merge!(generate_custom_http_headers) | ||
end | ||
|
@@ -87,6 +90,7 @@ def set_defaults | |
self.environment = 'default' | ||
self.url = nil | ||
self.instance_id = SecureRandom.uuid | ||
@connection_id = SecureRandom.uuid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the dumbest comment I've ever left on a PR ever but the change in syntax here is a bit jarring. Any chance we can move this line either to the top of the bottom of this function? Honestly I won't even be offended if you just ignore me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually makes perfect sense to me. Had the same thought :) Moving it to the bottom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I appreciate you haha |
||
self.project_name = nil | ||
self.disable_client = false | ||
self.disable_metrics = false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
require "securerandom" | ||
|
||
RSpec.describe Unleash::Client do | ||
after do | ||
WebMock.reset! | ||
File.delete(Unleash.configuration.backup_file) if File.exist?(Unleash.configuration.backup_file) | ||
end | ||
|
||
it "Uses custom http headers when initializing client" do | ||
fixed_uuid = "123e4567-e89b-12d3-a456-426614174000" | ||
allow(SecureRandom).to receive(:uuid).and_return(fixed_uuid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we don't expose connection id we need to mock the generation |
||
|
||
WebMock.stub_request(:post, "http://test-url/client/register") | ||
.with( | ||
headers: { | ||
'Accept' => '*/*', | ||
'Content-Type' => 'application/json', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -22,7 +28,8 @@ | |
'Accept' => '*/*', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]" | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}" | ||
} | ||
) | ||
.to_return(status: 200, body: "", headers: {}) | ||
|
@@ -45,8 +52,11 @@ | |
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'X-Unleash-Connection-Id' => fixed_uuid, | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -73,14 +83,18 @@ | |
.with(headers: { 'Content-Type': 'application/json' }) | ||
.with(headers: { 'X-API-KEY': '123', 'Content-Type': 'application/json' }) | ||
.with(headers: { 'UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'X-UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'UNLEASH-INSTANCEID': 'rspec/test' }) | ||
.with(headers: { 'X-UNLEASH-CONNECTION-ID': fixed_uuid }) | ||
).to have_been_made.once | ||
|
||
expect( | ||
a_request(:get, "http://test-url/client/features") | ||
.with(headers: { 'X-API-KEY': '123' }) | ||
.with(headers: { 'UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'X-UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'UNLEASH-INSTANCEID': 'rspec/test' }) | ||
.with(headers: { 'X-UNLEASH-CONNECTION-ID': fixed_uuid }) | ||
).to have_been_made.once | ||
|
||
# Test now sending of metrics | ||
|
@@ -91,7 +105,9 @@ | |
.with(headers: { 'Content-Type': 'application/json' }) | ||
.with(headers: { 'X-API-KEY': '123', 'Content-Type': 'application/json' }) | ||
.with(headers: { 'UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'X-UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'UNLEASH-INSTANCEID': 'rspec/test' }) | ||
.with(headers: { 'X-UNLEASH-CONNECTION-ID': fixed_uuid }) | ||
).not_to have_been_made | ||
|
||
# Sending metrics, if they have been evaluated: | ||
|
@@ -103,7 +119,9 @@ | |
.with(headers: { 'Content-Type': 'application/json' }) | ||
.with(headers: { 'X-API-KEY': '123', 'Content-Type': 'application/json' }) | ||
.with(headers: { 'UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'X-UNLEASH-APPNAME': 'my-test-app' }) | ||
.with(headers: { 'UNLEASH-INSTANCEID': 'rspec/test' }) | ||
.with(headers: { 'X-UNLEASH-CONNECTION-ID': fixed_uuid }) | ||
.with{ |request| JSON.parse(request.body)['bucket']['toggles']['Feature.A']['yes'] == 2 } | ||
).to have_been_made.once | ||
end | ||
|
@@ -116,8 +134,10 @@ | |
'Content-Type' => 'application/json', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -157,8 +177,10 @@ | |
'Content-Type' => 'application/json', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -257,6 +279,7 @@ | |
'Content-Type' => 'application/json', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -269,8 +292,10 @@ | |
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -305,6 +330,7 @@ | |
'Content-Type' => 'application/json', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -327,8 +353,10 @@ | |
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -605,8 +633,10 @@ | |
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
@@ -619,8 +649,10 @@ | |
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'Unleash-Appname' => 'my-test-app', | ||
'X-Unleash-Appname' => 'my-test-app', | ||
'Unleash-Instanceid' => 'rspec/test', | ||
'User-Agent' => "UnleashClientRuby/#{Unleash::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION} [#{RUBY_PLATFORM}]", | ||
'X-Unleash-Sdk' => "unleash-ruby@#{Unleash::VERSION}", | ||
'X-Api-Key' => '123' | ||
} | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will replace
UNLEASH-APPNAME
over time