You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ifv, ok:=os.LookupEnv("DD_API_KEY_SECRET_ARN"); ok {
38
+
returnc.resolveFromSecretsManager(ctx, awsCfg, v)
39
+
}
40
+
41
+
ifv, ok:=os.LookupEnv("DD_API_KEY_SSM_NAME"); ok {
42
+
returnc.resolveFromSSM(ctx, awsCfg, v)
43
+
}
44
+
45
+
ifv, ok:=os.LookupEnv("DD_KMS_API_KEY"); ok {
46
+
returnc.resolveFromKMS(ctx, awsCfg, v)
78
47
}
79
-
returnerrors.New("no API key configured: set DD_API_KEY_SECRET_ARN, DD_API_KEY_SSM_NAME, DD_KMS_API_KEY, or DD_API_KEY. See: https://docs.datadoghq.com/serverless/forwarder/")
48
+
49
+
returnerrors.New("no API key configured: set DD_API_KEY_SECRET_ARN, DD_API_KEY_SSM_NAME or DD_KMS_API_KEY. See: https://docs.datadoghq.com/serverless/forwarder/")
80
50
}
81
51
82
-
// Note: the API key verification could fail (e.g. Datadog verification endpoint or network problem)
83
-
// Instead of failing the whole lambda at startup, it should run up to the log sending part and verify the
84
-
// key at this moment, adding the run to the future retry logic in such case.
returnfmt.Errorf("%w: set DD_API_KEY_SECRET_ARN, DD_API_KEY_SSM_NAME or DD_KMS_API_KEY. See: https://docs.datadoghq.com/serverless/forwarder/", ErrMissingAPIKey)
89
55
}
90
56
91
57
iflen(c.APIKey) !=32 {
92
-
returnfmt.Errorf("invalid Datadog API key format: expected 32 characters, got %d. Verify your API key at https://app.%s/organization-settings/api-keys", len(c.APIKey), c.Site)
58
+
returnfmt.Errorf("%w: expected 32 characters, got %d. Verify your API key at https://app.%s/organization-settings/api-keys", ErrInvalidAPIKey, len(c.APIKey), c.Site)
slog.Debug("failed to close response body", "error", err)
120
-
}
121
-
122
-
ifresp.StatusCode>=200&&resp.StatusCode<300 {
123
-
slog.Debug("API key validated successfully")
124
-
returnnil
125
-
}
126
-
127
-
if!retryableStatusCodes[resp.StatusCode] {
128
-
slog.Warn("API key validation failed. Verify your API key is correct and DD_SITE matches your Datadog account region. See: https://docs.datadoghq.com/getting_started/site/",
slog.Warn("API key validation failed after retries. Verify your API key is correct and DD_SITE matches your Datadog account region. See: https://docs.datadoghq.com/getting_started/site/",
144
-
"attempts", maxRetries,
145
-
"lastStatus", lastStatus,
146
-
"site", c.Site,
147
-
)
76
+
deferfunc() {
77
+
io.Copy(io.Discard, resp.Body)
78
+
resp.Body.Close()
79
+
}()
80
+
81
+
ifresp.StatusCode==http.StatusForbidden {
82
+
slog.Warn("invalid Datadog API key", slog.String("url", "https://app."+c.Site+"/organization-settings/api-keys"))
83
+
} elseifresp.StatusCode!=http.StatusOK {
84
+
slog.Warn("unexpected response from validation endpoint", slog.String("status", resp.Status))
0 commit comments