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

feat: Add protocol field in route-registrar spec #322

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jobs/route_registrar/spec
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ properties:
tls_port (required, integer, for http routes): Either `port` or `tls_port` are required; if both are provided, Gorouter will prefer tls_port.
Requests for associated URIs will be forwarded over TLS by the router to this port.
The IP is determined automatically from the host on which route-registrar is run.
protocol (optional, string): 'http1' or 'http2'. If not provided, Gorouter uses 'http1' as default.
route_service_url (optional, string, for http routes): When valid route service URL is provided, Gorouter will proxy requests received for the uris above to the specified route service URL.
server_cert_domain_san (conditional, string, for http routes): Required if tls_port is present.
Gorouter will validate that the TLS certificate presented by the destination host contains this as a Subject Alternative Name (SAN).
Expand Down
4 changes: 4 additions & 0 deletions jobs/route_registrar/templates/registrar_settings.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
raise "expected route_registrar.routes[#{index}].route.server_cert_domain_san when tls_port is provided"
end

if route['protocol'] != nil && (route['protocol'] != 'http1' && route['protocol'] != 'http2')
raise "expected route_registrar.routes[#{index}].route.protocol to be http1 or http2 when protocol is provided"
end

if route['prepend_instance_index']
route['uris'].map! { |uri| "#{spec.index}-#{uri}" }
end
Expand Down
19 changes: 19 additions & 0 deletions spec/route_registar_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,25 @@
expect { template.render(merged_manifest_properties, consumes: links) }.not_to raise_error
end
end

describe 'when protocol is provided' do
it 'uses configured protocol http1' do
merged_manifest_properties['route_registrar']['routes'][0]['protocol'] = 'http1'
rendered_hash = JSON.parse(template.render(merged_manifest_properties, consumes: links))
expect(rendered_hash['routes'][0]['protocol']).to eq('http1')
end
it 'uses configured protocol http2' do
merged_manifest_properties['route_registrar']['routes'][0]['protocol'] = 'http2'
rendered_hash = JSON.parse(template.render(merged_manifest_properties, consumes: links))
expect(rendered_hash['routes'][0]['protocol']).to eq('http2')
end
it 'raises error for invalid protocol' do
merged_manifest_properties['route_registrar']['routes'][0]['protocol'] = 'abc'
expect { template.render(merged_manifest_properties, consumes: links) }.to raise_error(
RuntimeError, 'expected route_registrar.routes[0].route.protocol to be http1 or http2 when protocol is provided'
)
end
end
end
end

Expand Down