From fbdb8843112653436c1a8521245d575a444ffec8 Mon Sep 17 00:00:00 2001 From: Kik Engineering Date: Tue, 18 May 2021 18:20:51 -0400 Subject: [PATCH] agora/client: add app-index header GitOrigin-RevId: 9a92b972ea71d399a2d1fa691bd30e209933ccc5 --- agora/client/client.py | 2 +- agora/client/internal.py | 17 ++++++++++++----- tests/client/test_client.py | 2 +- tests/client/test_internal.py | 5 ++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/agora/client/client.py b/agora/client/client.py index 81f91a3..ee8bf38 100644 --- a/agora/client/client.py +++ b/agora/client/client.py @@ -267,7 +267,7 @@ def __init__( LimitStrategy(retry_config.max_nonce_refreshes + 1) ] - self._internal_client = InternalClient(self._grpc_channel, self._internal_retry_strategies) + self._internal_client = InternalClient(self._grpc_channel, self._internal_retry_strategies, self._app_index) self._default_commitment = default_commitment diff --git a/agora/client/internal.py b/agora/client/internal.py index b8513f6..432b697 100644 --- a/agora/client/internal.py +++ b/agora/client/internal.py @@ -46,7 +46,7 @@ class InternalClient: """ def __init__( - self, grpc_channel: grpc.Channel, retry_strategies: List[Strategy], + self, grpc_channel: grpc.Channel, retry_strategies: List[Strategy], app_index: int = 0, ): self._account_stub_v4 = account_pb_grpc.AccountStub(grpc_channel) self._transaction_stub_v4 = tx_pb_grpc.TransactionStub(grpc_channel) @@ -54,10 +54,17 @@ def __init__( self._retry_strategies = retry_strategies - self._metadata = ( - user_agent(VERSION), - ('kin-version', "4"), - ) + if app_index > 0: + self._metadata = ( + user_agent(VERSION), + ('kin-version', "4"), + ('app-index', str(app_index)), + ) + else: + self._metadata = ( + user_agent(VERSION), + ('kin-version', "4"), + ) # Currently only service config is cached, so limit to 1 entry self._response_cache = LRUCache(300, 1) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 2f4fb14..f95ce47 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -1506,7 +1506,7 @@ def _assert_user_agent(md): @staticmethod def _assert_kin_4_md(md: Tuple[Tuple, ...]): - assert len(md) == 3 + assert len(md) >= 3 assert md[0] == user_agent(VERSION) assert md[1] == ('kin-version', '4') diff --git a/tests/client/test_internal.py b/tests/client/test_internal.py index 8755235..ccfc52b 100644 --- a/tests/client/test_internal.py +++ b/tests/client/test_internal.py @@ -726,9 +726,12 @@ def _set_get_min_balance_response( @staticmethod def _assert_metadata(md: Tuple[Tuple, ...]): - assert len(md) == 3 + assert len(md) >= 3 assert md[0] == user_agent(VERSION) assert md[1] == ('kin-version', '4') + if len(md) == 4: + assert md[2] == ('app-index', '1') + @staticmethod def _gen_tx():