-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Eventbridge multiregion #2683
Merged
Merged
Eventbridge multiregion #2683
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83244bb
Eventbridge Multiregion
alextwoods 31c53ac
Add readme updates
alextwoods d99c333
revert codegen changes
alextwoods 3e921ac
Merge branch 'version-3' into eventbridge_multiregion
alextwoods 80bb4f0
Add plugin
alextwoods ee398d1
Add eventbridge to list of CRT requirements
alextwoods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
gems/aws-sdk-eventbridge/lib/aws-sdk-eventbridge/plugins/multi_region_endpoint.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
|
||
module Aws | ||
module EventBridge | ||
module Plugins | ||
# Resolve Multi-Region Endpoints | ||
class MultiRegionEndpoint < Seahorse::Client::Plugin | ||
|
||
def add_handlers(handlers, _config) | ||
handlers.add(Handler, operations: [:put_events]) | ||
end | ||
|
||
# After extracting out any ARN input, resolve a new URL with it. | ||
class Handler < Seahorse::Client::Handler | ||
def call(context) | ||
if (multi_region_endpoint_id = context.params[:endpoint_id]) | ||
|
||
validate_multi_region_endpoint!(multi_region_endpoint_id) | ||
validate_config!(context) | ||
|
||
url = context.http_request.endpoint | ||
region = context.config.region | ||
|
||
# if regional_endpoint is false, a custom endpoint was provided | ||
# customer provided endpoints should be used as is | ||
if context.config.regional_endpoint | ||
sfx = Aws::Partitions::EndpointProvider.dns_suffix_for( | ||
region, 'events', { dualstack: context.config.use_dualstack_endpoint } | ||
) | ||
url.host = "#{multi_region_endpoint_id}.endpoint.events.#{sfx}" | ||
end | ||
|
||
context.config.sigv4_signer = sigv4a_signer(context) | ||
end | ||
|
||
@handler.call(context) | ||
end | ||
|
||
private | ||
|
||
def validate_multi_region_endpoint!(multi_region_endpoint_id) | ||
unless !multi_region_endpoint_id.empty? && | ||
valid_hostname?(multi_region_endpoint_id) | ||
raise ArgumentError, 'multi_region_endpoint_id must be a valid host label.' | ||
end | ||
end | ||
|
||
def valid_hostname?(str) | ||
str =~ /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/ | ||
end | ||
|
||
def validate_config!(context) | ||
if context.config.use_fips_endpoint | ||
raise ArgumentError, | ||
'FIPS is not supported with EventBridge multi-region endpoints.' | ||
end | ||
end | ||
|
||
def sigv4a_signer(context) | ||
existing = context.config.sigv4_signer | ||
Aws::Sigv4::Signer.new( | ||
service: existing.service, | ||
region: '*', | ||
credentials_provider: existing.credentials_provider, | ||
signing_algorithm: :sigv4a, | ||
uri_escape_path: true, | ||
unsigned_headers: existing.unsigned_headers | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
135 changes: 135 additions & 0 deletions
135
gems/aws-sdk-eventbridge/spec/plugins/multi_region_endpoint_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
require_relative '../spec_helper' | ||
|
||
module Aws | ||
module EventBridge | ||
describe Client do | ||
let(:region) { 'us-east-1' } | ||
let(:use_fips_endpoint) { false } | ||
let(:use_dualstack_endpoint) { false } | ||
let(:client) do | ||
Client.new( | ||
stub_responses: true, region: region, | ||
use_dualstack_endpoint: use_dualstack_endpoint, | ||
use_fips_endpoint: use_fips_endpoint | ||
) | ||
end | ||
let(:event) do | ||
{ | ||
time: Time.now, | ||
source: "source", | ||
} | ||
end | ||
let(:entries) { [event] } | ||
|
||
def expect_sigv4a_signer(region='*') | ||
mock_signature = Aws::Sigv4::Signature.new(headers: {}) | ||
mock_signer = double('sigv4a_signer', sign_request: mock_signature) | ||
|
||
# a base signer is always created | ||
# multi-region endpoints result in a second signer being created with :sigv4a | ||
allow(Aws::Sigv4::Signer).to receive(:new).and_call_original | ||
allow(Aws::Sigv4::Signer).to receive(:new).with(hash_including(region: region, signing_algorithm: :sigv4a)).and_return(mock_signer) | ||
end | ||
|
||
it 'does not update the endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('events.us-east-1.amazonaws.com') | ||
end | ||
|
||
it 'it updates the endpoint, signs with sigv4a and uses the global region when endpoint_id is set ' do | ||
expect_sigv4a_signer('*') | ||
resp = client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
expect(resp.context.http_request.endpoint.host).to eq('abc123.456def.endpoint.events.amazonaws.com') | ||
end | ||
|
||
it 'raises when given an invalid endpoint_id' do | ||
expect do | ||
client.put_events(entries: entries, endpoint_id: 'badactor.com?foo=bar') | ||
end.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'raises when given an empty endpoint_id' do | ||
expect do | ||
client.put_events(entries: entries, endpoint_id: '') | ||
end.to raise_error(ArgumentError) | ||
end | ||
|
||
context 'use_dualstack_endpoint' do | ||
let(:use_dualstack_endpoint) { true } | ||
|
||
it 'does not update the endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('events.us-east-1.api.aws') | ||
end | ||
|
||
it 'uses the dualstack dnsSuffix when endpoint_id is set' do | ||
expect_sigv4a_signer('*') | ||
resp = client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
expect(resp.context.http_request.endpoint.host).to eq('abc123.456def.endpoint.events.api.aws') | ||
end | ||
end | ||
|
||
context 'use_fips_endpoint' do | ||
let(:use_fips_endpoint) { true } | ||
|
||
it 'does not update the endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('events-fips.us-east-1.amazonaws.com') | ||
end | ||
|
||
it 'raises when endpoint_id and use_fips_endpoint are set' do | ||
expect do | ||
client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
end.to raise_error(ArgumentError) | ||
end | ||
end | ||
|
||
context 'use_fips_endpoint and use_dualstack_endpoint' do | ||
let(:use_fips_endpoint) { true } | ||
let(:use_dualstack_endpoint) { true } | ||
|
||
it 'does not update the endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('events-fips.us-east-1.api.aws') | ||
end | ||
|
||
it 'raises when endpoint_id and use_fips_endpoint are set' do | ||
expect do | ||
client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
end.to raise_error(ArgumentError) | ||
end | ||
end | ||
|
||
context 'aws-iso partition' do | ||
let(:region) { 'us-iso-east-1' } | ||
|
||
it 'does not update the endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('events.us-iso-east-1.c2s.ic.gov') | ||
end | ||
|
||
it 'it updates the endpoint, signs with sigv4a and uses the global region when endpoint_id is set ' do | ||
expect_sigv4a_signer('*') | ||
resp = client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
expect(resp.context.http_request.endpoint.host).to eq('abc123.456def.endpoint.events.c2s.ic.gov') | ||
end | ||
end | ||
|
||
context 'custom endpoint' do | ||
let(:custom_endpoint) { 'https://example.org' } | ||
let(:client) { Client.new(endpoint: custom_endpoint, stub_responses: true, region: region) } | ||
|
||
it 'uses the custom endpoint when endpoint_id is not set' do | ||
resp = client.put_events(entries: entries) | ||
expect(resp.context.http_request.endpoint.host).to eq('example.org') | ||
end | ||
|
||
it 'does not modify the custom endpoint when endpoint_id is set' do | ||
expect_sigv4a_signer('*') | ||
resp = client.put_events(entries: entries, endpoint_id: 'abc123.456def') | ||
expect(resp.context.http_request.endpoint.host).to eq('example.org') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Eventbridge should also be on this list