微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

数据狗 API python 身份验证

如何解决数据狗 API python 身份验证

是否有关于如何使用 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。