azure-kusto-data
Advanced tools
Comparing version
21
index.js
@@ -0,11 +1,16 @@ | ||
"use strict"; | ||
/* tslint:disable:no-var-requires */ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const Client = require("./source/client"); | ||
const ClientRequestProperties = require("./source/clientRequestProperties"); | ||
const KustoConnectionStringBuilder = require("./source/connectionBuilder"); | ||
module.exports = { | ||
Client, | ||
KustoConnectionStringBuilder, | ||
ClientRequestProperties | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KustoConnectionStringBuilder = exports.ClientRequestProperties = exports.Client = void 0; | ||
const client_1 = __importDefault(require("./source/client")); | ||
exports.Client = client_1.default; | ||
const clientRequestProperties_1 = __importDefault(require("./source/clientRequestProperties")); | ||
exports.ClientRequestProperties = clientRequestProperties_1.default; | ||
const connectionBuilder_1 = __importDefault(require("./source/connectionBuilder")); | ||
exports.KustoConnectionStringBuilder = connectionBuilder_1.default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "azure-kusto-data", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Azure Data Explorer Query SDK", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"engines": { | ||
@@ -20,5 +21,7 @@ "node": ">= 8.0.0" | ||
"scripts": { | ||
"example": "node example.js", | ||
"test": "mocha", | ||
"lint": "eslint source --quiet" | ||
"build": "tsc -b", | ||
"prepublish": "npm run build ", | ||
"example": "npm run build && node example.js", | ||
"lint": "npm run build && tslint --project tsconfig.json --quiet", | ||
"test": "npm run build && mocha --require ts-node/register" | ||
}, | ||
@@ -35,6 +38,11 @@ "author": "", | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"mocha": "^7.1.2", | ||
"sinon": "^7.2.3" | ||
"sinon": "^7.2.3", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.1.3", | ||
"ts-node": "^9.1.1", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.13", | ||
"@types/uuid": "^8.3.0" | ||
} | ||
} |
@@ -0,14 +1,13 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const {AzureCliCredentials} = require("@azure/ms-rest-nodeauth"); | ||
module.exports = function acquireToken(connectionString, callback) { | ||
AzureCliCredentials.create({ resource: connectionString }).then((res)=>{ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ms_rest_nodeauth_1 = require("@azure/ms-rest-nodeauth"); | ||
function acquireToken(connectionString, callback) { | ||
ms_rest_nodeauth_1.AzureCliCredentials.create({ resource: connectionString }).then((res) => { | ||
const tokenData = res.tokenInfo; | ||
return callback(null, { tokenType: tokenData.tokenType, accessToken: tokenData.accessToken }); | ||
}).catch(err=>callback(err)); | ||
}; | ||
}).catch(err => callback(err)); | ||
} | ||
exports.default = acquireToken; | ||
//# sourceMappingURL=azLoginIdentityClient.js.map |
@@ -0,27 +1,38 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const moment = require("moment"); | ||
const uuidv4 = require("uuid/v4"); | ||
const AadHelper = require("./security"); | ||
const { KustoResponseDataSetV1, KustoResponseDataSetV2 } = require("./response"); | ||
const ConnectionStringBuilder = require("./connectionBuilder"); | ||
const ClientRequestProperties = require("./clientRequestProperties"); | ||
const pkg = require("../package.json"); | ||
const axios = require("axios"); | ||
const COMMAND_TIMEOUT_IN_MILLISECS = moment.duration(10.5, "minutes").asMilliseconds(); | ||
const QUERY_TIMEOUT_IN_MILLISECS = moment.duration(4.5, "minutes").asMilliseconds(); | ||
const CLIENT_SERVER_DELTA_IN_MILLISECS = moment.duration(0.5, "minutes").asMilliseconds(); | ||
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()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KustoClient = void 0; | ||
const moment_1 = __importDefault(require("moment")); | ||
const uuid_1 = __importDefault(require("uuid")); | ||
const security_1 = __importDefault(require("./security")); | ||
const response_1 = require("./response"); | ||
const connectionBuilder_1 = __importDefault(require("./connectionBuilder")); | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const COMMAND_TIMEOUT_IN_MILLISECS = moment_1.default.duration(10.5, "minutes").asMilliseconds(); | ||
const QUERY_TIMEOUT_IN_MILLISECS = moment_1.default.duration(4.5, "minutes").asMilliseconds(); | ||
const CLIENT_SERVER_DELTA_IN_MILLISECS = moment_1.default.duration(0.5, "minutes").asMilliseconds(); | ||
const MGMT_PREFIX = "."; | ||
const ExecutionType = Object.freeze({ | ||
Mgmt: 0, | ||
Query: 1, | ||
Ingest: 2 | ||
}); | ||
module.exports = class KustoClient { | ||
var ExecutionType; | ||
(function (ExecutionType) { | ||
ExecutionType[ExecutionType["Mgmt"] = 0] = "Mgmt"; | ||
ExecutionType[ExecutionType["Query"] = 1] = "Query"; | ||
ExecutionType[ExecutionType["Ingest"] = 2] = "Ingest"; | ||
})(ExecutionType || (ExecutionType = {})); | ||
class KustoClient { | ||
constructor(kcsb) { | ||
this.connectionString = typeof (kcsb) === "string" ? new ConnectionStringBuilder(kcsb) : kcsb; | ||
this.connectionString = typeof (kcsb) === "string" ? new connectionBuilder_1.default(kcsb) : kcsb; | ||
this.cluster = this.connectionString.dataSource; | ||
@@ -33,97 +44,91 @@ this.endpoints = { | ||
}; | ||
this.aadHelper = new AadHelper(this.connectionString); | ||
this.aadHelper = new security_1.default(this.connectionString); | ||
this.headers = { | ||
"Accept": "application/json", | ||
"Accept-Encoding": "gzip,deflate", | ||
"x-ms-client-version": `Kusto.Node.Client:${pkg.version}`, | ||
"x-ms-client-version": `Kusto.Node.Client:${package_json_1.default.version}`, | ||
}; | ||
} | ||
async execute(db, query, properties) { | ||
query = query.trim(); | ||
if (query.startsWith(MGMT_PREFIX)) { | ||
return this.executeMgmt(db, query, properties); | ||
} | ||
return this.executeQuery(db, query, properties); | ||
execute(db, query, properties) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
query = query.trim(); | ||
if (query.startsWith(MGMT_PREFIX)) { | ||
return this.executeMgmt(db, query, properties); | ||
} | ||
return this.executeQuery(db, query, properties); | ||
}); | ||
} | ||
async executeQuery(db, query, properties) { | ||
return this._execute(this.endpoints.query, ExecutionType.Query, db, query, null, properties); | ||
executeQuery(db, query, properties) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this._execute(this.endpoints.query, ExecutionType.Query, db, query, null, properties); | ||
}); | ||
} | ||
async executeMgmt(db, query, properties) { | ||
return this._execute(this.endpoints.mgmt, ExecutionType.Mgmt, db, query, null, properties); | ||
executeMgmt(db, query, properties) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this._execute(this.endpoints.mgmt, ExecutionType.Mgmt, db, query, null, properties); | ||
}); | ||
} | ||
async executeStreamingIngest(db, table, stream, streamFormat, mappingName) { | ||
let endpoint = `${this.endpoints.ingest}/${db}/${table}?streamFormat=${streamFormat}`; | ||
if (mappingName != null) { | ||
endpoint += `&mappingName=${mappingName}`; | ||
} | ||
return this._execute(endpoint, ExecutionType.Ingest, db, null, stream, null); | ||
executeStreamingIngest(db, table, stream, streamFormat, mappingName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = `${this.endpoints.ingest}/${db}/${table}?streamFormat=${streamFormat}`; | ||
if (mappingName != null) { | ||
endpoint += `&mappingName=${mappingName}`; | ||
} | ||
return this._execute(endpoint, ExecutionType.Ingest, db, null, stream, null); | ||
}); | ||
} | ||
async _execute(endpoint, executionType, db, query, stream, properties) { | ||
const headers = {}; | ||
Object.assign(headers, this.headers); | ||
let payload; | ||
let clientRequestPrefix = ""; | ||
let clientRequestId; | ||
let timeout = this._getClientTimeout(executionType, properties); | ||
if (query != null) { | ||
payload = { | ||
"db": db, | ||
"csl": query | ||
}; | ||
if (properties != null && properties instanceof ClientRequestProperties) { | ||
payload.properties = properties.toJson(); | ||
clientRequestId = properties.clientRequestId; | ||
_execute(endpoint, executionType, db, query, stream, properties) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const headers = {}; | ||
Object.assign(headers, this.headers); | ||
let payload; | ||
let clientRequestPrefix = ""; | ||
let clientRequestId; | ||
const timeout = this._getClientTimeout(executionType, properties); | ||
let payloadStr = ""; | ||
if (query != null) { | ||
payload = { | ||
"db": db, | ||
"csl": query | ||
}; | ||
if (properties != null) { | ||
payload.properties = properties.toJson(); | ||
clientRequestId = properties.clientRequestId; | ||
} | ||
payloadStr = JSON.stringify(payload); | ||
headers["Content-Type"] = "application/json; charset=utf-8"; | ||
clientRequestPrefix = "KNC.execute;"; | ||
} | ||
payload = JSON.stringify(payload); | ||
headers["Content-Type"] = "application/json; charset=utf-8"; | ||
clientRequestPrefix = "KNC.execute;"; | ||
} else if (stream != null) { | ||
payload = stream; | ||
clientRequestPrefix = "KNC.executeStreamingIngest;"; | ||
headers["Content-Encoding"] = "gzip"; | ||
headers["Content-Type"] = "multipart/form-data"; | ||
} | ||
headers["x-ms-client-request-id"] = clientRequestId || clientRequestPrefix + `${uuidv4()}`; | ||
headers["Authorization"] = await this.aadHelper._getAuthHeader(); | ||
return this._doRequest(endpoint, executionType, headers, payload, timeout, properties); | ||
else if (stream != null) { | ||
payloadStr = stream; | ||
clientRequestPrefix = "KNC.executeStreamingIngest;"; | ||
headers["Content-Encoding"] = "gzip"; | ||
headers["Content-Type"] = "multipart/form-data"; | ||
} | ||
headers["x-ms-client-request-id"] = clientRequestId || clientRequestPrefix + `${uuid_1.default.v4()}`; | ||
headers.Authorization = yield this.aadHelper._getAuthHeader(); | ||
return this._doRequest(endpoint, executionType, headers, payloadStr, timeout, properties); | ||
}); | ||
} | ||
async _doRequest(endpoint, executionType, headers, payload, timeout, properties) { | ||
let axiosConfig = { | ||
headers: headers, | ||
gzip: true, | ||
timeout: timeout | ||
}; | ||
let axiosResponse; | ||
try { | ||
axiosResponse = await axios.post(endpoint, payload, axiosConfig); | ||
} | ||
catch (error) { | ||
if (error.response) { | ||
throw error.response.data.error; | ||
_doRequest(endpoint, executionType, headers, payload, timeout, properties) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const axiosConfig = { | ||
headers, | ||
gzip: true, | ||
timeout | ||
}; | ||
let axiosResponse; | ||
try { | ||
axiosResponse = yield axios_1.default.post(endpoint, payload, axiosConfig); | ||
} | ||
throw error; | ||
} | ||
return this._parseResponse(axiosResponse.data, executionType, properties); | ||
catch (error) { | ||
if (error.response) { | ||
throw error.response.data.error; | ||
} | ||
throw error; | ||
} | ||
return this._parseResponse(axiosResponse.data, executionType, properties, axiosResponse.status); | ||
}); | ||
} | ||
_parseResponse(response, executionType, properties) { | ||
_parseResponse(response, executionType, properties, status) { | ||
const { raw } = properties || {}; | ||
@@ -133,21 +138,21 @@ if (raw === true || executionType == ExecutionType.Ingest) { | ||
} | ||
let kustoResponse = null; | ||
try { | ||
if (executionType == ExecutionType.Query) { | ||
kustoResponse = new KustoResponseDataSetV2(response); | ||
} else { | ||
kustoResponse = new KustoResponseDataSetV1(response); | ||
kustoResponse = new response_1.KustoResponseDataSetV2(response); | ||
} | ||
} catch (ex) { | ||
throw `Failed to parse response ({${response.status}}) with the following error [${ex}].`; | ||
else { | ||
kustoResponse = new response_1.KustoResponseDataSetV1(response); | ||
} | ||
} | ||
catch (ex) { | ||
throw new Error(`Failed to parse response ({${status}}) with the following error [${ex}].`); | ||
} | ||
if (kustoResponse.getErrorsCount() > 0) { | ||
throw `Kusto request had errors. ${kustoResponse.getExceptions()}`; | ||
throw new Error(`Kusto request had errors. ${kustoResponse.getExceptions()}`); | ||
} | ||
return kustoResponse; | ||
} | ||
_getClientTimeout(executionType, properties) { | ||
if (properties != null && properties instanceof ClientRequestProperties) { | ||
if (properties != null) { | ||
const clientTimeout = properties.getClientTimeout(); | ||
@@ -157,3 +162,2 @@ if (clientTimeout) { | ||
} | ||
const serverTimeout = properties.getTimeout(); | ||
@@ -164,6 +168,7 @@ if (serverTimeout) { | ||
} | ||
const defaultTimeout = executionType == ExecutionType.Query ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS; | ||
return defaultTimeout; | ||
return executionType == ExecutionType.Query ? QUERY_TIMEOUT_IN_MILLISECS : COMMAND_TIMEOUT_IN_MILLISECS; | ||
} | ||
}; | ||
} | ||
exports.KustoClient = KustoClient; | ||
exports.default = KustoClient; | ||
//# sourceMappingURL=client.js.map |
@@ -0,5 +1,7 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
module.exports = class ClientRequestProperties { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ClientRequestProperties = void 0; | ||
class ClientRequestProperties { | ||
constructor(options, parameters, clientRequestId) { | ||
@@ -10,18 +12,13 @@ this._options = options || {}; | ||
} | ||
setOption(name, value) { | ||
this._options[name] = value; | ||
} | ||
getOption(name, defaultValue) { | ||
if (!this._options || this._options[name] === undefined) | ||
return defaultValue; | ||
return this._options[name]; | ||
} | ||
setParameter(name, value) { | ||
this._parameters[name] = value; | ||
} | ||
getParameter(name, defaultValue) { | ||
@@ -31,33 +28,24 @@ if (!this._parameters || this._parameters[name] === undefined) { | ||
} | ||
return this._parameters[name]; | ||
} | ||
clearParameters() { | ||
this._parameters = {}; | ||
} | ||
setTimeout(timeoutMillis) { | ||
this.setOption("servertimeout", timeoutMillis); | ||
} | ||
getTimeout() { | ||
return this.getOption("servertimeout"); | ||
} | ||
setClientTimeout(timeoutMillis) { | ||
this._clientTimeOut = timeoutMillis; | ||
} | ||
getClientTimeout() { | ||
return this._clientTimeOut; | ||
} | ||
clearOptions() { | ||
this._options = {}; | ||
} | ||
toJson() { | ||
let json = {}; | ||
const json = {}; | ||
if (Object.keys(this._options).length !== 0) { | ||
@@ -69,26 +57,23 @@ json.Options = this._options; | ||
} | ||
if (Object.keys(this._parameters).length !== 0) { | ||
json.Parameters = this._parameters; | ||
} | ||
return Object.keys(json).length !== 0 ? json : null; | ||
} | ||
toString() { | ||
return JSON.stringify(this.toJson()); | ||
} | ||
_msToTimespan(duration) { | ||
var milliseconds = parseInt((duration % 1000) / 100) | ||
, seconds = parseInt((duration / 1000) % 60) | ||
, minutes = parseInt((duration / (1000 * 60)) % 60) | ||
, hours = parseInt((duration / (1000 * 60 * 60)) % 24); | ||
hours = (hours < 10) ? "0" + hours : hours; | ||
minutes = (minutes < 10) ? "0" + minutes : minutes; | ||
seconds = (seconds < 10) ? "0" + seconds : seconds; | ||
return hours + ":" + minutes + ":" + seconds + "." + milliseconds; | ||
const milliseconds = Math.floor((duration % 1000) / 100); | ||
const seconds = Math.floor((duration / 1000) % 60); | ||
const minutes = Math.floor((duration / (1000 * 60)) % 60); | ||
const hours = Math.floor((duration / (1000 * 60 * 60)) % 24); | ||
const hoursStr = (hours < 10) ? "0" + hours : String(hours); | ||
const minutesStr = (minutes < 10) ? "0" + minutes : String(minutes); | ||
const secondsStr = (seconds < 10) ? "0" + seconds : String(seconds); | ||
return hoursStr + ":" + minutesStr + ":" + secondsStr + "." + milliseconds; | ||
} | ||
}; | ||
} | ||
exports.ClientRequestProperties = ClientRequestProperties; | ||
exports.default = ClientRequestProperties; | ||
//# sourceMappingURL=clientRequestProperties.js.map |
@@ -0,4 +1,6 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KustoConnectionStringBuilder = void 0; | ||
const KeywordMapping = Object.freeze({ | ||
@@ -46,8 +48,6 @@ dataSource: { | ||
}); | ||
const getPropName = (key) => { | ||
let _key = key.trim().toLowerCase(); | ||
for (let keyword of Object.keys(KeywordMapping)) { | ||
let k = KeywordMapping[keyword]; | ||
const _key = key.trim().toLowerCase(); | ||
for (const keyword of Object.keys(KeywordMapping)) { | ||
const k = KeywordMapping[keyword]; | ||
if (k.validNames.indexOf(_key) >= 0) { | ||
@@ -59,28 +59,24 @@ return k.propName; | ||
}; | ||
module.exports = class KustoConnectionStringBuilder { | ||
class KustoConnectionStringBuilder { | ||
constructor(connectionString) { | ||
if (!connectionString || connectionString.trim().length === 0) throw new Error("Missing connection string"); | ||
if (!connectionString || connectionString.trim().length === 0) | ||
throw new Error("Missing connection string"); | ||
if (connectionString.endsWith("/") || connectionString.endsWith("\\")) { | ||
connectionString = connectionString.slice(0, -1); | ||
} | ||
if (!!connectionString && connectionString.split(";")[0].indexOf("=") === -1) { | ||
connectionString = "Data Source=" + connectionString; | ||
} | ||
this[KeywordMapping.authorityId.propName] = "common"; | ||
let params = connectionString.split(";"); | ||
for (let i = 0; i < params.length; i++) { | ||
let kvp = params[i].split("="); | ||
const params = connectionString.split(";"); | ||
for (const item of params) { | ||
const kvp = item.split("="); | ||
this[getPropName(kvp[0])] = kvp[1].trim(); | ||
} | ||
} | ||
static withAadUserPasswordAuthentication(connectionString, userId, password, authorityId) { | ||
if (!userId || userId.trim().length == 0) throw new Error("Invalid user"); | ||
if (!password || password.trim().length == 0) throw new Error("Invalid password"); | ||
if (!userId || userId.trim().length == 0) | ||
throw new Error("Invalid user"); | ||
if (!password || password.trim().length == 0) | ||
throw new Error("Invalid password"); | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
@@ -90,10 +86,9 @@ kcsb[KeywordMapping.aadUserId.propName] = userId; | ||
kcsb[KeywordMapping.authorityId.propName] = authorityId || "common"; | ||
return kcsb; | ||
} | ||
static withAadApplicationKeyAuthentication(connectionString, aadAppId, appKey, authorityId) { | ||
if (!aadAppId || aadAppId.trim().length == 0) throw new Error("Invalid app id"); | ||
if (!appKey || appKey.trim().length == 0) throw new Error("Invalid app key"); | ||
if (!aadAppId || aadAppId.trim().length == 0) | ||
throw new Error("Invalid app id"); | ||
if (!appKey || appKey.trim().length == 0) | ||
throw new Error("Invalid app key"); | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
@@ -103,11 +98,11 @@ kcsb[KeywordMapping.applicationClientId.propName] = aadAppId; | ||
kcsb[KeywordMapping.authorityId.propName] = authorityId || "common"; | ||
return kcsb; | ||
} | ||
static withAadApplicationCertificateAuthentication(connectionString, aadAppId, certificate, thumbprint, authorityId) { | ||
if (!aadAppId || aadAppId.trim().length == 0) throw new Error("Invalid app id"); | ||
if (!certificate || certificate.trim().length == 0) throw new Error("Invalid certificate"); | ||
if (!thumbprint || thumbprint.trim().length == 0) throw new Error("Invalid thumbprint"); | ||
if (!aadAppId || aadAppId.trim().length == 0) | ||
throw new Error("Invalid app id"); | ||
if (!certificate || certificate.trim().length == 0) | ||
throw new Error("Invalid certificate"); | ||
if (!thumbprint || thumbprint.trim().length == 0) | ||
throw new Error("Invalid thumbprint"); | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
@@ -118,7 +113,4 @@ kcsb[KeywordMapping.applicationClientId.propName] = aadAppId; | ||
kcsb[KeywordMapping.authorityId.propName] = authorityId || "common"; | ||
return kcsb; | ||
} | ||
static withAadDeviceAuthentication(connectionString, authorityId, authCallback) { | ||
@@ -128,11 +120,8 @@ const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
kcsb.AuthorizationCallback = authCallback; | ||
return kcsb; | ||
} | ||
// Notice: you can leave `msiEndpoint` and `clientId` | ||
// Notice: you can leave `msiEndpoint` and `clientId` | ||
static withAadManagedIdentities(connectionString, msiEndpoint, clientId) { | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
kcsb.msiEndpoint = msiEndpoint; | ||
if (msiEndpoint == undefined) { | ||
@@ -142,28 +131,24 @@ if (process && process.env && process.env.MSI_ENDPOINT) { | ||
kcsb.msiSecret = process.env.MSI_SECRET; | ||
} else { | ||
} | ||
else { | ||
kcsb.msiEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token"; | ||
} | ||
} | ||
kcsb.msiClientId = clientId; | ||
kcsb.managedIdentity = true; | ||
return kcsb; | ||
} | ||
static withAzLoginIdentity(connectionString) { | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
kcsb.azLoginIdentity = true; | ||
return kcsb; | ||
} | ||
static withAccessToken(connectionString, accessToken) { | ||
const kcsb = new KustoConnectionStringBuilder(connectionString); | ||
kcsb.accessToken = accessToken; | ||
return kcsb; | ||
} | ||
}; | ||
} | ||
exports.KustoConnectionStringBuilder = KustoConnectionStringBuilder; | ||
exports.default = KustoConnectionStringBuilder; | ||
//# sourceMappingURL=connectionBuilder.js.map |
@@ -0,23 +1,22 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const request = require("request"); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-ignore | ||
const request_1 = __importDefault(require("request")); | ||
const MSI_API_VERSION = "2018-02-01"; | ||
const MSI_FUNCTION_API_VERSION = "2017-09-01"; | ||
module.exports = function acquireToken(resource, msiEndpoint, msiClientId, msiSecret, callback) { | ||
function acquireToken(resource, msiEndpoint, msiClientId, msiSecret, callback) { | ||
let msiUri = `${msiEndpoint}/?resource=${resource}&api-version=${msiSecret ? MSI_FUNCTION_API_VERSION : MSI_API_VERSION}`; | ||
if (msiClientId) { | ||
msiUri += `&client_id=${msiClientId}`; | ||
} | ||
const headers = {}; | ||
if (msiSecret) { | ||
headers.Secret = msiSecret; | ||
} | ||
request({ | ||
request_1.default({ | ||
method: "GET", | ||
@@ -27,11 +26,13 @@ url: msiUri, | ||
}, (error, response, body) => { | ||
if (error) return callback(error); | ||
if (error) | ||
return callback(error); | ||
if (response.statusCode < 200 || response.statusCode >= 400) { | ||
return callback(`Unexpected status ${response.statusCode}.\n ${response.body}`); | ||
} | ||
const tokenData = JSON.parse(body); | ||
return callback(null, { tokenType: tokenData.token_type, accessToken: tokenData.access_token }); | ||
}); | ||
}; | ||
} | ||
exports.default = acquireToken; | ||
; | ||
//# sourceMappingURL=managedIdentitiesClient.js.map |
@@ -0,22 +1,24 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const moment = require("moment"); | ||
const WellKnownDataSet = { | ||
PrimaryResult: "PrimaryResult", | ||
QueryCompletionInformation: "QueryCompletionInformation", | ||
TableOfContents: "TableOfContents", | ||
QueryProperties: "QueryProperties" | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
module.exports.WellKnownDataSet = WellKnownDataSet; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KustoResultTable = exports.KustoResultColumn = exports.KustoResultRow = exports.WellKnownDataSet = void 0; | ||
const moment_1 = __importDefault(require("moment")); | ||
var WellKnownDataSet; | ||
(function (WellKnownDataSet) { | ||
WellKnownDataSet["PrimaryResult"] = "PrimaryResult"; | ||
WellKnownDataSet["QueryCompletionInformation"] = "QueryCompletionInformation"; | ||
WellKnownDataSet["TableOfContents"] = "TableOfContents"; | ||
WellKnownDataSet["QueryProperties"] = "QueryProperties"; | ||
})(WellKnownDataSet = exports.WellKnownDataSet || (exports.WellKnownDataSet = {})); | ||
; | ||
const ValueParser = { | ||
datetime: moment, | ||
timespan: moment.duration, | ||
DateTime: moment, | ||
TimeSpan: moment.duration, | ||
datetime: moment_1.default, | ||
timespan: moment_1.default.duration, | ||
DateTime: moment_1.default, | ||
TimeSpan: moment_1.default.duration, | ||
}; | ||
class KustoResultRow { | ||
@@ -26,30 +28,23 @@ constructor(columns, row) { | ||
this.raw = row; | ||
for (let col of this.columns) { | ||
let parse = ValueParser[col.type]; | ||
for (const col of this.columns) { | ||
const parse = ValueParser[col.type]; | ||
this[col.name] = parse ? parse(row[col.ordinal]) : row[col.ordinal]; | ||
} | ||
} | ||
* values() { | ||
for (let item in this.rows) { | ||
*values() { | ||
// tslint:disable-next-line:forin | ||
for (const item in this.rows) { | ||
yield item; | ||
} | ||
} | ||
getValueAt(index) { | ||
return this[this.columns[index].name]; | ||
} | ||
toJson() { | ||
let obj = {}; | ||
for (let col of this.columns) { | ||
const obj = {}; | ||
for (const col of this.columns) { | ||
obj[col.name] = this[col.name]; | ||
} | ||
return obj; | ||
} | ||
toString() { | ||
@@ -59,17 +54,14 @@ return JSON.stringify(this.toJson()); | ||
} | ||
module.exports.KustoResultRow = KustoResultRow; | ||
exports.KustoResultRow = KustoResultRow; | ||
class KustoResultColumn { | ||
constructor(columnObj, ordinal) { | ||
this.name = columnObj.ColumnName; | ||
var _a, _b; | ||
this.name = (_a = columnObj.ColumnName) !== null && _a !== void 0 ? _a : null; | ||
// TODO: should validate type? should coarse value to type? | ||
this.type = columnObj.ColumnType || columnObj.DateType; | ||
this.type = (_b = (columnObj.ColumnType || columnObj.DateType)) !== null && _b !== void 0 ? _b : null; | ||
this.ordinal = ordinal; | ||
} | ||
} | ||
module.exports.KustoResultColumn = KustoResultColumn; | ||
module.exports.KustoResultTable = class KustoResultTable { | ||
exports.KustoResultColumn = KustoResultColumn; | ||
class KustoResultTable { | ||
constructor(tableObj) { | ||
@@ -80,39 +72,32 @@ this.name = tableObj.TableName; | ||
} | ||
if (tableObj.TableKind) { | ||
this.kind = tableObj.TableKind; | ||
} | ||
this.columns = tableObj.Columns.map((item, index) => new KustoResultColumn(item, index)); | ||
this._rows = tableObj.Rows; | ||
if (this._rows && this._rows.length > 0) { | ||
for (let i = 0; i<tableObj.Rows.length; i++) { | ||
Object.defineProperty(this, i, { get: () => new KustoResultRow(this.columns, this._rows[i])}); | ||
for (let i = 0; i < tableObj.Rows.length; i++) { | ||
Object.defineProperty(this, i, { get: () => new KustoResultRow(this.columns, this._rows[i]) }); | ||
} | ||
} | ||
} | ||
* rows() { | ||
for (let row of this._rows) { | ||
*rows() { | ||
for (const row of this._rows) { | ||
yield new KustoResultRow(this.columns, row); | ||
} | ||
} | ||
toJson() { | ||
let table = {}; | ||
const table = {}; | ||
table.name = this.name; | ||
table.data = []; | ||
for (let row of this.rows()) { | ||
for (const row of this.rows()) { | ||
table.data.push(row.toJson()); | ||
} | ||
return table; | ||
} | ||
toString() { | ||
return JSON.stringify(this.toJson()); | ||
} | ||
}; | ||
} | ||
exports.KustoResultTable = KustoResultTable; | ||
//# sourceMappingURL=models.js.map |
@@ -0,25 +1,24 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const { KustoResultTable, WellKnownDataSet } = require("./models"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KustoResponseDataSetV2 = exports.KustoResponseDataSetV1 = exports.KustoResponseDataSet = void 0; | ||
const models_1 = require("./models"); | ||
class KustoResponseDataSet { | ||
constructor(tables) { | ||
let _tables = tables; | ||
if (!Array.isArray(tables)) { | ||
_tables = [tables]; | ||
} | ||
this.tables = []; | ||
this.tableNames = []; | ||
this.primaryResults = []; | ||
for (let table of _tables) { | ||
let resultTable = new KustoResultTable(table); | ||
for (const table of _tables) { | ||
const resultTable = new models_1.KustoResultTable(table); | ||
this.tables.push(resultTable); | ||
this.tableNames.push(resultTable.name); | ||
if (resultTable.kind === WellKnownDataSet.PrimaryResult) { | ||
if (resultTable.kind === models_1.WellKnownDataSet.PrimaryResult) { | ||
this.primaryResults.push(resultTable); | ||
} else if (resultTable.kind === WellKnownDataSet.QueryCompletionInformation) { | ||
} | ||
else if (resultTable.kind === models_1.WellKnownDataSet.QueryCompletionInformation) { | ||
this.statusTable = resultTable; | ||
@@ -29,11 +28,8 @@ } | ||
} | ||
getErrorsCount() { | ||
let errors = 0; | ||
if (this.statusTable && this.statusTable._rows.length != 0) { | ||
let minLevel = 4; | ||
const errorColumn = this.constructor.getErrorColumn(); | ||
for (let row of this.statusTable.rows()) { | ||
const errorColumn = this.getErrorColumn(); | ||
for (const row of this.statusTable.rows()) { | ||
if (row[errorColumn] < 4) { | ||
@@ -43,3 +39,4 @@ if (row[errorColumn] < minLevel) { | ||
errors = 1; | ||
} else if (row[errorColumn] == minLevel) { | ||
} | ||
else if (row[errorColumn] == minLevel) { | ||
errors += 1; | ||
@@ -50,17 +47,14 @@ } | ||
} | ||
if (this.dataSetCompletion && this.dataSetCompletion["HasErrors"]) { | ||
if (this.dataSetCompletion && this.dataSetCompletion.HasErrors) { | ||
errors += 1; | ||
} | ||
return errors; | ||
} | ||
getExceptions() { | ||
const result = []; | ||
if (this.statusTable && this.statusTable._rows.length != 0) { | ||
const errorColumn = this.constructor.getErrorColumn(); | ||
const cridColumn = this.constructor.getCridColumn(); | ||
const statusColumn = this.constructor.getStatusColumn(); | ||
for (let row of this.statusTable.rows()) { | ||
const errorColumn = this.getErrorColumn(); | ||
const cridColumn = this.getCridColumn(); | ||
const statusColumn = this.getStatusColumn(); | ||
for (const row of this.statusTable.rows()) { | ||
if (row[errorColumn] < 4) { | ||
@@ -71,5 +65,5 @@ result.push(`Please provide the following data to Kusto: CRID=${row[cridColumn]} Description: ${row[statusColumn]}`); | ||
} | ||
if (this.dataSetCompletion && this.dataSetCompletion["HasErrors"]) { | ||
for (let row of this.dataSetCompletion["OneApiErrors"]) { | ||
result.push( row["error"]["@message"]); | ||
if (this.dataSetCompletion && this.dataSetCompletion.HasErrors && this.dataSetCompletion.OneApiErrors) { | ||
for (const row of this.dataSetCompletion.OneApiErrors) { | ||
result.push(row.error["@message"]); | ||
} | ||
@@ -80,57 +74,55 @@ } | ||
} | ||
exports.KustoResponseDataSet = KustoResponseDataSet; | ||
// TODO: should only expose 1 response type, versioning should be handled internally | ||
module.exports.KustoResponseDataSetV1 = class KustoResponseDataSetV1 extends KustoResponseDataSet { | ||
static getStatusColumn() { return "StatusDescription"; } | ||
static getCridColumn() { return "ClientActivityId"; } | ||
static getErrorColumn() { return "Severity"; } | ||
static getTablesKinds() { | ||
return { | ||
"QueryResult": WellKnownDataSet.PrimaryResult, | ||
"QueryProperties": WellKnownDataSet.QueryProperties, | ||
"QueryStatus": WellKnownDataSet.QueryCompletionInformation, | ||
}; | ||
} | ||
class KustoResponseDataSetV1 extends KustoResponseDataSet { | ||
constructor(data) { | ||
super(data.Tables); | ||
this.dataSetCompletion = null; | ||
if (this.tables.length <= 2) { | ||
if (this.tables[0].kind === undefined) { | ||
this.tables[0].kind = WellKnownDataSet.PrimaryResult; | ||
this.tables[0].kind = models_1.WellKnownDataSet.PrimaryResult; | ||
this.primaryResults.push(this.tables[0]); | ||
} | ||
this.tables[0].id = 0; | ||
if (this.tables.length == 2) { | ||
this.tables[1].kind = WellKnownDataSet.QueryProperties; | ||
this.tables[1].kind = models_1.WellKnownDataSet.QueryProperties; | ||
this.tables[1].id = 1; | ||
} | ||
} else { | ||
} | ||
else { | ||
const toc = this.tables[this.tables.length - 1]; | ||
toc.kind = WellKnownDataSet.TableOfContents; | ||
toc.kind = models_1.WellKnownDataSet.TableOfContents; | ||
toc.id = this.tables.length - 1; | ||
for (let i = 0; i < this.tables.length - 1; i++) { | ||
this.tables[i].name = toc[i]["Name"]; | ||
this.tables[i].id = toc[i]["Id"]; | ||
this.tables[i].kind = KustoResponseDataSetV1.getTablesKinds()[toc[i]["Kind"]]; | ||
this.tables[i].name = toc[i].Name; | ||
this.tables[i].id = toc[i].Id; | ||
this.tables[i].kind = KustoResponseDataSetV1.getTablesKinds()[toc[i].Kind]; | ||
} | ||
} | ||
this.version = "1.0"; | ||
} | ||
}; | ||
getStatusColumn() { | ||
return "StatusDescription"; | ||
} | ||
getCridColumn() { | ||
return "ClientActivityId"; | ||
} | ||
getErrorColumn() { | ||
return "Severity"; | ||
} | ||
static getTablesKinds() { | ||
return { | ||
"QueryResult": models_1.WellKnownDataSet.PrimaryResult, | ||
"QueryProperties": models_1.WellKnownDataSet.QueryProperties, | ||
"QueryStatus": models_1.WellKnownDataSet.QueryCompletionInformation, | ||
}; | ||
} | ||
} | ||
exports.KustoResponseDataSetV1 = KustoResponseDataSetV1; | ||
// TODO: should only expose 1 response type, versioning should be handled internally | ||
module.exports.KustoResponseDataSetV2 = class KustoResponseDataSetV2 extends KustoResponseDataSet { | ||
static getStatusColumn() { return "Payload"; } | ||
static getErrorColumn() { return "Level"; } | ||
static getCridColumn() { return "ClientRequestId"; } | ||
class KustoResponseDataSetV2 extends KustoResponseDataSet { | ||
constructor(data) { | ||
let dataTables = []; | ||
let dataSetHeader; | ||
let dataSetCompletion; | ||
const dataTables = []; | ||
let dataSetHeader = null; | ||
let dataSetCompletion = null; | ||
data.forEach(frame => { | ||
@@ -149,3 +141,2 @@ switch (frame.FrameType) { | ||
}); | ||
super(dataTables); | ||
@@ -156,2 +147,14 @@ this.dataSetHeader = dataSetHeader; | ||
} | ||
}; | ||
getStatusColumn() { | ||
return "Payload"; | ||
} | ||
getErrorColumn() { | ||
return "Level"; | ||
} | ||
getCridColumn() { | ||
return "ClientRequestId"; | ||
} | ||
} | ||
exports.KustoResponseDataSetV2 = KustoResponseDataSetV2; | ||
; | ||
//# sourceMappingURL=response.js.map |
@@ -0,35 +1,38 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
const { AuthenticationContext } = require("adal-node"); | ||
const acquireManagedIdentityToken = require("./managedIdentitiesClient"); | ||
const azLoginIndentityToken = require("./azLoginIdentityClient"); | ||
const AuthenticationMethod = Object.freeze({ | ||
username: 0, | ||
appKey: 1, | ||
appCertificate: 2, | ||
deviceLogin: 3, | ||
managedIdentities: 4, | ||
azLogin: 5, | ||
accessToken: 6, | ||
}); | ||
module.exports = class AadHelper { | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AadHelper = void 0; | ||
const adal_node_1 = require("adal-node"); | ||
const managedIdentitiesClient_1 = __importDefault(require("./managedIdentitiesClient")); | ||
const azLoginIdentityClient_1 = __importDefault(require("./azLoginIdentityClient")); | ||
var AuthenticationMethod; | ||
(function (AuthenticationMethod) { | ||
AuthenticationMethod[AuthenticationMethod["username"] = 0] = "username"; | ||
AuthenticationMethod[AuthenticationMethod["appKey"] = 1] = "appKey"; | ||
AuthenticationMethod[AuthenticationMethod["appCertificate"] = 2] = "appCertificate"; | ||
AuthenticationMethod[AuthenticationMethod["deviceLogin"] = 3] = "deviceLogin"; | ||
AuthenticationMethod[AuthenticationMethod["managedIdentities"] = 4] = "managedIdentities"; | ||
AuthenticationMethod[AuthenticationMethod["azLogin"] = 5] = "azLogin"; | ||
AuthenticationMethod[AuthenticationMethod["accessToken"] = 6] = "accessToken"; | ||
})(AuthenticationMethod || (AuthenticationMethod = {})); | ||
class AadHelper { | ||
constructor(kcsb) { | ||
this.token = {}; | ||
const authority = kcsb.authorityId || "common"; | ||
let url; | ||
if (!kcsb.dataSource) { | ||
throw new Error("Invalid string builder - missing dataSource"); | ||
} | ||
// support node compatibility | ||
try { | ||
url = new URL(kcsb.dataSource); | ||
} catch (e) { | ||
url = new URL(kcsb.dataSource); // CHANGE | ||
} | ||
catch (e) { | ||
const URL = require("url").URL; | ||
url = new URL(kcsb.dataSource); | ||
} | ||
const aadAuthorityUri = process.env.AadAuthorityUri; | ||
@@ -39,37 +42,53 @@ const fullAuthorityUri = aadAuthorityUri ? | ||
: `https://login.microsoftonline.com/${authority}`; | ||
this.kustoCluster = `${url.protocol}//${url.hostname}`; | ||
this.adalContext = new AuthenticationContext(fullAuthorityUri); | ||
this.adalContext = new adal_node_1.AuthenticationContext(fullAuthorityUri); | ||
if (!!kcsb.aadUserId && !!kcsb.password) { | ||
this.authMethod = AuthenticationMethod.username; | ||
this.clientId = "db662dc1-0cfe-4e1c-a843-19a68e65be58"; | ||
this.username = kcsb.aadUserId; | ||
this.password = kcsb.password; | ||
} else if (!!kcsb.applicationClientId && !!kcsb.applicationKey) { | ||
this.authMethod = AuthenticationMethod.appKey; | ||
this.clientId = kcsb.applicationClientId; | ||
this.clientSecret = kcsb.applicationKey; | ||
} else if (!!kcsb.applicationClientId && | ||
this.method = { | ||
authMethod: AuthenticationMethod.username, | ||
clientId: "db662dc1-0cfe-4e1c-a843-19a68e65be58", | ||
username: kcsb.aadUserId, | ||
password: kcsb.password, | ||
}; | ||
} | ||
else if (!!kcsb.applicationClientId && !!kcsb.applicationKey) { | ||
this.method = { | ||
authMethod: AuthenticationMethod.appKey, | ||
clientId: kcsb.applicationClientId, | ||
clientSecret: kcsb.applicationKey, | ||
}; | ||
} | ||
else if (!!kcsb.applicationClientId && | ||
!!kcsb.applicationCertificate && !!kcsb.applicationCertificateThumbprint) { | ||
this.authMethod = AuthenticationMethod.appCertificate; | ||
this.clientId = kcsb.applicationClientId; | ||
this.certificate = kcsb.applicationCertificate; | ||
this.thumbprint = kcsb.applicationCertificateThumbprint; | ||
} else if (kcsb.managedIdentity) { | ||
this.authMethod = AuthenticationMethod.managedIdentities; | ||
this.msiEndpoint = kcsb.msiEndpoint; | ||
this.msiSecret = kcsb.msiSecret; | ||
this.msiClientId = kcsb.msiClientId; | ||
} else if (kcsb.azLoginIdentity) { | ||
this.authMethod = AuthenticationMethod.azLogin; | ||
} else if (kcsb.accessToken) { | ||
this.authMethod = AuthenticationMethod.accessToken; | ||
this.accessToken = kcsb.accessToken; | ||
} else { | ||
this.authMethod = AuthenticationMethod.deviceLogin; | ||
this.clientId = "db662dc1-0cfe-4e1c-a843-19a68e65be58"; | ||
this.authCallback = kcsb.AuthorizationCallback; | ||
this.method = { | ||
authMethod: AuthenticationMethod.appCertificate, | ||
clientId: kcsb.applicationClientId, | ||
certificate: kcsb.applicationCertificate, | ||
thumbprint: kcsb.applicationCertificateThumbprint | ||
}; | ||
} | ||
else if (kcsb.managedIdentity) { | ||
this.method = { | ||
authMethod: AuthenticationMethod.managedIdentities, | ||
msiEndpoint: kcsb.msiEndpoint, | ||
msiSecret: kcsb.msiSecret, | ||
msiClientId: kcsb.msiClientId | ||
}; | ||
} | ||
else if (kcsb.azLoginIdentity) { | ||
this.method = { authMethod: AuthenticationMethod.azLogin }; | ||
} | ||
else if (kcsb.accessToken) { | ||
this.method = { | ||
authMethod: AuthenticationMethod.accessToken, | ||
accessToken: kcsb.accessToken | ||
}; | ||
} | ||
else { | ||
this.method = { | ||
authMethod: AuthenticationMethod.deviceLogin, | ||
clientId: "db662dc1-0cfe-4e1c-a843-19a68e65be58", | ||
authCallback: kcsb.AuthorizationCallback | ||
}; | ||
} | ||
} | ||
_getAuthHeader() { | ||
@@ -80,3 +99,4 @@ return new Promise((resolve, reject) => { | ||
reject(error); | ||
} else { | ||
} | ||
else { | ||
resolve(authHeader); | ||
@@ -87,72 +107,64 @@ } | ||
} | ||
_getAuthHeaderWithCallback(cb) { | ||
let resource = this.kustoCluster; | ||
let formatHeader = ({ tokenType, accessToken }) => `${tokenType} ${accessToken}`; | ||
switch (this.authMethod) { | ||
const resource = this.kustoCluster; | ||
const formatHeader = ({ tokenType, accessToken }) => `${tokenType} ${accessToken}`; | ||
switch (this.method.authMethod) { | ||
case AuthenticationMethod.username: | ||
return this.adalContext.acquireTokenWithUsernamePassword( | ||
resource, this.username, this.password, this.clientId, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
} | ||
); | ||
return this.adalContext.acquireTokenWithUsernamePassword(resource, this.method.username, this.method.password, this.method.clientId, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
}); | ||
case AuthenticationMethod.appKey: | ||
return this.adalContext.acquireTokenWithClientCredentials( | ||
resource, this.clientId, this.clientSecret, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
} | ||
); | ||
return this.adalContext.acquireTokenWithClientCredentials(resource, this.method.clientId, this.method.clientSecret, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
}); | ||
case AuthenticationMethod.appCertificate: | ||
return this.adalContext.acquireTokenWithClientCertificate( | ||
resource, this.clientId, this.certificate, this.thumbprint, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
} | ||
); | ||
return this.adalContext.acquireTokenWithClientCertificate(resource, this.method.clientId, this.method.certificate, this.method.thumbprint, (err, tokenResponse) => { | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
}); | ||
case AuthenticationMethod.deviceLogin: | ||
return this.adalContext.acquireUserCode(resource, this.clientId, null, (err, tokenResponse) => { | ||
return this.adalContext.acquireUserCode(resource, this.method.clientId, "", (err, tokenResponse) => { | ||
this.method = this.method; | ||
if (err) { | ||
return cb(err); | ||
} else { | ||
if (this.authCallback) { | ||
this.authCallback(tokenResponse); | ||
} else { | ||
} | ||
else { | ||
if (this.method.authCallback) { | ||
this.method.authCallback(tokenResponse); | ||
} | ||
else { | ||
// tslint:disable-next-line:no-console | ||
console.log(tokenResponse.message); | ||
} | ||
return this.adalContext.acquireTokenWithDeviceCode(resource, this.clientId, tokenResponse, (err, tokenResponse) => { | ||
if (err) { | ||
return cb(err); | ||
return this.adalContext.acquireTokenWithDeviceCode(resource, this.method.clientId, tokenResponse, (innerError, innerResponse) => { | ||
if (innerError) { | ||
return cb(innerError); | ||
} | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
return cb(innerError, innerResponse && formatHeader(innerResponse)); | ||
}); | ||
} | ||
}); | ||
case AuthenticationMethod.managedIdentities: | ||
return acquireManagedIdentityToken( | ||
resource, this.msiEndpoint, this.msiClientId, this.msiSecret, (err, tokenResponse) => { | ||
if (err) { | ||
return cb(err); | ||
} | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
return managedIdentitiesClient_1.default(resource, this.method.msiEndpoint, this.method.msiClientId, this.method.msiSecret, (err, tokenResponse) => { | ||
if (err) { | ||
return cb(err); | ||
} | ||
); | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
}); | ||
case AuthenticationMethod.azLogin: | ||
return azLoginIndentityToken(resource, (err, tokenResponse) => { | ||
if(err) { | ||
return azLoginIdentityClient_1.default(resource, (err, tokenResponse) => { | ||
if (err) { | ||
return cb(err); | ||
} | ||
return cb(err, tokenResponse && formatHeader(tokenResponse)); | ||
}); | ||
case AuthenticationMethod.accessToken: | ||
return cb(undefined, `Bearer ${this.accessToken}`); | ||
return cb(undefined, `Bearer ${this.method.accessToken}`); | ||
default: | ||
return cb("Couldn't Authenticate, something went wrong trying to choose authentication method"); | ||
} | ||
} | ||
}; | ||
} | ||
exports.AadHelper = AadHelper; | ||
; | ||
exports.default = AadHelper; | ||
//# sourceMappingURL=security.js.map |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
231302
524.47%42
250%2131
172.86%8
166.67%1
Infinity%