简体   繁体   English

BigQuery 库中的 [AssertionCredentials] 参数是什么以及如何获取它?

[英]What is [AssertionCredentials] parameter in BigQuery library and how to get it?

BigQuery-Python is a small python package that provides functions to interact with GCP's BigQuery. BigQuery-Python是一个小型 python 包,提供与 GCP 的 BigQuery 交互的功能。 To use it one needs to first instantiate a client object.要使用它,首先需要实例化一个客户端对象。 The documentation for the function get_client() states that函数get_client() 的文档指出

def get_client(project_id=None, credentials=None,
               service_url=None, service_account=None,
               private_key=None, private_key_file=None,
               json_key=None, json_key_file=None,
               readonly=True, swallow_results=True,
               num_retries=0):
    """Return a singleton instance of BigQueryClient. Either
    AssertionCredentials or a service account and private key combination need
    to be provided in order to authenticate requests to BigQuery.
    Parameters
    ----------
    project_id : str, optional
        The BigQuery project id, required unless json_key or json_key_file is
        provided.
    credentials : oauth2client.client.SignedJwtAssertionCredentials, optional
        AssertionCredentials instance to authenticate requests to BigQuery
        (optional, must provide `service_account` and (`private_key` or
        `private_key_file`) or (`json_key` or `json_key_file`) if not included

Can someone explain to me what is the credentials parameter is and how to use it properly?有人可以向我解释什么是 credentials 参数以及如何正确使用它吗?

The credentials parameter in the case of that library refers to means of authenticating with GCP.该库的 credentials 参数是指使用 GCP 进行身份验证的方法。

The developer has provided examples in the documentation .开发人员在文档中提供了示例

You must first create your service account in GCP .您必须先在 GCP 中创建您的服务帐户 Then you can download a JSON key for that service account which you use in authenticating with the service.然后,您可以为该服务帐户下载一个 JSON 密钥,您将使用该密钥对服务进行身份验证。 Eg例如

# JSON key provided by Google
json_key = 'key.json'
 
client = get_client(json_key_file=json_key, readonly=True)

It should be noted that this is a third-party library and it seems to require setting up a service account and downloading credentials but this isn't considered a best practice.应该注意的是,这是一个第三方库,它似乎需要设置服务帐户和下载凭据,但这并不是最佳做法。 You should use attached service accounts wherever possible .您应该尽可能使用附加服务帐户 These will use Application Default Credentials which are better from a management and security point of view.这些将使用从管理和安全角度来看更好的应用程序默认凭证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM