Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: Add support for rest/ token in x-goog-api-client header (#189)
  • Loading branch information
vam-google committed May 18, 2021
1 parent 03a79f1 commit 15aca6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions google/api_core/client_info.py
Expand Up @@ -54,6 +54,7 @@ class ClientInfo(object):
user_agent (Optional[str]): Prefix to the user agent header. This is
used to supply information such as application name or partner tool.
Recommended format: ``application-or-tool-ID/major.minor.version``.
rest_version (Optional[str]): The requests library version.
"""

def __init__(
Expand All @@ -64,13 +65,15 @@ def __init__(
gapic_version=None,
client_library_version=None,
user_agent=None,
rest_version=None,
):
self.python_version = python_version
self.grpc_version = grpc_version
self.api_core_version = api_core_version
self.gapic_version = gapic_version
self.client_library_version = client_library_version
self.user_agent = user_agent
self.rest_version = rest_version

def to_user_agent(self):
"""Returns the user-agent string for this client info."""
Expand All @@ -87,6 +90,9 @@ def to_user_agent(self):
if self.grpc_version is not None:
ua += "grpc/{grpc_version} "

if self.rest_version is not None:
ua += "rest/{rest_version} "

ua += "gax/{api_core_version} "

if self.gapic_version is not None:
Expand Down
21 changes: 20 additions & 1 deletion tests/unit/test_client_info.py
Expand Up @@ -24,6 +24,7 @@ def test_constructor_defaults():
assert info.api_core_version is not None
assert info.gapic_version is None
assert info.client_library_version is None
assert info.rest_version is None


def test_constructor_options():
Expand All @@ -33,7 +34,8 @@ def test_constructor_options():
api_core_version="3",
gapic_version="4",
client_library_version="5",
user_agent="6"
user_agent="6",
rest_version="7",
)

assert info.python_version == "1"
Expand All @@ -42,6 +44,7 @@ def test_constructor_options():
assert info.gapic_version == "4"
assert info.client_library_version == "5"
assert info.user_agent == "6"
assert info.rest_version == "7"


def test_to_user_agent_minimal():
Expand All @@ -67,3 +70,19 @@ def test_to_user_agent_full():
user_agent = info.to_user_agent()

assert user_agent == "app-name/1.0 gl-python/1 grpc/2 gax/3 gapic/4 gccl/5"


def test_to_user_agent_rest():
info = client_info.ClientInfo(
python_version="1",
grpc_version=None,
rest_version="2",
api_core_version="3",
gapic_version="4",
client_library_version="5",
user_agent="app-name/1.0",
)

user_agent = info.to_user_agent()

assert user_agent == "app-name/1.0 gl-python/1 rest/2 gax/3 gapic/4 gccl/5"

0 comments on commit 15aca6b

Please sign in to comment.