From e638c7265b2700249451d70c85470c8d5fdb894b Mon Sep 17 00:00:00 2001 From: Vinicius Aguiar Date: Sun, 24 Sep 2023 14:04:38 -0300 Subject: [PATCH] chore: update staging frontend url (#401) --- .github/workflows/cd-staging.yaml | 2 +- .../core/views/dataset_redirect.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cd-staging.yaml b/.github/workflows/cd-staging.yaml index 3aa91366..42de7799 100644 --- a/.github/workflows/cd-staging.yaml +++ b/.github/workflows/cd-staging.yaml @@ -67,7 +67,7 @@ jobs: memory: 500Mi env: - name: "BASE_URL_FRONTEND" - value: "https://homologation.basedosdados.org" + value: "https://staging.basedosdados.org" - name: "BASE_URL_API" value: "https://staging.api.basedosdados.org" envFrom: diff --git a/basedosdados_api/core/views/dataset_redirect.py b/basedosdados_api/core/views/dataset_redirect.py index b124df96..fa626257 100644 --- a/basedosdados_api/core/views/dataset_redirect.py +++ b/basedosdados_api/core/views/dataset_redirect.py @@ -6,24 +6,25 @@ from basedosdados_api.api.v1.models import CloudTable, Dataset +URL_MAPPING = { + "localhost:8001": "localhost:3000", + "api.basedosdados.org": "basedosdados.org", + "staging.api.basedosdados.org": "staging.basedosdados.org", + "development.api.basedosdados.org": "development.basedosdados.org", +} + class DatasetRedirectView(View): """View to redirect old dataset urls.""" def get(self, request, *args, **kwargs): """Redirect to new dataset url.""" - full_url = request.build_absolute_uri() # noqa + full_url = request.build_absolute_uri() domain = urlparse(full_url).netloc dataset = request.GET.get("dataset") dataset_slug = dataset.replace("-", "_") - BASE_URL = { - "localhost:8001": "localhost:3000", - "development.api.basedosdados.org": "development.basedosdados.org", - "staging.api.basedosdados.org": "homologation.basedosdados.org", - "api.basedosdados.org": "basedosdados.org", - } - redirect_domain = BASE_URL[domain] + redirect_domain = URL_MAPPING[domain] try: redirect_url = CloudTable.objects.filter(gcp_dataset_id=dataset_slug).first() @@ -31,7 +32,6 @@ def get(self, request, *args, **kwargs): raise CloudTable.DoesNotExist redirect_url = f"http://{redirect_domain}/dataset/{str(redirect_url.table.dataset.id)}" except CloudTable.DoesNotExist: - # não tem cloud table, procura pelo nome do dataset try: new_ds = Dataset.objects.filter(slug__icontains=dataset_slug).first() redirect_url = f"http://{redirect_domain}/dataset/{str(new_ds.id)}"