Skip to content

Commit d711427

Browse files
committed
Bug fix to prevent queues from being exposed across environments.
1 parent f5dd378 commit d711427

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • services/extract/src/pipeline/extract

services/extract/src/pipeline/extract/tasks.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Standard library imports
44
import json
5+
import os
56
import time
67
from abc import ABC, abstractmethod
78

@@ -114,6 +115,14 @@ def __init__(self) -> None:
114115
f"Django project not correctly configured. {e}"
115116
) from None
116117

118+
# Parse environment variables
119+
try:
120+
self._env_flag = "-p-" if os.environ["ENV"] == "prod" else "-t-"
121+
except KeyError as e:
122+
raise RuntimeError(
123+
f'Missing required environment variable "{e}". '
124+
) from None
125+
117126
# List project queues
118127
try:
119128
self._queues = self.list_names()
@@ -202,7 +211,7 @@ def get_name(self, source: str) -> str:
202211
return matches[0]
203212

204213
def list_names(self) -> list[str]:
205-
"""Fetches the names of all queues in the current project.
214+
"""Fetches the names of all queues in the current project environment.
206215
207216
NOTE: Names are fully-qualified and have the format:
208217
`projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`
@@ -239,7 +248,11 @@ def list_names(self) -> list[str]:
239248
)
240249

241250
# Return names
242-
return [queue["name"] for queue in r.json()["queues"]]
251+
return [
252+
queue["name"]
253+
for queue in r.json()["queues"]
254+
if self._env_flag in queue["name"]
255+
]
243256

244257
def purge(self) -> None:
245258
"""Purges all tasks from the configured queues.

0 commit comments

Comments
 (0)