import requests import os from internal.helpers import get_secret def get_airflow_configuration(): profile = os.getenv("PROFILE", "devel") secret = get_secret("airflow-ui-pass") return dict( host=f'https://airflow-{"dev" if profile in ["devel", "devel2"] else profile}.fansifter.cloud/api/v1', username=secret["username"], password=secret["password"], ) airflow_configuration = get_airflow_configuration() class AirflowAPI: @staticmethod def _make_get_call(url): username, password = airflow_configuration["username"], airflow_configuration["password"] response = requests.get(url=url, auth=(username, password),) if response.status_code != 200: raise RuntimeError(response.text) return response @staticmethod def get_dag_tasks(dag_id): url = f"{airflow_configuration['host']}/dags/{dag_id}/tasks" return AirflowAPI._make_get_call(url).json() @staticmethod def get_dag_run(dag_id, dag_run_id): url = f"{airflow_configuration['host']}/dags/{dag_id}/dagRuns/{dag_run_id}" return AirflowAPI._make_get_call(url).json() @staticmethod def get_task_instances(dag_id, dag_run_id): url = f"{airflow_configuration['host']}/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances" return AirflowAPI._make_get_call(url).json()