Skip to content

Commit

Permalink
Fix app_url_name by stripping data-platform-app prefix (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk authored Feb 21, 2024
1 parent c5e9669 commit cb57411
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controlpanel/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@ def auth0_client_name(self, env_name=None):

def app_url_name(self, env_name):
format_pattern = settings.APP_URL_NAME_PATTERN.get(env_name.upper())
namespace = self.namespace.removeprefix("data-platform-app-")
if not format_pattern:
format_pattern = settings.APP_URL_NAME_PATTERN.get(self.DEFAULT_SETTING_KEY_WORD)
if format_pattern:
return format_pattern.format(app_name=self.namespace, env=env_name)
return format_pattern.format(app_name=namespace, env=env_name)
else:
return self.namespace
return namespace

def get_auth_client(self, env_name):
env_name = env_name or self.DEFAULT_AUTH_CATEGORY
Expand Down
13 changes: 13 additions & 0 deletions tests/api/models/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,16 @@ def test_app_allowed_ip_ranges():
def test_iam_role_arn():
app = App(slug="example-app")
assert app.iam_role_arn == f"arn:aws:iam::{settings.AWS_DATA_ACCOUNT_ID}:role/test_app_example-app"


@pytest.mark.parametrize("namespace, env, expected", [
("data-platform-app-example", "dev", "example-dev"),
("example", "dev", "example-dev"),
("data-platform-example", "dev", "data-platform-example-dev"),
("data-platform-app-example", "prod", "example"),
("example", "prod", "example"),
("data-platform-example", "prod", "data-platform-example"),
])
def test_app_url_name(namespace, env, expected):
app = App(namespace=namespace)
assert app.app_url_name(env_name=env) == expected

0 comments on commit cb57411

Please sign in to comment.