azure-kusto-data 4.0.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist-esm/src/client.js +227 -0
- package/dist-esm/src/clientDetails.js +79 -0
- package/{source → dist-esm/src}/clientRequestProperties.js +13 -0
- package/dist-esm/src/cloudSettings.js +60 -0
- package/dist-esm/src/connectionBuilder.browser.js +72 -0
- package/dist-esm/src/connectionBuilder.js +128 -0
- package/dist-esm/src/connectionBuilderBase.js +138 -0
- package/{source → dist-esm/src}/errors.js +0 -0
- package/{index.js → dist-esm/src/index.js} +8 -5
- package/{source → dist-esm/src}/kustoTrustedEndpoints.js +0 -0
- package/{source → dist-esm/src}/models.js +8 -6
- package/{source → dist-esm/src}/response.js +0 -0
- package/{source → dist-esm/src}/security.js +17 -31
- package/dist-esm/src/timeUtils.js +28 -0
- package/dist-esm/src/tokenProvider.js +252 -0
- package/{source → dist-esm/src}/typeUtilts.js +0 -0
- package/{source → dist-esm/src}/utils.js +0 -0
- package/dist-esm/src/version.js +8 -0
- package/{source → dist-esm/src}/wellKnownKustoEndpoints.json +0 -0
- package/dist-esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -15
- package/{source → types/src}/client.d.ts +1 -0
- package/types/src/clientDetails.d.ts +20 -0
- package/{source → types/src}/clientRequestProperties.d.ts +3 -0
- package/{source → types/src}/cloudSettings.d.ts +1 -0
- package/types/src/connectionBuilder.browser.d.ts +18 -0
- package/types/src/connectionBuilder.d.ts +24 -0
- package/types/src/connectionBuilderBase.d.ts +56 -0
- package/{source → types/src}/errors.d.ts +1 -0
- package/types/src/index.d.ts +10 -0
- package/{source → types/src}/kustoTrustedEndpoints.d.ts +1 -0
- package/{source → types/src}/models.d.ts +7 -1
- package/{source → types/src}/response.d.ts +1 -0
- package/{source → types/src}/security.d.ts +3 -3
- package/types/src/timeUtils.d.ts +3 -0
- package/{source → types/src}/tokenProvider.d.ts +36 -60
- package/{source → types/src}/typeUtilts.d.ts +1 -0
- package/{source → types/src}/utils.d.ts +1 -0
- package/types/src/version.d.ts +2 -0
- package/example.js +0 -49
- package/index.d.ts +0 -5
- package/source/client.js +0 -241
- package/source/cloudSettings.js +0 -73
- package/source/connectionBuilder.d.ts +0 -45
- package/source/connectionBuilder.js +0 -231
- package/source/tokenProvider.js +0 -350
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.KustoConnectionStringBuilderBase = exports.KeywordMapping = void 0;
|
|
6
|
+
const clientDetails_1 = require("./clientDetails");
|
|
7
|
+
exports.KeywordMapping = Object.freeze({
|
|
8
|
+
dataSource: {
|
|
9
|
+
mappedTo: "Data Source",
|
|
10
|
+
validNames: ["data source", "addr", "address", "network address", "server"],
|
|
11
|
+
},
|
|
12
|
+
aadFederatedSecurity: {
|
|
13
|
+
mappedTo: "AAD Federated Security",
|
|
14
|
+
validNames: ["aad federated security", "federated security", "federated", "fed", "aadfed"],
|
|
15
|
+
isBool: true,
|
|
16
|
+
},
|
|
17
|
+
initialCatalog: {
|
|
18
|
+
mappedTo: "Initial Catalog",
|
|
19
|
+
validNames: ["initial catalog", "database"],
|
|
20
|
+
},
|
|
21
|
+
aadUserId: {
|
|
22
|
+
mappedTo: "AAD User ID",
|
|
23
|
+
validNames: ["aad user id"],
|
|
24
|
+
},
|
|
25
|
+
password: {
|
|
26
|
+
mappedTo: "Password",
|
|
27
|
+
validNames: ["password", "pwd"],
|
|
28
|
+
isSecret: true,
|
|
29
|
+
},
|
|
30
|
+
applicationClientId: {
|
|
31
|
+
mappedTo: "Application Client Id",
|
|
32
|
+
validNames: ["application client id", "appclientid"],
|
|
33
|
+
},
|
|
34
|
+
applicationKey: {
|
|
35
|
+
mappedTo: "Application Key",
|
|
36
|
+
validNames: ["application key", "appkey"],
|
|
37
|
+
isSecret: true,
|
|
38
|
+
},
|
|
39
|
+
applicationCertificatePrivateKey: {
|
|
40
|
+
mappedTo: "Application Certificate PrivateKey",
|
|
41
|
+
validNames: ["Application Certificate PrivateKey"],
|
|
42
|
+
isSecret: true,
|
|
43
|
+
},
|
|
44
|
+
applicationCertificateSendX5c: {
|
|
45
|
+
mappedTo: "Application Certificate x5c",
|
|
46
|
+
validNames: ["application certificate x5c", "Application Certificate Send Public Certificate", "Application Certificate SendX5c", "SendX5c"],
|
|
47
|
+
isBool: true,
|
|
48
|
+
},
|
|
49
|
+
authorityId: {
|
|
50
|
+
mappedTo: "Authority Id",
|
|
51
|
+
validNames: ["authority id", "authorityid", "authority", "tenantid", "tenant", "tid"],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const getPropName = (key) => {
|
|
55
|
+
const _key = key.trim().toLowerCase();
|
|
56
|
+
for (const keyword of Object.keys(exports.KeywordMapping)) {
|
|
57
|
+
const k = exports.KeywordMapping[keyword];
|
|
58
|
+
if (!k) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (k.validNames.map((n) => n.trim().toLowerCase()).indexOf(_key) >= 0) {
|
|
62
|
+
return [keyword, k];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error("Failed to get prop: " + key);
|
|
66
|
+
};
|
|
67
|
+
class KustoConnectionStringBuilderBase {
|
|
68
|
+
constructor(connectionString) {
|
|
69
|
+
var _a;
|
|
70
|
+
this.authorityId = "organizations";
|
|
71
|
+
this.applicationNameForTracing = null;
|
|
72
|
+
this.userNameForTracing = null;
|
|
73
|
+
if (connectionString.trim().length === 0)
|
|
74
|
+
throw new Error("Missing connection string");
|
|
75
|
+
if (connectionString.endsWith("/") || connectionString.endsWith("\\")) {
|
|
76
|
+
connectionString = connectionString.slice(0, -1);
|
|
77
|
+
}
|
|
78
|
+
if (!!connectionString && connectionString.split(";")[0].indexOf("=") === -1) {
|
|
79
|
+
connectionString = "Data Source=" + connectionString;
|
|
80
|
+
}
|
|
81
|
+
const params = connectionString.split(";");
|
|
82
|
+
for (const item of params) {
|
|
83
|
+
const kvp = item.split("=");
|
|
84
|
+
const [mappingTypeName, mappingType] = getPropName(kvp[0]);
|
|
85
|
+
if (mappingType.isBool) {
|
|
86
|
+
this[mappingTypeName] = kvp[1].trim().toLowerCase() === "true";
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this[mappingTypeName] = (_a = kvp[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!this.initialCatalog) {
|
|
93
|
+
this.initialCatalog = KustoConnectionStringBuilderBase.DefaultDatabaseName;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
clientDetails() {
|
|
97
|
+
return new clientDetails_1.ClientDetails(this.applicationNameForTracing, this.userNameForTracing);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Sets the connector details for tracing purposes.
|
|
101
|
+
*
|
|
102
|
+
* @param name The name of the connector
|
|
103
|
+
* @param version The version of the connector
|
|
104
|
+
* @param appName? The name of the containing application
|
|
105
|
+
* @param appVersion?? The version of the containing application
|
|
106
|
+
* @param sendUser Whether to send the username
|
|
107
|
+
* @param overrideUser?? Override the username ( if sendUser is True )
|
|
108
|
+
* @param additionalFields? Additional fields to add to the header
|
|
109
|
+
*/
|
|
110
|
+
setConnectorDetails(name, version, appName, appVersion, sendUser = false, overrideUser, additionalFields) {
|
|
111
|
+
const clientDetails = clientDetails_1.ClientDetails.setConnectorDetails(name, version, appName, appVersion, sendUser, overrideUser, additionalFields);
|
|
112
|
+
this.applicationNameForTracing = clientDetails.applicationNameForTracing;
|
|
113
|
+
this.userNameForTracing = clientDetails.userNameForTracing;
|
|
114
|
+
}
|
|
115
|
+
toString(removeSecrets = true) {
|
|
116
|
+
return Object.entries(exports.KeywordMapping)
|
|
117
|
+
.map(([key, mappingType]) => {
|
|
118
|
+
const value = this[key];
|
|
119
|
+
if (!mappingType || value === undefined) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
if (mappingType.isSecret && removeSecrets) {
|
|
123
|
+
return `${mappingType.mappedTo}=${KustoConnectionStringBuilderBase.SecretReplacement}`;
|
|
124
|
+
}
|
|
125
|
+
return `${mappingType.mappedTo}=${value.toString()}`;
|
|
126
|
+
})
|
|
127
|
+
.filter((x) => x !== "")
|
|
128
|
+
.join(";");
|
|
129
|
+
}
|
|
130
|
+
static fromExisting(other) {
|
|
131
|
+
return Object.assign({}, other);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.KustoConnectionStringBuilderBase = KustoConnectionStringBuilderBase;
|
|
135
|
+
KustoConnectionStringBuilderBase.DefaultDatabaseName = "NetDefaultDB";
|
|
136
|
+
KustoConnectionStringBuilderBase.SecretReplacement = "****";
|
|
137
|
+
exports.default = KustoConnectionStringBuilderBase;
|
|
138
|
+
//# sourceMappingURL=connectionBuilderBase.js.map
|
|
File without changes
|
|
@@ -28,13 +28,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.KustoDataErrors = exports.KustoConnectionStringBuilder = exports.ClientRequestProperties = exports.Client = void 0;
|
|
32
|
-
const client_1 = __importDefault(require("./
|
|
31
|
+
exports.TimeUtils = exports.KustoDataErrors = exports.KustoConnectionStringBuilder = exports.ClientRequestProperties = exports.Client = void 0;
|
|
32
|
+
const client_1 = __importDefault(require("./client"));
|
|
33
33
|
exports.Client = client_1.default;
|
|
34
|
-
const clientRequestProperties_1 = __importDefault(require("./
|
|
34
|
+
const clientRequestProperties_1 = __importDefault(require("./clientRequestProperties"));
|
|
35
35
|
exports.ClientRequestProperties = clientRequestProperties_1.default;
|
|
36
|
-
const connectionBuilder_1 = __importDefault(require("./
|
|
36
|
+
const connectionBuilder_1 = __importDefault(require("./connectionBuilder"));
|
|
37
37
|
exports.KustoConnectionStringBuilder = connectionBuilder_1.default;
|
|
38
|
-
const KustoDataErrors = __importStar(require("./
|
|
38
|
+
const KustoDataErrors = __importStar(require("./errors"));
|
|
39
39
|
exports.KustoDataErrors = KustoDataErrors;
|
|
40
|
+
const timeUtils_1 = require("./timeUtils");
|
|
41
|
+
const TimeUtils = { toMilliseconds: timeUtils_1.toMilliseconds };
|
|
42
|
+
exports.TimeUtils = TimeUtils;
|
|
40
43
|
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
5
|
exports.KustoResultTable = exports.KustoResultColumn = exports.KustoResultRow = exports.WellKnownDataSet = void 0;
|
|
9
|
-
const
|
|
6
|
+
const timeUtils_1 = require("./timeUtils");
|
|
10
7
|
var WellKnownDataSet;
|
|
11
8
|
(function (WellKnownDataSet) {
|
|
12
9
|
WellKnownDataSet["PrimaryResult"] = "PrimaryResult";
|
|
@@ -14,8 +11,13 @@ var WellKnownDataSet;
|
|
|
14
11
|
WellKnownDataSet["TableOfContents"] = "TableOfContents";
|
|
15
12
|
WellKnownDataSet["QueryProperties"] = "QueryProperties";
|
|
16
13
|
})(WellKnownDataSet = exports.WellKnownDataSet || (exports.WellKnownDataSet = {}));
|
|
17
|
-
const defaultDatetimeParser = (t) =>
|
|
18
|
-
const defaultTimespanParser =
|
|
14
|
+
const defaultDatetimeParser = (t) => new Date(t);
|
|
15
|
+
const defaultTimespanParser = timeUtils_1.parseKustoTimestampToMillis;
|
|
16
|
+
/**
|
|
17
|
+
* Represents a Kusto result row.
|
|
18
|
+
* Use `dateTimeParser` and `timeSpanParser` to customize the parsing of the `datetime` and `timespan` types.
|
|
19
|
+
* By default, `datetime` is parsed to a `Date` object and `timespan` is parsed to a number representing the number of milliseconds, as returned by subtracting two `Date` objects.
|
|
20
|
+
*/
|
|
19
21
|
class KustoResultRow {
|
|
20
22
|
constructor(columns, row, dateTimeParser = defaultDatetimeParser, timeSpanParser = defaultTimespanParser) {
|
|
21
23
|
this.columns = columns.sort((a, b) => a.ordinal - b.ordinal);
|
|
File without changes
|
|
@@ -22,20 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.AadHelper = void 0;
|
|
36
|
-
require("./tokenProvider");
|
|
37
27
|
const TokenProvider = __importStar(require("./tokenProvider"));
|
|
38
28
|
const errors_1 = require("./errors");
|
|
29
|
+
const tokenProvider_1 = require("./tokenProvider");
|
|
39
30
|
class AadHelper {
|
|
40
31
|
constructor(kcsb) {
|
|
41
32
|
if (!kcsb.dataSource) {
|
|
@@ -47,8 +38,8 @@ class AadHelper {
|
|
|
47
38
|
else if (!!kcsb.applicationClientId && !!kcsb.applicationKey) {
|
|
48
39
|
this.tokenProvider = new TokenProvider.ApplicationKeyTokenProvider(kcsb.dataSource, kcsb.applicationClientId, kcsb.applicationKey, kcsb.authorityId);
|
|
49
40
|
}
|
|
50
|
-
else if (!!kcsb.applicationClientId && !!kcsb.
|
|
51
|
-
this.tokenProvider = new TokenProvider.ApplicationCertificateTokenProvider(kcsb.dataSource, kcsb.applicationClientId, kcsb.
|
|
41
|
+
else if (!!kcsb.applicationClientId && !!kcsb.applicationCertificatePrivateKey) {
|
|
42
|
+
this.tokenProvider = new TokenProvider.ApplicationCertificateTokenProvider(kcsb.dataSource, kcsb.applicationClientId, kcsb.applicationCertificatePrivateKey, kcsb.applicationCertificateSendX5c, kcsb.authorityId);
|
|
52
43
|
}
|
|
53
44
|
else if (kcsb.useManagedIdentityAuth) {
|
|
54
45
|
this.tokenProvider = new TokenProvider.MsiTokenProvider(kcsb.dataSource, kcsb.msiClientId, kcsb.authorityId, kcsb.timeoutMs);
|
|
@@ -57,34 +48,29 @@ class AadHelper {
|
|
|
57
48
|
this.tokenProvider = new TokenProvider.AzCliTokenProvider(kcsb.dataSource, kcsb.authorityId, kcsb.timeoutMs);
|
|
58
49
|
}
|
|
59
50
|
else if (kcsb.accessToken) {
|
|
60
|
-
this.tokenProvider = new
|
|
51
|
+
this.tokenProvider = new tokenProvider_1.BasicTokenProvider(kcsb.dataSource, kcsb.accessToken);
|
|
61
52
|
}
|
|
62
53
|
else if (kcsb.useUserPromptAuth) {
|
|
63
|
-
this.tokenProvider = new
|
|
54
|
+
this.tokenProvider = new tokenProvider_1.UserPromptProvider(kcsb.dataSource, kcsb.interactiveCredentialOptions);
|
|
64
55
|
}
|
|
65
56
|
else if (kcsb.tokenProvider) {
|
|
66
|
-
this.tokenProvider = new
|
|
57
|
+
this.tokenProvider = new tokenProvider_1.CallbackTokenProvider(kcsb.dataSource, kcsb.tokenProvider);
|
|
67
58
|
}
|
|
68
59
|
else if (kcsb.useDeviceCodeAuth) {
|
|
69
|
-
if (kcsb.deviceCodeCallback === undefined) {
|
|
70
|
-
throw new errors_1.KustoAuthenticationError("Device code authentication requires a callback function", undefined, TokenProvider.DeviceLoginTokenProvider.name, {});
|
|
71
|
-
}
|
|
72
60
|
this.tokenProvider = new TokenProvider.DeviceLoginTokenProvider(kcsb.dataSource, kcsb.deviceCodeCallback, kcsb.authorityId);
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
getAuthHeader() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
});
|
|
63
|
+
async getAuthHeader() {
|
|
64
|
+
if (!this.tokenProvider) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const token = await this.tokenProvider.acquireToken();
|
|
69
|
+
return `${token.tokenType} ${token.accessToken}`;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
throw new errors_1.KustoAuthenticationError(e instanceof Error ? e.message : `${e}`, e instanceof Error ? e : undefined, this.tokenProvider.constructor.name, this.tokenProvider.context());
|
|
73
|
+
}
|
|
88
74
|
}
|
|
89
75
|
}
|
|
90
76
|
exports.AadHelper = AadHelper;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.parseKustoTimestampToMillis = exports.toMilliseconds = void 0;
|
|
6
|
+
function toMilliseconds(hours, minutes, seconds) {
|
|
7
|
+
return (hours * 60 * 60 + minutes * 60 + seconds) * 1000;
|
|
8
|
+
}
|
|
9
|
+
exports.toMilliseconds = toMilliseconds;
|
|
10
|
+
// Format: [+|-]d.hh:mm:ss[.fffffff]
|
|
11
|
+
const TimespanRegex = /^(-?)(?:(\d+).)?(\d{2}):(\d{2}):(\d{2}(\.\d+)?$)/;
|
|
12
|
+
function parseKustoTimestampToMillis(t) {
|
|
13
|
+
if (t == null) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const match = TimespanRegex.exec(t);
|
|
17
|
+
if (match) {
|
|
18
|
+
const sign = match[1] === "-" ? -1 : 1;
|
|
19
|
+
const days = parseInt(match[2] || "0", 10);
|
|
20
|
+
const hours = parseInt(match[3], 10);
|
|
21
|
+
const minutes = parseInt(match[4], 10);
|
|
22
|
+
const seconds = parseFloat(match[5]);
|
|
23
|
+
return sign * 1000 * (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds);
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Timespan value '${t}' cannot be decoded`);
|
|
26
|
+
}
|
|
27
|
+
exports.parseKustoTimestampToMillis = parseKustoTimestampToMillis;
|
|
28
|
+
//# sourceMappingURL=timeUtils.js.map
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationKeyTokenProvider = exports.ApplicationCertificateTokenProvider = exports.DeviceLoginTokenProvider = exports.UserPassTokenProvider = exports.AzCliTokenProvider = exports.MsiTokenProvider = exports.UserPromptProvider = exports.AzureIdentityProvider = exports.CloudSettingsTokenProvider = exports.CallbackTokenProvider = exports.BasicTokenProvider = exports.TokenProviderBase = void 0;
|
|
4
|
+
// Copyright (c) Microsoft Corporation.
|
|
5
|
+
// Licensed under the MIT License.
|
|
6
|
+
const identity_1 = require("@azure/identity");
|
|
7
|
+
const identity_2 = require("@azure/identity");
|
|
8
|
+
const cloudSettings_1 = require("./cloudSettings");
|
|
9
|
+
const BEARER_TYPE = "Bearer";
|
|
10
|
+
/**
|
|
11
|
+
* This base class abstracts token acquisition for all implementations.
|
|
12
|
+
* The class is build for Lazy initialization, so that the first call, take on instantiation of 'heavy' long-lived class members
|
|
13
|
+
*/
|
|
14
|
+
class TokenProviderBase {
|
|
15
|
+
context() {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
constructor(kustoUri) {
|
|
19
|
+
this.kustoUri = kustoUri;
|
|
20
|
+
if (kustoUri != null) {
|
|
21
|
+
const suffix = (!this.kustoUri.endsWith("/") ? "/" : "") + ".default";
|
|
22
|
+
this.scopes = [kustoUri + suffix];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.TokenProviderBase = TokenProviderBase;
|
|
27
|
+
/**
|
|
28
|
+
* Basic Token Provider keeps and returns a token received on construction
|
|
29
|
+
*/
|
|
30
|
+
class BasicTokenProvider extends TokenProviderBase {
|
|
31
|
+
constructor(kustoUri, token) {
|
|
32
|
+
super(kustoUri);
|
|
33
|
+
this.token = token;
|
|
34
|
+
}
|
|
35
|
+
acquireToken() {
|
|
36
|
+
return Promise.resolve({
|
|
37
|
+
tokenType: BEARER_TYPE,
|
|
38
|
+
accessToken: this.token,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.BasicTokenProvider = BasicTokenProvider;
|
|
43
|
+
/**
|
|
44
|
+
* Callback Token Provider generates a token based on a callback function provided by the caller
|
|
45
|
+
*/
|
|
46
|
+
class CallbackTokenProvider extends TokenProviderBase {
|
|
47
|
+
constructor(kustoUri, callback) {
|
|
48
|
+
super(kustoUri);
|
|
49
|
+
this.callback = callback;
|
|
50
|
+
}
|
|
51
|
+
async acquireToken() {
|
|
52
|
+
const token = await this.callback();
|
|
53
|
+
return { tokenType: BEARER_TYPE, accessToken: token };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.CallbackTokenProvider = CallbackTokenProvider;
|
|
57
|
+
/**
|
|
58
|
+
* Token providers that require cloud settings to be configured - msal and azure identity
|
|
59
|
+
*/
|
|
60
|
+
class CloudSettingsTokenProvider extends TokenProviderBase {
|
|
61
|
+
additionalCloudSettingsInit() { }
|
|
62
|
+
constructor(kustoUri) {
|
|
63
|
+
super(kustoUri);
|
|
64
|
+
this.initialized = false;
|
|
65
|
+
}
|
|
66
|
+
async acquireToken() {
|
|
67
|
+
if (!this.initialized) {
|
|
68
|
+
if (this.cloudInfo == null) {
|
|
69
|
+
this.cloudInfo = await cloudSettings_1.CloudSettings.getInstance().getCloudInfoForCluster(this.kustoUri);
|
|
70
|
+
let resourceUri = this.cloudInfo.KustoServiceResourceId;
|
|
71
|
+
if (this.cloudInfo.LoginMfaRequired) {
|
|
72
|
+
resourceUri = resourceUri.replace(".kusto.", ".kustomfa.");
|
|
73
|
+
}
|
|
74
|
+
this.scopes = [resourceUri + "/.default"];
|
|
75
|
+
this.additionalCloudSettingsInit();
|
|
76
|
+
this.initClient();
|
|
77
|
+
}
|
|
78
|
+
this.initialized = true;
|
|
79
|
+
}
|
|
80
|
+
const token = await this.acquireTokenWithCloudSettings();
|
|
81
|
+
if (token) {
|
|
82
|
+
return { tokenType: token.tokenType, accessToken: token.accessToken };
|
|
83
|
+
}
|
|
84
|
+
throw new Error("Failed to get token from msal");
|
|
85
|
+
}
|
|
86
|
+
context() {
|
|
87
|
+
return Object.assign(Object.assign({}, super.context()), { kustoUri: this.kustoUri });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.CloudSettingsTokenProvider = CloudSettingsTokenProvider;
|
|
91
|
+
class AzureIdentityProvider extends CloudSettingsTokenProvider {
|
|
92
|
+
constructor(kustoUri, authorityId, timeoutMs) {
|
|
93
|
+
super(kustoUri);
|
|
94
|
+
this.authorityId = authorityId;
|
|
95
|
+
this.timeoutMs = timeoutMs;
|
|
96
|
+
}
|
|
97
|
+
initClient() {
|
|
98
|
+
this.credential = this.getCredential();
|
|
99
|
+
}
|
|
100
|
+
async acquireTokenWithCloudSettings() {
|
|
101
|
+
const response = await this.credential.getToken(this.scopes, {
|
|
102
|
+
requestOptions: {
|
|
103
|
+
timeout: this.timeoutMs,
|
|
104
|
+
},
|
|
105
|
+
tenantId: this.authorityId,
|
|
106
|
+
});
|
|
107
|
+
if (response === null) {
|
|
108
|
+
throw new Error("Failed to get token from msal");
|
|
109
|
+
}
|
|
110
|
+
return { tokenType: BEARER_TYPE, accessToken: response.token };
|
|
111
|
+
}
|
|
112
|
+
context() {
|
|
113
|
+
let base = Object.assign(Object.assign({}, super.context()), { kustoUri: this.kustoUri, authorityId: this.authorityId });
|
|
114
|
+
if (this.timeoutMs) {
|
|
115
|
+
base = Object.assign(Object.assign({}, base), { timeoutMs: this.timeoutMs });
|
|
116
|
+
}
|
|
117
|
+
return base;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.AzureIdentityProvider = AzureIdentityProvider;
|
|
121
|
+
/**
|
|
122
|
+
* UserPromptProvider will pop up a login prompt to acquire a token.
|
|
123
|
+
*/
|
|
124
|
+
class UserPromptProvider extends AzureIdentityProvider {
|
|
125
|
+
constructor(kustoUri, interactiveCredentialOptions, timeoutMs) {
|
|
126
|
+
super(kustoUri, interactiveCredentialOptions === null || interactiveCredentialOptions === void 0 ? void 0 : interactiveCredentialOptions.tenantId, timeoutMs);
|
|
127
|
+
this.interactiveCredentialOptions = interactiveCredentialOptions;
|
|
128
|
+
// The default port is 80, which can lead to permission errors, so we'll choose another port
|
|
129
|
+
this.MinPort = 20000;
|
|
130
|
+
this.MaxPort = 65536;
|
|
131
|
+
}
|
|
132
|
+
getCredential() {
|
|
133
|
+
var _a, _b, _c, _d;
|
|
134
|
+
return new identity_2.InteractiveBrowserCredential(Object.assign(Object.assign({}, this.interactiveCredentialOptions), { tenantId: this.authorityId, clientId: (_b = (_a = this.interactiveCredentialOptions) === null || _a === void 0 ? void 0 : _a.clientId) !== null && _b !== void 0 ? _b : this.cloudInfo.KustoClientAppId, redirectUri: (_d = (_c = this.interactiveCredentialOptions) === null || _c === void 0 ? void 0 : _c.redirectUri) !== null && _d !== void 0 ? _d : `http://localhost:${this.getRandomPortInRange()}/` }));
|
|
135
|
+
}
|
|
136
|
+
getRandomPortInRange() {
|
|
137
|
+
return Math.floor(Math.random() * (this.MaxPort - this.MinPort) + this.MinPort);
|
|
138
|
+
}
|
|
139
|
+
context() {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
let base = super.context();
|
|
142
|
+
if ((_a = this.interactiveCredentialOptions) === null || _a === void 0 ? void 0 : _a.loginHint) {
|
|
143
|
+
base = Object.assign(Object.assign({}, base), { loginHint: (_b = this.interactiveCredentialOptions) === null || _b === void 0 ? void 0 : _b.loginHint });
|
|
144
|
+
}
|
|
145
|
+
return base;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.UserPromptProvider = UserPromptProvider;
|
|
149
|
+
/**
|
|
150
|
+
* MSI Token Provider obtains a token from the MSI endpoint
|
|
151
|
+
* The args parameter is a dictionary conforming with the ManagedIdentityCredential initializer API arguments
|
|
152
|
+
*/
|
|
153
|
+
class MsiTokenProvider extends AzureIdentityProvider {
|
|
154
|
+
constructor(kustoUri, clientId, authorityId, timeoutMs) {
|
|
155
|
+
super(kustoUri, authorityId, timeoutMs);
|
|
156
|
+
this.clientId = clientId;
|
|
157
|
+
}
|
|
158
|
+
getCredential() {
|
|
159
|
+
return this.clientId ? new identity_1.ManagedIdentityCredential(this.clientId) : new identity_1.ManagedIdentityCredential();
|
|
160
|
+
}
|
|
161
|
+
context() {
|
|
162
|
+
return Object.assign(Object.assign({}, super.context()), { clientId: this.clientId });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.MsiTokenProvider = MsiTokenProvider;
|
|
166
|
+
/**
|
|
167
|
+
* AzCli Token Provider obtains a refresh token from the AzCli cache and uses it to authenticate with MSAL
|
|
168
|
+
*/
|
|
169
|
+
class AzCliTokenProvider extends AzureIdentityProvider {
|
|
170
|
+
getCredential() {
|
|
171
|
+
return new identity_1.AzureCliCredential();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.AzCliTokenProvider = AzCliTokenProvider;
|
|
175
|
+
/**
|
|
176
|
+
* Acquire a token from MSAL with username and password
|
|
177
|
+
*/
|
|
178
|
+
class UserPassTokenProvider extends AzureIdentityProvider {
|
|
179
|
+
constructor(kustoUri, userName, password, authorityId) {
|
|
180
|
+
super(kustoUri, authorityId, undefined);
|
|
181
|
+
this.userName = userName;
|
|
182
|
+
this.password = password;
|
|
183
|
+
}
|
|
184
|
+
getCredential() {
|
|
185
|
+
return new identity_1.UsernamePasswordCredential(this.authorityId, this.cloudInfo.KustoClientAppId, this.userName, this.password);
|
|
186
|
+
}
|
|
187
|
+
context() {
|
|
188
|
+
return Object.assign(Object.assign({}, super.context()), { userName: this.userName, homeAccountId: this.homeAccountId });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.UserPassTokenProvider = UserPassTokenProvider;
|
|
192
|
+
/**
|
|
193
|
+
* Acquire a token from Device Login flow
|
|
194
|
+
*/
|
|
195
|
+
class DeviceLoginTokenProvider extends AzureIdentityProvider {
|
|
196
|
+
constructor(kustoUri, deviceCodeCallback, authorityId) {
|
|
197
|
+
super(kustoUri, authorityId, undefined);
|
|
198
|
+
this.deviceCodeCallback = deviceCodeCallback;
|
|
199
|
+
}
|
|
200
|
+
getCredential() {
|
|
201
|
+
return new identity_1.DeviceCodeCredential({
|
|
202
|
+
tenantId: this.authorityId,
|
|
203
|
+
clientId: this.cloudInfo.KustoClientAppId,
|
|
204
|
+
userPromptCallback: this.deviceCodeCallback,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.DeviceLoginTokenProvider = DeviceLoginTokenProvider;
|
|
209
|
+
/**
|
|
210
|
+
* Acquire a token from MSAL using application certificate
|
|
211
|
+
* Passing the public certificate is optional and will result in Subject Name & Issuer Authentication
|
|
212
|
+
*/
|
|
213
|
+
class ApplicationCertificateTokenProvider extends AzureIdentityProvider {
|
|
214
|
+
constructor(kustoUri, appClientId, certPrivateKey, sendX5c, authorityId) {
|
|
215
|
+
super(kustoUri, authorityId);
|
|
216
|
+
this.appClientId = appClientId;
|
|
217
|
+
this.certPrivateKey = certPrivateKey;
|
|
218
|
+
this.sendX5c = sendX5c;
|
|
219
|
+
}
|
|
220
|
+
getCredential() {
|
|
221
|
+
return new identity_1.ClientCertificateCredential(this.authorityId, this.appClientId, {
|
|
222
|
+
certificate: this.certPrivateKey,
|
|
223
|
+
}, {
|
|
224
|
+
sendCertificateChain: this.sendX5c,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
context() {
|
|
228
|
+
return Object.assign(Object.assign({}, super.context()), { clientId: this.appClientId, sendX5c: this.sendX5c });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.ApplicationCertificateTokenProvider = ApplicationCertificateTokenProvider;
|
|
232
|
+
/**
|
|
233
|
+
* Acquire a token from MSAL with application id and Key
|
|
234
|
+
*/
|
|
235
|
+
class ApplicationKeyTokenProvider extends AzureIdentityProvider {
|
|
236
|
+
constructor(kustoUri, appClientId, appKey, authorityId) {
|
|
237
|
+
super(kustoUri, authorityId);
|
|
238
|
+
this.appClientId = appClientId;
|
|
239
|
+
this.appKey = appKey;
|
|
240
|
+
}
|
|
241
|
+
getCredential() {
|
|
242
|
+
return new identity_1.ClientSecretCredential(this.authorityId, // The tenant ID in Azure Active Directory
|
|
243
|
+
this.appClientId, // The app registration client Id in the AAD tenant
|
|
244
|
+
this.appKey // The app registration secret for the registered application
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
context() {
|
|
248
|
+
return Object.assign(Object.assign({}, super.context()), { clientId: this.appClientId });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.ApplicationKeyTokenProvider = ApplicationKeyTokenProvider;
|
|
252
|
+
//# sourceMappingURL=tokenProvider.js.map
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.SDK_VERSION = void 0;
|
|
6
|
+
// SDK_VERSION should be updated in all 3 package.json and lerna.json(by running lerna version)
|
|
7
|
+
exports.SDK_VERSION = "5.0.0";
|
|
8
|
+
//# sourceMappingURL=version.js.map
|
|
File without changes
|