UNPKG

f5-conx-core

Version:

F5 SDK for JavaScript with Typescript type definitions

111 lines 3.97 kB
/* * Copyright 2020. F5 Networks, Inc. See End User License Agreement ("EULA") for * license terms. Notwithstanding anything to the contrary in the EULA, Licensee * may copy and modify this software product for its internal business purposes. * Further, Licensee may upload, publish and distribute the modified version of * the software product on devcentral.f5.com. */ 'use strict'; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DoClient = void 0; class DoClient { constructor(versions, doMetaData, mgmtClient) { this.version = versions; this.metaData = doMetaData; this.mgmtClient = mgmtClient; } /** * get current DO declaration from f5 device * @returns */ get() { return __awaiter(this, void 0, void 0, function* () { return this.mgmtClient.makeRequest(this.metaData.endPoints.declare, { validateStatus: () => true }); // return 'do-get'; }); } /** * post do declaration to f5 device * @returns */ post(data) { return __awaiter(this, void 0, void 0, function* () { return yield this.mgmtClient.makeRequest(this.metaData.endPoints.declare, { method: 'POST', data }) .then((resp) => __awaiter(this, void 0, void 0, function* () { const asyncUrl = `${this.metaData.endPoints.declare}/task/${resp.data.id}`; return this.mgmtClient.followAsync(asyncUrl) .catch(() => { return this.task(resp.data.id); }); })); }); } /** * inspect DO * @returns */ inpsect() { return __awaiter(this, void 0, void 0, function* () { return this.mgmtClient.makeRequest(this.metaData.endPoints.inspect, { validateStatus: () => true }); }); } /** * get DO task * @returns */ task(id) { return __awaiter(this, void 0, void 0, function* () { /** * getting the direct task by ID from DO, only returns very high level information. not the expected details like other atc services, so we have to get all task details and filter what we need */ return this.mgmtClient.makeRequest(`${this.metaData.endPoints.declare}/task`, { validateStatus: () => true }) .then(resp => { if (id) { return resp.data = resp.data.filter((el) => el.id === id); } else { return resp; } }); }); } /** * * check DO declaration for async post parameter * * @param data do declaration * @returns true/false */ isAsync(data) { // inspect json dec for async param if (data.class === 'DO' && data.declaration.async === true) { return true; } else if (data.class === 'Device' && data.async === true) { return true; } else { return false; } } } exports.DoClient = DoClient; //# sourceMappingURL=doClient.js.map