问题描述
是否有关于如何使用 python lib datadog_api_client.v2
对 datadog 进行身份验证的基本示例?我正在查看他们的文档 https://datadoghq.dev/datadog-api-client-python/v2/#apikeyauth,但没有看到任何我期待的示例:
import datadog_api_client.v2
import os
from datadog_api_client.v2 import list_tag_configurations
configuration = datadog_api_client.v2.Configuration(
host = "https://api.datadoghq.com"
)
configuration.api_key['apiKeyAuth'] = os.getenv('123')
with datadog_api_client.v2.apiclient(configuration) as api_client:
api_instance = list_tag_configurations(api_client)
print(api_instance)
解决方法
这是我发现的唯一一个关于如何在 datadog_api_client / v2 / configuration.py starting on line 83 的 github 存储库源代码中使用 Configuration
的 v2 身份验证示例:
conf = datadog_api_client.v2.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
我的猜测是使用 v1 的示例进行身份验证,但将 v1 更改为 v2 会起作用。
这是他们的根 github readme.md
from dateutil.parser import parse as dateutil_parser
import datadog_api_client.v1
from datadog_api_client.v1.api import aws_integration_api
from datadog_api_client.v1.models import *
from pprint import pprint
# Defining the host is optional and defaults to https://api.datadoghq.com
# See configuration.py for a list of all supported configuration parameters.
configuration = datadog_api_client.v1.Configuration(
host = "https://api.datadoghq.com"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below,use the example that
# satisfies your auth use case.
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
这是他们在 list_tag_configurations
上的 v2 文档中的一个示例:https://datadoghq.dev/datadog-api-client-python/v2/MetricsApi/#list_tag_configurations