f5-conx-core
Version:
F5 SDK for JavaScript with Typescript type definitions
122 lines • 5.71 kB
JavaScript
;
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.detectNextAsync = void 0;
const externalHttps_1 = require("../externalHttps");
const misc_1 = require("../utils/misc");
/**
* Discover if host is next or next-cm by trying to authenticate and analyzing failure messages
* @param host hostname/fqdn/IP
*/
function detectNextAsync(host) {
return __awaiter(this, void 0, void 0, function* () {
// create a new ext service to make the call
// by default the device cert is self signed, so disable cert checking
const extHttp = new externalHttps_1.ExtHttp({
rejectUnauthorized: false
});
// build a random user/pass to send to the auth endpoint
// this prevents us from locking out known users with multiple attempts
const uuid = (0, misc_1.getRandomUUID)(4, { simple: true });
const username = 'vscode-f5-' + uuid;
const password = 'discovery-' + uuid;
// try the next login
return yield extHttp.makeRequest({
url: `https://${host}/api/v1/login`,
method: "GET",
timeout: 5,
auth: {
username,
password
},
validateStatus: function (status) {
// only allow 401 response code
// we are expecting a 401 since the user/pass is just generated for this test
return status === 401;
}
})
.then(resp => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
if (
// next instance auth response
resp.statusText === 'Unauthorized' &&
((_c = (_b = (_a = resp.data) === null || _a === void 0 ? void 0 : _a._errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.detail) === 'Failed to authenticate.' &&
typeof ((_f = (_e = (_d = resp.data) === null || _d === void 0 ? void 0 : _d._errors) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.code) === 'string') {
return {
product: 'NEXT',
status: resp.status,
statusText: resp.statusText,
code: (_g = resp.data) === null || _g === void 0 ? void 0 : _g._errors[0].code,
detail: (_h = resp.data) === null || _h === void 0 ? void 0 : _h._errors[0].detail
};
}
else if (
// This is CM response to NEXT token/login request
// it's unique enough, from the message, that we now know it's CM
resp.status === 401 &&
resp.statusText === "Unauthorized" &&
((_j = resp.data) === null || _j === void 0 ? void 0 : _j.message) === "GATEWAY-00022: Invalid token data") {
return {
product: 'NEXT-CM',
status: resp.status,
statusText: resp.statusText,
code: (_k = resp.data) === null || _k === void 0 ? void 0 : _k.status,
message: (_l = resp.data) === null || _l === void 0 ? void 0 : _l.message
};
}
else {
throw Error('not next/cm');
}
});
// .catch(async resp => {
// // throw resp;
// const x = resp;
// if (resp instanceof AxiosError) {
// }
// // not next, so let's see if it's next-cm
// return await extHttp.makeRequest({
// url: `https://${host}/api/login`,
// method: "POST",
// timeout: 10,
// data: {
// username,
// password
// },
// validateStatus: function (status) {
// // only allow 401 response code
// return status === 401;
// }
// })
// .then(resp => {
// if (
// resp.statusText === 'Unauthorized' &&
// resp.data.message === 'SYSTEM-00008: Incorrect credentials' &&
// resp.data.status === 401
// ) {
// return {
// product: 'NEXT-CM',
// status: resp.status,
// statusText: resp.statusText,
// code: resp.data?.status,
// message: resp.data?.message
// } as DetectNext;
// } else {
// throw Error('not mbip')
// }
// })
// .catch(resp => {
// throw resp;
// })
// })
});
}
exports.detectNextAsync = detectNextAsync;
//# sourceMappingURL=detectNextBigip.js.map