Skip to content

Commit

Permalink
fix: account for single tenant in browseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-roys committed Jul 28, 2023
1 parent 817bab3 commit e00ca63
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions snyk/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import re
from dataclasses import InitVar, dataclass, field
from typing import Any, Dict, List, Optional, Union

Expand Down Expand Up @@ -681,11 +682,14 @@ def __getattr__(self, item):
)
elif item == "browseUrl":
# Ensure that our browse URL matches the tenant the user is making a request to
if self.organization.client.api_url.startswith("https://api.eu.snyk.io"):
url_prefix = "https://app.eu.snyk.io"
elif self.organization.client.api_url.startswith("https://api.au.snyk.io"):
url_prefix = "https://app.au.snyk.io"
tenant_matches = match = re.match(
r"^https://api\.(.*?)\.snyk\.io", self.organization.client.api_url
)
if tenant_matches:
# If a tenant is found, insert it into the URL
url_prefix = f"https://app.{match.group(1)}.snyk.io"
else:
# If no tenant is found, use a default URL
url_prefix = "https://app.snyk.io"
return f"{url_prefix}/org/{self.organization.slug}/project/{self.id}"
else:
Expand Down

0 comments on commit e00ca63

Please sign in to comment.