UNPKG

airflow-api

Version:

A node module for airflow in Typescript

87 lines 3.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const types_1 = require("./types/"); class Airflow { constructor(config) { this.retrieve = (method, route, body, options) => { switch (method) { case types_1.httpMethods.GET: return this.axios[method](route); break; case types_1.httpMethods.PUT: return this.axios[method](route, body, options); break; case types_1.httpMethods.POST: return this.axios[method](route, body, options); break; case types_1.httpMethods.DELETE: return this.axios[method](route); break; } }; this.createDAGRunById = async (id, config) => { return await this.retrieve(types_1.httpMethods.POST, `/api/experimental/dags/${id}/dag_runs`, config); }; this.getDAGRunById = async (id) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/dags/${id}/dag_runs`); }; this.getDAGRunByIdandDate = async (id, date) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/dags/${id}/dag_runs/${date}`); }; this.checkTest = async () => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/test`); }; this.getDAGTaskById = async (id, taskId) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/dags/${id}/tasks/${taskId}`); }; this.getDAGTaskByDateandId = async (id, taskId, date) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/dags/${id}/dag_runs/${date}/tasks/${taskId}`); }; this.pauseDAGById = async (id, pause) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/dags/${id}/paused/${pause.toString()}`); }; this.latestDAGRuns = async () => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/latest_runs`); }; this.getAllPools = async () => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/pools`); }; this.getPoolByName = async (name) => { return await this.retrieve(types_1.httpMethods.GET, `/api/experimental/pools/${name}`); }; this.removePoolByName = async (name) => { return await this.retrieve(types_1.httpMethods.DELETE, `/api/experimental/pools/${name}`); }; this.createPool = async (config) => { return await this.retrieve(types_1.httpMethods.POST, `/api/experimental/pools`, config); }; if (!config.airflowUrl) { throw new Error('airflowUrl is required'); } let auth; const configBase = { baseURL: config.airflowUrl, timeout: config.timeout || 10000, }; if (config.airflowUsername && config.airflowPassword) { auth = { username: config.airflowUsername, password: config.airflowPassword }; } const _axios = axios_1.default.create(Object.assign({}, configBase, auth)); _axios.interceptors.response.use((response) => response && response.data ? response.data : null, (error) => { return Promise.reject(error.response && error.response.data); }); this.axios = _axios; this.config = config; } ; } exports.client = Airflow; ; //# sourceMappingURL=index.js.map