New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

azure-kusto-data

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-kusto-data - npm Package Compare versions

Comparing version

to
0.3.0

source/managedIdentitiesClient.js

3

package.json
{
"name": "azure-kusto-data",
"version": "0.2.5",
"version": "0.3.0",
"description": "Azure Data Explorer Query SDK",

@@ -33,2 +33,3 @@ "main": "index.js",

"devDependencies": {
"eslint": "^6.0.1",
"mocha": "^5.2.0",

@@ -35,0 +36,0 @@ "sinon": "^7.2.3"

@@ -27,4 +27,4 @@ # Microsoft Azure Kusto Data Library for Node

### AAD appliction
There are two ways to authenticate using AAD application:
### AAD application
There are three ways to authenticate using AAD application:
Option 1: Authenticating using AAD application id and corresponding key.

@@ -41,3 +41,9 @@ ```javascript

Option 3: Authenticating using (AAD Managed Identities)[https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview].
```javascript
const kcsb = KustoConnectionStringBuilder.withAadManagedIdentities(`https://${clusterName}.kusto.windows.net`, '(Optional)msiEndpoint', '(Optional)clientId');
```
### Username/Password

@@ -84,6 +90,11 @@ ```javascript

let client = new Client("http://cluster.region.kusto.windows.net");
let clientRequestProps = new ClientRequestProperties();
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);
client.executeQuery("db","Table | count", (err, results) => { console.log(results);}, clientRequestProps);
clientRequestProps.setParameter("amount", 100);
client.executeQuery("db", query, (err, results) => { console.log(results); }, clientRequestProps);
```

@@ -90,0 +101,0 @@

module.exports = class ClientRequestProperties {
constructor() {
this._options = {};
constructor(options, parameters) {
this._options = options || {};
this._parameters = parameters || {};
}

@@ -17,2 +18,18 @@

setParameter(name, value) {
this._parameters[name] = value;
}
getParameter(name, defaultValue) {
if (!this._parameters || this._parameters[name] === undefined) {
return defaultValue;
}
return this._parameters[name];
}
clearParameters() {
this._parameters = {};
}
setTimeout(timeoutMillis) {

@@ -31,7 +48,13 @@ this.setOption("servertimeout", timeoutMillis);

toJson() {
if (!this._options || Object.keys(this._options).length == 0) {
return null;
let json = {};
if (Object.keys(this._options).length !== 0) {
json.Options = this._options;
}
return { "Options" : this._options };
if (Object.keys(this._parameters).length !== 0) {
json.Parameters = this._parameters;
}
return Object.keys(json).length !== 0 ? json : null;
}

@@ -38,0 +61,0 @@

@@ -41,3 +41,3 @@ const KeywordMapping = Object.freeze({

validNames: ["authority id", "authorityid", "authority", "tenantid", "tenant", "tid"]
},
}
});

@@ -120,2 +120,22 @@

}
// Notice: you can leave `msiEndpoint` and `clientId`
static withAadManagedIdentities(connectionString, msiEndpoint, clientId) {
const kcsb = new KustoConnectionStringBuilder(connectionString);
kcsb.msiEndpoint = msiEndpoint;
if (msiEndpoint == undefined) {
if (process && process.env && process.env.MSI_ENDPOINT) {
kcsb.msiEndpoint = process.env.MSI_ENDPOINT;
kcsb.msiSecret = process.env.MSI_SECRET;
} else {
kcsb.msiEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token";
}
}
kcsb.msiClientId = clientId;
kcsb.managedIdentity = true;
return kcsb;
}
};
const { AuthenticationContext } = require("adal-node");
const acquireManagedIdentityToken = require("./managedIdentitiesClient");

@@ -8,3 +9,4 @@ const AuthenticationMethod = Object.freeze({

appCertificate: 2,
deviceLogin: 3
deviceLogin: 3,
managedIdentities: 4
});

@@ -19,9 +21,9 @@

let url;
// support node compatability
try {
url = new URL(kcsb.dataSource);
} catch (e){
} catch (e) {
const URL = require("url").URL;
url = new URL(kcsb.dataSource);
url = new URL(kcsb.dataSource);
}

@@ -46,2 +48,7 @@

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 {

@@ -98,2 +105,12 @@ this.authMethod = AuthenticationMethod.deviceLogin;

});
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));
}
);
default:

@@ -100,0 +117,0 @@ return cb("Couldn't Authenticate, something went wrong trying to choose authentication method");