Skip to content

Move logic for explicit routing headers to google-api-core #2160

@parthea

Description

@parthea

See feedback in https://github.com/googleapis/gapic-generator-python/pull/2131/files#r1751065571 from review of PR #2131 which calls out that the logic for explicit routing headers which exists in _client_macros.j2 could be moved to google-api-core, similar to how we have gapic_v1.routing_header.to_grpc_metadata

This logic:

{% for routing_param in method.routing_rule.routing_parameters %}
{% if routing_param.path_template %} {# Need to match. #}
routing_param_regex = {{ routing_param.to_regex() }}
regex_match = routing_param_regex.match(request.{{ routing_param.field }})
if regex_match and regex_match.group("{{ routing_param.key }}"):
header_params["{{ routing_param.key }}"] = regex_match.group("{{ routing_param.key }}")
{% else %}
if request.{{ routing_param.field }}:
header_params["{{ routing_param.key }}"] = request.{{ routing_param.field }}
{% endif %}
{% endfor %} {# method.routing_rule.routing_parameters #}

Could be refactored into a helper function in google-api-core similar to gapic_v1.routing_header.to_grpc_metadata

if header_params:
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(header_params),
)

Metadata

Metadata

Assignees

Labels

type: cleanupAn internal cleanup or hygiene concern.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions