Skip to content

Commit

Permalink
fix(datadog): oauth integration in EU (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Feb 14, 2024
1 parent 8a3031d commit 2f0bdcb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 0 additions & 1 deletion keep-ui/app/providers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default async function Page({
}: {
searchParams?: { [key: string]: string };
}) {
const session = await getServerSession(authOptions);
return <ProvidersPage searchParams={searchParams} />;
}

Expand Down
10 changes: 6 additions & 4 deletions keep-ui/app/providers/providers-tiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ const ProvidersTiles = ({
const providerName = searchParams?.get("provider_name");

useEffect(() => {
if (providerType && providerName) {
if (providerType) {
// Find the provider based on providerType and providerName
const provider = providers.find(
(provider) => provider.type === providerType
);

if (provider) {
setSelectedProvider(provider);
setFormValues({
provider_name: providerName,
});
if (providerName) {
setFormValues({
provider_name: providerName,
});
}
setOpenPanel(true);
}
}
Expand Down
21 changes: 19 additions & 2 deletions keep/providers/datadog_provider/datadog_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class DatadogProviderAuthConfig:
},
default="",
)
domain: str = dataclasses.field(
metadata={
"required": True,
"description": "Datadog API domain",
"sensitive": False,
"hint": "https://api.datadoghq.com",
},
default="https://api.datadoghq.com",
)
oauth_token: dict = dataclasses.field(
metadata={
"description": "For OAuth flow",
Expand Down Expand Up @@ -197,9 +206,14 @@ def __init__(
self.configuration.api_key[
"appKeyAuth"
] = self.authentication_config.app_key
domain = self.authentication_config.domain or "https://api.datadoghq.com"
self.configuration.host = domain
elif self.authentication_config.oauth_token:
domain = self.authentication_config.oauth_token.get(
"domain", "datadoghq.com"
)
response = requests.post(
"https://api.datadoghq.com/oauth2/v1/token",
f"https://api.{domain}/oauth2/v1/token",
data={
"grant_type": "refresh_token",
"client_id": DatadogProvider.DATADOG_CLIENT_ID,
Expand All @@ -220,6 +234,7 @@ def __init__(
raise Exception("Could not refresh token, need to re-authenticate")
response_json = response.json()
self.configuration.access_token = response_json.get("access_token")
self.configuration.host = f"https://api.{domain}"
# update the oauth_token refresh_token for next run
self.config.authentication["oauth_token"]["refresh_token"] = response_json[
"refresh_token"
Expand All @@ -238,6 +253,7 @@ def oauth2_logic(**payload) -> dict:
Returns:
dict: access token to Datadog.
"""
domain = payload.pop("domain", "datadoghq.com")
verifier = payload.pop("verifier", None)
if not verifier:
raise Exception("No verifier provided")
Expand All @@ -246,7 +262,7 @@ def oauth2_logic(**payload) -> dict:
raise Exception("No code provided")

token = requests.post(
"https://api.datadoghq.com/oauth2/v1/token",
f"https://api.{domain}/oauth2/v1/token",
data={
"grant_type": "authorization_code",
"client_id": payload["client_id"],
Expand All @@ -267,6 +283,7 @@ def oauth2_logic(**payload) -> dict:
"verifier": verifier,
"code": code,
"redirect_uri": payload["redirect_uri"],
"domain": domain,
}
}

Expand Down

0 comments on commit 2f0bdcb

Please sign in to comment.