Capture Datadog API domain on OAuth callback
Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -123,4 +123,12 @@ var providerOrgConfigs = map[coredata.ConnectorProvider]providerOrgConfig{
|
|||||||
return s.TeamID
|
return s.TeamID
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Pattern 2-auto: the API domain is captured during the OAuth
|
||||||
|
// callback from Datadog's `domain` parameter; no picker UI.
|
||||||
|
coredata.ConnectorProviderDatadog: {
|
||||||
|
SelectedSlug: func(c *coredata.Connector) string {
|
||||||
|
s, _ := coredata.ConnectorSettings[coredata.DatadogConnectorSettings](c)
|
||||||
|
return s.Domain
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
cnnctr, err = svc.Connectors.Create(r.Context(), scope, createReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorCtx(r.Context(), "cannot create connector", log.Error(err))
|
logger.ErrorCtx(r.Context(), "cannot create connector", log.Error(err))
|
||||||
|
|||||||
Reference in New Issue
Block a user