當前位置: 首頁>>代碼示例>>Python>>正文


Python grpc.AuthMetadataPluginCallback方法代碼示例

本文整理匯總了Python中grpc.AuthMetadataPluginCallback方法的典型用法代碼示例。如果您正苦於以下問題:Python grpc.AuthMetadataPluginCallback方法的具體用法?Python grpc.AuthMetadataPluginCallback怎麽用?Python grpc.AuthMetadataPluginCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在grpc的用法示例。


在下文中一共展示了grpc.AuthMetadataPluginCallback方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_call_no_refresh

# 需要導入模塊: import grpc [as 別名]
# 或者: from grpc import AuthMetadataPluginCallback [as 別名]
def test_call_no_refresh(self):
        credentials = CredentialsStub()
        request = mock.create_autospec(transport.Request)

        plugin = google.auth.transport.grpc.AuthMetadataPlugin(credentials, request)

        context = mock.create_autospec(grpc.AuthMetadataContext, instance=True)
        context.method_name = mock.sentinel.method_name
        context.service_url = mock.sentinel.service_url
        callback = mock.create_autospec(grpc.AuthMetadataPluginCallback)

        plugin(context, callback)

        time.sleep(2)

        callback.assert_called_once_with(
            [(u"authorization", u"Bearer {}".format(credentials.token))], None
        ) 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:20,代碼來源:test_grpc.py

示例2: test_call_refresh

# 需要導入模塊: import grpc [as 別名]
# 或者: from grpc import AuthMetadataPluginCallback [as 別名]
def test_call_refresh(self):
        credentials = CredentialsStub()
        credentials.expiry = datetime.datetime.min + _helpers.CLOCK_SKEW
        request = mock.create_autospec(transport.Request)

        plugin = google.auth.transport.grpc.AuthMetadataPlugin(credentials, request)

        context = mock.create_autospec(grpc.AuthMetadataContext, instance=True)
        context.method_name = mock.sentinel.method_name
        context.service_url = mock.sentinel.service_url
        callback = mock.create_autospec(grpc.AuthMetadataPluginCallback)

        plugin(context, callback)

        time.sleep(2)

        assert credentials.token == "token1"
        callback.assert_called_once_with(
            [(u"authorization", u"Bearer {}".format(credentials.token))], None
        ) 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:22,代碼來源:test_grpc.py

示例3: __call__

# 需要導入模塊: import grpc [as 別名]
# 或者: from grpc import AuthMetadataPluginCallback [as 別名]
def __call__(self, context, callback):
        """Passes authorization metadata into the given callback.

        Args:
          context (grpc.AuthMetadataContext): The RPC context.
          callback (grpc.AuthMetadataPluginCallback): The callback that will
            be invoked to pass in the authorization metadata.
        """
        headers = {}
        self._credentials.before_request(
            self._request, context.method_name, context.service_url, headers
        )
        id_token = getattr(self._credentials, "id_token", None)
        if id_token:
            self._credentials.apply(headers, token=id_token)
        else:
            logger.error("Failed to find ID token credentials")
        # Pass headers as key-value pairs to match CallCredentials metadata.
        callback(list(headers.items()), None) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:21,代碼來源:auth.py

示例4: __call__

# 需要導入模塊: import grpc [as 別名]
# 或者: from grpc import AuthMetadataPluginCallback [as 別名]
def __call__(self, context, callback):
        """Passes authorization metadata into the given callback.

        Args:
            context (grpc.AuthMetadataContext): The RPC context.
            callback (grpc.AuthMetadataPluginCallback): The callback that will
                be invoked to pass in the authorization metadata.
        """
        callback(self._get_authorization_headers(context), None) 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:11,代碼來源:grpc.py


注:本文中的grpc.AuthMetadataPluginCallback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。