From 56fe6d212b3ed7d0d96a7c45321e5d1fbb8e66d4 Mon Sep 17 00:00:00 2001 From: Tamara Boehm Date: Wed, 10 May 2023 12:51:49 +0200 Subject: [PATCH] feat: Add protocol field in route-registrar spec --- jobs/route_registrar/spec | 1 + .../templates/registrar_settings.json.erb | 4 ++++ spec/route_registar_templates_spec.rb | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/jobs/route_registrar/spec b/jobs/route_registrar/spec index 595f20753..bf3d9a039 100644 --- a/jobs/route_registrar/spec +++ b/jobs/route_registrar/spec @@ -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). diff --git a/jobs/route_registrar/templates/registrar_settings.json.erb b/jobs/route_registrar/templates/registrar_settings.json.erb index c91a8114b..e2e17de12 100644 --- a/jobs/route_registrar/templates/registrar_settings.json.erb +++ b/jobs/route_registrar/templates/registrar_settings.json.erb @@ -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 diff --git a/spec/route_registar_templates_spec.rb b/spec/route_registar_templates_spec.rb index 495adce57..76e5674a1 100644 --- a/spec/route_registar_templates_spec.rb +++ b/spec/route_registar_templates_spec.rb @@ -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