当前位置: 首页>>代码示例>>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;未经允许,请勿转载。