我通过转到“组织设置”>“Api 密钥”>“新密钥”在 datadog 中创建了一个 api 密钥
在 datadog 身份验证文档这是测试密钥是否有效的方法:
// Validate API key returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)
func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewAuthenticationApi(apiClient)
resp, r, err := api.Validate(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AuthenticationApi.Validate`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `AuthenticationApi.Validate`:\n%s\n", responseContent)
}
然后它说运行:
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" go run "main.go"
为什么我收到 403 禁止 ;-;
我尝试制作新钥匙,但我不知道还能做什么
您可能使用了错误的主机名或在错误的站点中创建了 API 密钥。确保您为 API 调用使用正确的
site
设置。在您引用的文档页面的右上角,有一个用于选择您的站点的下拉列表,它将更新所需的 URL,例如GET https://api.datadoghq.eu/api/v1/validate
和 DD_SITE="datadoghq.eu" DD_API_KEY="<DD_API_KEY>" go run "main.go"