azure-kusto-node/azure-kusto-data
AsafMah 2c2b604d7a
Properly fix security issue and restore lockfiles to version 1 (#165)
2022-02-13 12:31:51 +02:00
..
source Fix mappings - Added all mapping types, and send them correctly (#154) 2022-02-13 11:39:45 +02:00
test Added support for custom parsers (#161) 2022-02-10 08:57:18 +02:00
.npmignore Security update, Faster tests and improvements (#160) 2022-01-25 12:10:52 +02:00
README.md Fix the link formatting in option 3 (#117) 2021-04-26 16:20:27 +03:00
example.js Revert "Added support for custom parsers" 2022-01-25 13:12:52 +02:00
index.ts Moved the project to typescript 2020-12-16 16:39:25 +02:00
package-lock.json Properly fix security issue and restore lockfiles to version 1 (#165) 2022-02-13 12:31:51 +02:00
package.json Properly fix security issue and restore lockfiles to version 1 (#165) 2022-02-13 12:31:51 +02:00
tsconfig.json Node typescript fix (#116) 2021-02-21 15:46:10 +02:00
tslint.json Fixed lints and deprecated functions (#162) 2022-01-27 13:02:04 +02:00

README.md

Microsoft Azure Kusto Data Library for Node

Installation

npm install azure-kusto-data

Quick Start

const KustoClient = require("azure-kusto-data").Client;
const KustoConnectionStringBuilder = require("azure-kusto-data").KustoConnectionStringBuilder;

const kcsb = KustoConnectionStringBuilder.withAadApplicationKeyAuthentication(`https://${clusterName}.kusto.windows.net`,'appid','appkey','authorityId');
const client = new KustoClient(kcsb);

const results = await client.execute("db", "TableName | limit 1");
console.log(JSON.stringify(results));
console.log(results.primaryResults[0].toString());

Authentication

There are several authentication methods

AAD application

There are three ways to authenticate using AAD application:

Option 1: Authenticating using AAD application id and corresponding key.

const kcsb = KustoConnectionStringBuilder.withAadApplicationKeyAuthentication(`https://${clusterName}.kusto.windows.net`,'appid','appkey','authorityId');

Option 2: Authenticating using AAD application id and corresponding certificate.

const kcsb = KustoConnectionStringBuilder.withAadApplicationCertificateAuthentication(`https://${clusterName}.kusto.windows.net`, 'appid', 'certificate', 'thumbprint', 'authorityId');

Option 3: Authenticating using AAD Managed Identities.

const kcsb = KustoConnectionStringBuilder.withAadManagedIdentities(`https://${clusterName}.kusto.windows.net`, '(Optional)msiEndpoint', '(Optional)clientId');

Username/Password

KustoConnectionStringBuilder.withAadUserPasswordAuthentication(`https://${clusterName}.kusto.windows.net`,'username','password');

Authority is optional when it can inferred from the domain ('user@microsoft.com' would make the authority 'microsoft.com'). In any case it is possible to pass the authority id

KustoConnectionStringBuilder.withAadUserPasswordAuthentication(`https://${clusterName}.kusto.windows.net`,'username','password','authorityId');

Device

Using this method will write a token to the console, which can be used to authenticate at https://login.microsoftonline.com/common/oauth2/deviceauth and will allow temporary access.

<!>It is not meant for production purposes<!>

// will log the DEVICE token and url to use
KustoConnectionStringBuilder.withAadDeviceAuthentication(`https://${clusterName}.kusto.windows.net`, authId);

// in case you want to do your own thing with the response, you can pass a callback
// NOTICE: code will still block until device is authenticated
KustoConnectionStringBuilder.withAadDeviceAuthentication(`https://${clusterName}.kusto.windows.net`, authId, (tokenResponse) => {
    // your code, for example copy to clipboard or open url in browser
    console.log("Open " + tokenResponse.verificationUrl + " and use " + tokenResponse.userCode + " code to authorize.");
});

Usage

Query language docs can be found at https://docs.microsoft.com/en-us/azure/data-explorer/write-queries#overview-of-the-query-language

Advanced Usage

ClientRequestProperties

For more fine grained control, we expose ClientRequestProperties.

const ClientRequestProperties = require("azure-kusto-data").ClientRequestProperties;
const Client = require("azure-kusto-data").Client;

const client = new Client("http://cluster.region.kusto.windows.net");
const query = `
declare query_parameters(amount:long);
T | where amountColumn == amount
`;
const clientRequestProps = new ClientRequestProperties();
clientRequestProps.setOption("servertimeout", 1000 * 60);
clientRequestProps.setParameter("amount", 100);
const results = await client.executeQuery("db", query, clientRequestProps);

A full list of those properties can be found at https://docs.microsoft.com/en-us/azure/kusto/api/netfx/request-properties