Capture Datadog API domain on OAuth callback
Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -293,6 +293,37 @@ func handleConnectorComplete(
|
||||
}
|
||||
}
|
||||
|
||||
// Datadog returns the customer's API domain as a `domain`
|
||||
// query parameter on the callback (CompleteWithState has
|
||||
// already validated it by building the token URL from it).
|
||||
// Re-validate defensively, reverse-map to the site key, and
|
||||
// persist both on the connector settings.
|
||||
if connectorProvider == coredata.ConnectorProviderDatadog {
|
||||
domain := query.Get("domain")
|
||||
if !connector.IsValidDatadogDomain(domain) {
|
||||
logger.WarnCtx(r.Context(), "rejecting invalid datadog domain",
|
||||
log.String("provider", string(connectorProvider)),
|
||||
)
|
||||
httpserver.RenderError(w, http.StatusBadRequest, fmt.Errorf("invalid domain"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
region, _ := connector.DatadogSiteForDomain(domain)
|
||||
raw, err := json.Marshal(&coredata.DatadogConnectorSettings{
|
||||
Region: region,
|
||||
Domain: domain,
|
||||
})
|
||||
if err != nil {
|
||||
logger.ErrorCtx(r.Context(), "cannot marshal datadog settings", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusInternalServerError, fmt.Errorf("internal error"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
createReq.RawSettings = raw
|
||||
}
|
||||
|
||||
cnnctr, err = svc.Connectors.Create(r.Context(), scope, createReq)
|
||||
if err != nil {
|
||||
logger.ErrorCtx(r.Context(), "cannot create connector", log.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user