@databricks/sql 1.2.1 → 1.3.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/dist/DBSQLClient.d.ts +7 -6
- package/dist/DBSQLClient.js +91 -59
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +24 -0
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +165 -0
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +47 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +169 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.d.ts +10 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js +29 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.d.ts +7 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.js +11 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.d.ts +10 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.js +32 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/index.d.ts +21 -0
- package/dist/connection/auth/DatabricksOAuth/index.js +41 -0
- package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -0
- package/dist/connection/auth/PlainHttpAuthentication.d.ts +11 -11
- package/dist/connection/auth/PlainHttpAuthentication.js +15 -7
- package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
- package/dist/connection/connections/HttpConnection.d.ts +1 -2
- package/dist/connection/connections/HttpConnection.js +24 -14
- package/dist/connection/connections/HttpConnection.js.map +1 -1
- package/dist/connection/contracts/IAuthentication.d.ts +2 -2
- package/dist/connection/contracts/IConnectionOptions.d.ts +3 -1
- package/dist/connection/contracts/IConnectionProvider.d.ts +1 -2
- package/dist/contracts/IDBSQLClient.d.ts +17 -3
- package/dist/globalConfig.d.ts +5 -0
- package/dist/globalConfig.js +5 -0
- package/dist/globalConfig.js.map +1 -1
- package/dist/hive/Commands/BaseCommand.d.ts +3 -1
- package/dist/hive/Commands/BaseCommand.js +66 -4
- package/dist/hive/Commands/BaseCommand.js.map +1 -1
- package/dist/hive/HiveDriver.d.ts +3 -2
- package/dist/hive/HiveDriver.js +116 -44
- package/dist/hive/HiveDriver.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +8 -0
- package/dist/result/ArrowResult.js +3 -0
- package/dist/result/ArrowResult.js.map +1 -1
- package/dist/utils/areHeadersEqual.d.ts +2 -0
- package/dist/utils/areHeadersEqual.js +49 -0
- package/dist/utils/areHeadersEqual.js.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -2
- package/thrift/TCLIService.d.ts +17 -0
- package/thrift/TCLIService_types.d.ts +185 -13
- package/thrift/TCLIService_types.js +2013 -279
- package/dist/connection/auth/NoSaslAuthentication.d.ts +0 -5
- package/dist/connection/auth/NoSaslAuthentication.js +0 -14
- package/dist/connection/auth/NoSaslAuthentication.js.map +0 -1
- package/dist/connection/auth/helpers/SaslPackageFactory.d.ts +0 -11
- package/dist/connection/auth/helpers/SaslPackageFactory.js +0 -20
- package/dist/connection/auth/helpers/SaslPackageFactory.js.map +0 -1
- package/dist/connection/contracts/ITransport.d.ts +0 -6
- package/dist/connection/contracts/ITransport.js +0 -3
- package/dist/connection/contracts/ITransport.js.map +0 -1
- package/dist/connection/transports/HttpTransport.d.ts +0 -8
- package/dist/connection/transports/HttpTransport.js +0 -18
- package/dist/connection/transports/HttpTransport.js.map +0 -1
- package/dist/connection/types/AuthOptions.d.ts +0 -4
- package/dist/connection/types/AuthOptions.js +0 -3
- package/dist/connection/types/AuthOptions.js.map +0 -1
package/dist/DBSQLClient.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
4
|
-
import IDBSQLClient, { ConnectionOptions, OpenSessionRequest, ClientOptions } from './contracts/IDBSQLClient';
|
|
3
|
+
import IDBSQLClient, { ClientOptions, ConnectionOptions, OpenSessionRequest } from './contracts/IDBSQLClient';
|
|
5
4
|
import IDBSQLSession from './contracts/IDBSQLSession';
|
|
6
5
|
import IAuthentication from './connection/contracts/IAuthentication';
|
|
7
6
|
export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
|
|
8
7
|
private client;
|
|
9
|
-
private connection;
|
|
10
|
-
private connectionProvider;
|
|
11
8
|
private authProvider;
|
|
9
|
+
private connectionOptions;
|
|
10
|
+
private additionalHeaders;
|
|
12
11
|
private readonly logger;
|
|
13
12
|
private readonly thrift;
|
|
14
13
|
constructor(options?: ClientOptions);
|
|
15
14
|
private getConnectionOptions;
|
|
15
|
+
private getAuthProvider;
|
|
16
16
|
/**
|
|
17
17
|
* Connects DBSQLClient to endpoint
|
|
18
18
|
* @public
|
|
19
19
|
* @param options - host, path, and token are required
|
|
20
|
-
* @param authProvider - Optional custom authentication provider
|
|
20
|
+
* @param authProvider - [DEPRECATED - use `authType: 'custom'] Optional custom authentication provider
|
|
21
21
|
* @returns Session object that can be used to execute statements
|
|
22
22
|
* @example
|
|
23
23
|
* const session = client.connect({host, path, token});
|
|
@@ -33,6 +33,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
|
|
|
33
33
|
* const session = await client.openSession();
|
|
34
34
|
*/
|
|
35
35
|
openSession(request?: OpenSessionRequest): Promise<IDBSQLSession>;
|
|
36
|
-
getClient
|
|
36
|
+
private getClient;
|
|
37
|
+
private createConnection;
|
|
37
38
|
close(): Promise<void>;
|
|
38
39
|
}
|
package/dist/DBSQLClient.js
CHANGED
|
@@ -30,12 +30,12 @@ const TCLIService_types_1 = require("../thrift/TCLIService_types");
|
|
|
30
30
|
const HiveDriver_1 = __importDefault(require("./hive/HiveDriver"));
|
|
31
31
|
const Types_1 = require("./hive/Types");
|
|
32
32
|
const DBSQLSession_1 = __importDefault(require("./DBSQLSession"));
|
|
33
|
-
const NoSaslAuthentication_1 = __importDefault(require("./connection/auth/NoSaslAuthentication"));
|
|
34
33
|
const HttpConnection_1 = __importDefault(require("./connection/connections/HttpConnection"));
|
|
35
34
|
const Status_1 = __importDefault(require("./dto/Status"));
|
|
36
35
|
const HiveDriverError_1 = __importDefault(require("./errors/HiveDriverError"));
|
|
37
36
|
const utils_1 = require("./utils");
|
|
38
37
|
const PlainHttpAuthentication_1 = __importDefault(require("./connection/auth/PlainHttpAuthentication"));
|
|
38
|
+
const DatabricksOAuth_1 = __importDefault(require("./connection/auth/DatabricksOAuth"));
|
|
39
39
|
const IDBSQLLogger_1 = require("./contracts/IDBSQLLogger");
|
|
40
40
|
const DBSQLLogger_1 = __importDefault(require("./DBSQLLogger"));
|
|
41
41
|
function prependSlash(str) {
|
|
@@ -58,45 +58,108 @@ function getInitialNamespaceOptions(catalogName, schemaName) {
|
|
|
58
58
|
class DBSQLClient extends events_1.EventEmitter {
|
|
59
59
|
constructor(options) {
|
|
60
60
|
super();
|
|
61
|
+
this.client = null;
|
|
62
|
+
this.authProvider = null;
|
|
63
|
+
this.connectionOptions = null;
|
|
64
|
+
this.additionalHeaders = {};
|
|
61
65
|
this.thrift = thrift_1.default;
|
|
62
|
-
this.connectionProvider = new HttpConnection_1.default();
|
|
63
|
-
this.authProvider = new NoSaslAuthentication_1.default();
|
|
64
66
|
this.logger = (options === null || options === void 0 ? void 0 : options.logger) || new DBSQLLogger_1.default();
|
|
65
|
-
this.client = null;
|
|
66
|
-
this.connection = null;
|
|
67
67
|
this.logger.log(IDBSQLLogger_1.LogLevel.info, 'Created DBSQLClient');
|
|
68
68
|
}
|
|
69
|
-
getConnectionOptions(options) {
|
|
70
|
-
const { host, port, path,
|
|
69
|
+
getConnectionOptions(options, headers) {
|
|
70
|
+
const { host, port, path, clientId, authType,
|
|
71
|
+
// @ts-expect-error TS2339: Property 'token' does not exist on type 'ConnectionOptions'
|
|
72
|
+
token,
|
|
73
|
+
// @ts-expect-error TS2339: Property 'persistence' does not exist on type 'ConnectionOptions'
|
|
74
|
+
persistence,
|
|
75
|
+
// @ts-expect-error TS2339: Property 'provider' does not exist on type 'ConnectionOptions'
|
|
76
|
+
provider } = options, otherOptions = __rest(options, ["host", "port", "path", "clientId", "authType", "token", "persistence", "provider"]);
|
|
71
77
|
return {
|
|
72
78
|
host,
|
|
73
79
|
port: port || 443,
|
|
74
|
-
options: Object.assign({ path: prependSlash(path), https: true }, otherOptions),
|
|
80
|
+
options: Object.assign(Object.assign({ path: prependSlash(path), https: true }, otherOptions), { headers: Object.assign(Object.assign({}, headers), { 'User-Agent': (0, utils_1.buildUserAgentString)(options.clientId) }) }),
|
|
75
81
|
};
|
|
76
82
|
}
|
|
83
|
+
getAuthProvider(options, authProvider) {
|
|
84
|
+
if (authProvider) {
|
|
85
|
+
return authProvider;
|
|
86
|
+
}
|
|
87
|
+
switch (options.authType) {
|
|
88
|
+
case undefined:
|
|
89
|
+
case 'access-token':
|
|
90
|
+
return new PlainHttpAuthentication_1.default({
|
|
91
|
+
username: 'token',
|
|
92
|
+
password: options.token,
|
|
93
|
+
});
|
|
94
|
+
case 'databricks-oauth':
|
|
95
|
+
return new DatabricksOAuth_1.default({
|
|
96
|
+
host: options.host,
|
|
97
|
+
logger: this.logger,
|
|
98
|
+
persistence: options.persistence,
|
|
99
|
+
azureTenantId: options.azureTenantId,
|
|
100
|
+
});
|
|
101
|
+
case 'custom':
|
|
102
|
+
return options.provider;
|
|
103
|
+
// no default
|
|
104
|
+
}
|
|
105
|
+
}
|
|
77
106
|
/**
|
|
78
107
|
* Connects DBSQLClient to endpoint
|
|
79
108
|
* @public
|
|
80
109
|
* @param options - host, path, and token are required
|
|
81
|
-
* @param authProvider - Optional custom authentication provider
|
|
110
|
+
* @param authProvider - [DEPRECATED - use `authType: 'custom'] Optional custom authentication provider
|
|
82
111
|
* @returns Session object that can be used to execute statements
|
|
83
112
|
* @example
|
|
84
113
|
* const session = client.connect({host, path, token});
|
|
85
114
|
*/
|
|
86
115
|
connect(options, authProvider) {
|
|
87
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
this.authProvider =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
this.authProvider = this.getAuthProvider(options, authProvider);
|
|
118
|
+
this.connectionOptions = options;
|
|
119
|
+
return this;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Starts new session
|
|
124
|
+
* @public
|
|
125
|
+
* @param request - Can be instantiated with initialSchema, empty by default
|
|
126
|
+
* @returns Session object that can be used to execute statements
|
|
127
|
+
* @throws {StatusError}
|
|
128
|
+
* @example
|
|
129
|
+
* const session = await client.openSession();
|
|
130
|
+
*/
|
|
131
|
+
openSession(request = {}) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const driver = new HiveDriver_1.default(() => this.getClient());
|
|
134
|
+
const response = yield driver.openSession(Object.assign({ client_protocol_i64: new Types_1.Int64(TCLIService_types_1.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V6) }, getInitialNamespaceOptions(request.initialCatalog, request.initialSchema)));
|
|
135
|
+
Status_1.default.assert(response.status);
|
|
136
|
+
return new DBSQLSession_1.default(driver, (0, utils_1.definedOrError)(response.sessionHandle), this.logger);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getClient() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
if (!this.connectionOptions || !this.authProvider) {
|
|
142
|
+
throw new HiveDriverError_1.default('DBSQLClient: not connected');
|
|
143
|
+
}
|
|
144
|
+
const authHeaders = yield this.authProvider.authenticate();
|
|
145
|
+
// When auth headers change - recreate client. Thrift library does not provide API for updating
|
|
146
|
+
// changed options, therefore we have to recreate both connection and client to apply new headers
|
|
147
|
+
if (!this.client || !(0, utils_1.areHeadersEqual)(this.additionalHeaders, authHeaders)) {
|
|
148
|
+
this.logger.log(IDBSQLLogger_1.LogLevel.info, 'DBSQLClient: initializing thrift client');
|
|
149
|
+
this.additionalHeaders = authHeaders;
|
|
150
|
+
const connectionOptions = this.getConnectionOptions(this.connectionOptions, this.additionalHeaders);
|
|
151
|
+
const connection = yield this.createConnection(connectionOptions);
|
|
152
|
+
this.client = this.thrift.createClient(TCLIService_1.default, connection.getConnection());
|
|
153
|
+
}
|
|
154
|
+
return this.client;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
createConnection(options) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const connectionProvider = new HttpConnection_1.default();
|
|
160
|
+
const connection = yield connectionProvider.connect(options);
|
|
161
|
+
const thriftConnection = connection.getConnection();
|
|
162
|
+
thriftConnection.on('error', (error) => {
|
|
100
163
|
// Error.stack already contains error type and message, so log stack if available,
|
|
101
164
|
// otherwise fall back to just error type + message
|
|
102
165
|
this.logger.log(IDBSQLLogger_1.LogLevel.error, error.stack || `${error.name}: ${error.message}`);
|
|
@@ -108,57 +171,26 @@ class DBSQLClient extends events_1.EventEmitter {
|
|
|
108
171
|
// Since we already logged it few lines above, just suppress this behaviour
|
|
109
172
|
}
|
|
110
173
|
});
|
|
111
|
-
|
|
174
|
+
thriftConnection.on('reconnecting', (params) => {
|
|
112
175
|
this.logger.log(IDBSQLLogger_1.LogLevel.debug, `Reconnecting, params: ${JSON.stringify(params)}`);
|
|
113
176
|
this.emit('reconnecting', params);
|
|
114
177
|
});
|
|
115
|
-
|
|
178
|
+
thriftConnection.on('close', () => {
|
|
116
179
|
this.logger.log(IDBSQLLogger_1.LogLevel.debug, 'Closing connection.');
|
|
117
180
|
this.emit('close');
|
|
118
181
|
});
|
|
119
|
-
|
|
182
|
+
thriftConnection.on('timeout', () => {
|
|
120
183
|
this.logger.log(IDBSQLLogger_1.LogLevel.debug, 'Connection timed out.');
|
|
121
184
|
this.emit('timeout');
|
|
122
185
|
});
|
|
123
|
-
return
|
|
186
|
+
return connection;
|
|
124
187
|
});
|
|
125
188
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Starts new session
|
|
128
|
-
* @public
|
|
129
|
-
* @param request - Can be instantiated with initialSchema, empty by default
|
|
130
|
-
* @returns Session object that can be used to execute statements
|
|
131
|
-
* @throws {StatusError}
|
|
132
|
-
* @example
|
|
133
|
-
* const session = await client.openSession();
|
|
134
|
-
*/
|
|
135
|
-
openSession(request = {}) {
|
|
136
|
-
var _a;
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
if (!((_a = this.connection) === null || _a === void 0 ? void 0 : _a.isConnected())) {
|
|
139
|
-
throw new HiveDriverError_1.default('DBSQLClient: connection is lost');
|
|
140
|
-
}
|
|
141
|
-
const driver = new HiveDriver_1.default(this.getClient());
|
|
142
|
-
const response = yield driver.openSession(Object.assign({ client_protocol_i64: new Types_1.Int64(TCLIService_types_1.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V6) }, getInitialNamespaceOptions(request.initialCatalog, request.initialSchema)));
|
|
143
|
-
Status_1.default.assert(response.status);
|
|
144
|
-
return new DBSQLSession_1.default(driver, (0, utils_1.definedOrError)(response.sessionHandle), this.logger);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
getClient() {
|
|
148
|
-
if (!this.client) {
|
|
149
|
-
throw new HiveDriverError_1.default('DBSQLClient: client is not initialized');
|
|
150
|
-
}
|
|
151
|
-
return this.client;
|
|
152
|
-
}
|
|
153
189
|
close() {
|
|
154
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.connection.getConnection().end();
|
|
159
|
-
}
|
|
160
|
-
this.connection = null;
|
|
161
|
-
}
|
|
191
|
+
this.client = null;
|
|
192
|
+
this.authProvider = null;
|
|
193
|
+
this.connectionOptions = null;
|
|
162
194
|
});
|
|
163
195
|
}
|
|
164
196
|
}
|
package/dist/DBSQLClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBSQLClient.js","sourceRoot":"","sources":["../lib/DBSQLClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"DBSQLClient.js","sourceRoot":"","sources":["../lib/DBSQLClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6C;AAE7C,mCAAsC;AACtC,wEAAgD;AAChD,mEAA+D;AAE/D,mEAA2C;AAC3C,wCAAqC;AACrC,kEAA0C;AAG1C,6FAAqE;AAErE,0DAAkC;AAClC,+EAAuD;AACvD,mCAAgF;AAChF,wGAAgF;AAChF,wFAAgE;AAChE,2DAAkE;AAClE,gEAAwC;AAExC,SAAS,YAAY,CAAC,GAAW;IAC/B,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAC3C,OAAO,IAAI,GAAG,EAAE,CAAC;KAClB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAoB,EAAE,UAAmB;IAC3E,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,EAAE;QAC/B,OAAO,EAAE,CAAC;KACX;IAED,OAAO;QACL,gBAAgB,EAAE;YAChB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
+
import IDBSQLLogger from '../../../contracts/IDBSQLLogger';
|
|
3
|
+
import { OAuthScopes } from './OAuthScope';
|
|
4
|
+
export interface AuthorizationCodeOptions {
|
|
5
|
+
client: BaseClient;
|
|
6
|
+
ports: Array<number>;
|
|
7
|
+
logger?: IDBSQLLogger;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthorizationCodeFetchResult {
|
|
10
|
+
code: string;
|
|
11
|
+
verifier: string;
|
|
12
|
+
redirectUri: string;
|
|
13
|
+
}
|
|
14
|
+
export default class AuthorizationCode {
|
|
15
|
+
private readonly client;
|
|
16
|
+
private readonly host;
|
|
17
|
+
private readonly ports;
|
|
18
|
+
private readonly logger?;
|
|
19
|
+
constructor(options: AuthorizationCodeOptions);
|
|
20
|
+
private openUrl;
|
|
21
|
+
fetch(scopes: OAuthScopes): Promise<AuthorizationCodeFetchResult>;
|
|
22
|
+
private startServer;
|
|
23
|
+
private renderCallbackResponse;
|
|
24
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const http_1 = __importDefault(require("http"));
|
|
16
|
+
const openid_client_1 = require("openid-client");
|
|
17
|
+
const open_1 = __importDefault(require("open"));
|
|
18
|
+
const IDBSQLLogger_1 = require("../../../contracts/IDBSQLLogger");
|
|
19
|
+
const OAuthScope_1 = require("./OAuthScope");
|
|
20
|
+
function startServer(host, port, requestHandler) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const server = http_1.default.createServer(requestHandler);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const errorListener = (error) => {
|
|
25
|
+
server.off('error', errorListener);
|
|
26
|
+
reject(error);
|
|
27
|
+
};
|
|
28
|
+
server.on('error', errorListener);
|
|
29
|
+
server.listen(port, host, () => {
|
|
30
|
+
server.off('error', errorListener);
|
|
31
|
+
resolve(server);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function stopServer(server) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (!server.listening) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const errorListener = (error) => {
|
|
43
|
+
server.off('error', errorListener);
|
|
44
|
+
reject(error);
|
|
45
|
+
};
|
|
46
|
+
server.on('error', errorListener);
|
|
47
|
+
server.close(() => {
|
|
48
|
+
server.off('error', errorListener);
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
class AuthorizationCode {
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.host = 'localhost';
|
|
57
|
+
this.client = options.client;
|
|
58
|
+
this.ports = options.ports;
|
|
59
|
+
this.logger = options.logger;
|
|
60
|
+
}
|
|
61
|
+
openUrl(url) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return (0, open_1.default)(url);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
fetch(scopes) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const verifierString = openid_client_1.generators.codeVerifier(32);
|
|
69
|
+
const challengeString = openid_client_1.generators.codeChallenge(verifierString);
|
|
70
|
+
const state = openid_client_1.generators.state(16);
|
|
71
|
+
let receivedParams;
|
|
72
|
+
const server = yield this.startServer((req, res) => {
|
|
73
|
+
const params = this.client.callbackParams(req);
|
|
74
|
+
if (params.state === state) {
|
|
75
|
+
receivedParams = params;
|
|
76
|
+
res.writeHead(200);
|
|
77
|
+
res.end(this.renderCallbackResponse());
|
|
78
|
+
server.stop();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
res.writeHead(404);
|
|
82
|
+
res.end();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const redirectUri = `http://${server.host}:${server.port}`;
|
|
86
|
+
const authUrl = this.client.authorizationUrl({
|
|
87
|
+
response_type: 'code',
|
|
88
|
+
response_mode: 'query',
|
|
89
|
+
scope: scopes.join(OAuthScope_1.scopeDelimiter),
|
|
90
|
+
code_challenge: challengeString,
|
|
91
|
+
code_challenge_method: 'S256',
|
|
92
|
+
state,
|
|
93
|
+
redirect_uri: redirectUri,
|
|
94
|
+
});
|
|
95
|
+
yield this.openUrl(authUrl);
|
|
96
|
+
yield server.stopped();
|
|
97
|
+
if (!receivedParams || !receivedParams.code) {
|
|
98
|
+
if (receivedParams === null || receivedParams === void 0 ? void 0 : receivedParams.error) {
|
|
99
|
+
const errorMessage = `OAuth error: ${receivedParams.error} ${receivedParams.error_description}`;
|
|
100
|
+
throw new Error(errorMessage);
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`No path parameters were returned to the callback at ${redirectUri}`);
|
|
103
|
+
}
|
|
104
|
+
return { code: receivedParams.code, verifier: verifierString, redirectUri };
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
startServer(requestHandler) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
for (const port of this.ports) {
|
|
111
|
+
const host = this.host; // eslint-disable-line prefer-destructuring
|
|
112
|
+
try {
|
|
113
|
+
const server = yield startServer(host, port, requestHandler); // eslint-disable-line no-await-in-loop
|
|
114
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(IDBSQLLogger_1.LogLevel.info, `Listening for OAuth authorization callback at ${host}:${port}`);
|
|
115
|
+
let resolveStopped;
|
|
116
|
+
let rejectStopped;
|
|
117
|
+
const stoppedPromise = new Promise((resolve, reject) => {
|
|
118
|
+
resolveStopped = resolve;
|
|
119
|
+
rejectStopped = reject;
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
host,
|
|
123
|
+
port,
|
|
124
|
+
server,
|
|
125
|
+
stop: () => stopServer(server).then(resolveStopped).catch(rejectStopped),
|
|
126
|
+
stopped: () => stoppedPromise,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
// if port already in use - try another one, otherwise re-throw an exception
|
|
131
|
+
if (error instanceof Error && 'code' in error && error.code === 'EADDRINUSE') {
|
|
132
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(IDBSQLLogger_1.LogLevel.debug, `Failed to start server at ${host}:${port}: ${error.code}`);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw new Error('Failed to start server: all ports are in use');
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
renderCallbackResponse() {
|
|
143
|
+
const applicationName = 'Databricks Sql Connector';
|
|
144
|
+
return `<html lang="en">
|
|
145
|
+
<head>
|
|
146
|
+
<title>Close this Tab</title>
|
|
147
|
+
<style>
|
|
148
|
+
body {
|
|
149
|
+
font-family: "Barlow", Helvetica, Arial, sans-serif;
|
|
150
|
+
padding: 20px;
|
|
151
|
+
background-color: #f3f3f3;
|
|
152
|
+
}
|
|
153
|
+
</style>
|
|
154
|
+
</head>
|
|
155
|
+
<body>
|
|
156
|
+
<h1>Please close this tab.</h1>
|
|
157
|
+
<p>
|
|
158
|
+
The ${applicationName} received a response. You may close this tab.
|
|
159
|
+
</p>
|
|
160
|
+
</body>
|
|
161
|
+
</html>`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.default = AuthorizationCode;
|
|
165
|
+
//# sourceMappingURL=AuthorizationCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthorizationCode.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/AuthorizationCode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAqE;AACrE,iDAA2E;AAC3E,gDAAwB;AACxB,kEAAyE;AACzE,6CAA2D;AAQ3D,SAAe,WAAW,CACxB,IAAY,EACZ,IAAY,EACZ,cAAmE;;QAEnE,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QAEjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,aAAa,GAAG,CAAC,KAAY,EAAE,EAAE;gBACrC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;gBACnC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YAEF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;gBAC7B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;gBACnC,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AAED,SAAe,UAAU,CAAC,MAAc;;QACtC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACrB,OAAO;SACR;QAED,OAAO,I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;qBACb;iBACF;aACF;YAED,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;;KACjE;IAEO,sBAAsB;QAC5B,MAAM,eAAe,GAAG,0BAA0B,CAAC;QAEnD,OAAO;;;;;;;;;;;;;;UAcD,eAAe;;;QAGjB,CAAC;IACP,CAAC;CACF;AAxHD,oCAwHC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Issuer, BaseClient } from 'openid-client';
|
|
2
|
+
import IDBSQLLogger from '../../../contracts/IDBSQLLogger';
|
|
3
|
+
import OAuthToken from './OAuthToken';
|
|
4
|
+
import { OAuthScopes } from './OAuthScope';
|
|
5
|
+
export interface OAuthManagerOptions {
|
|
6
|
+
host: string;
|
|
7
|
+
callbackPorts?: Array<number>;
|
|
8
|
+
clientId?: string;
|
|
9
|
+
azureTenantId?: string;
|
|
10
|
+
logger?: IDBSQLLogger;
|
|
11
|
+
}
|
|
12
|
+
export default abstract class OAuthManager {
|
|
13
|
+
protected readonly options: OAuthManagerOptions;
|
|
14
|
+
protected readonly logger?: IDBSQLLogger;
|
|
15
|
+
protected issuer?: Issuer;
|
|
16
|
+
protected client?: BaseClient;
|
|
17
|
+
constructor(options: OAuthManagerOptions);
|
|
18
|
+
protected abstract getOIDCConfigUrl(): string;
|
|
19
|
+
protected abstract getAuthorizationUrl(): string;
|
|
20
|
+
protected abstract getClientId(): string;
|
|
21
|
+
protected abstract getCallbackPorts(): Array<number>;
|
|
22
|
+
protected getScopes(requestedScopes: OAuthScopes): OAuthScopes;
|
|
23
|
+
protected getClient(): Promise<BaseClient>;
|
|
24
|
+
refreshAccessToken(token: OAuthToken): Promise<OAuthToken>;
|
|
25
|
+
getToken(scopes: OAuthScopes): Promise<OAuthToken>;
|
|
26
|
+
static getManager(options: OAuthManagerOptions): OAuthManager;
|
|
27
|
+
}
|
|
28
|
+
export declare class AWSOAuthManager extends OAuthManager {
|
|
29
|
+
static domains: string[];
|
|
30
|
+
static defaultClientId: string;
|
|
31
|
+
static defaultCallbackPorts: number[];
|
|
32
|
+
protected getOIDCConfigUrl(): string;
|
|
33
|
+
protected getAuthorizationUrl(): string;
|
|
34
|
+
protected getClientId(): string;
|
|
35
|
+
protected getCallbackPorts(): Array<number>;
|
|
36
|
+
}
|
|
37
|
+
export declare class AzureOAuthManager extends OAuthManager {
|
|
38
|
+
static domains: string[];
|
|
39
|
+
static defaultClientId: string;
|
|
40
|
+
static defaultCallbackPorts: number[];
|
|
41
|
+
static datatricksAzureApp: string;
|
|
42
|
+
protected getOIDCConfigUrl(): string;
|
|
43
|
+
protected getAuthorizationUrl(): string;
|
|
44
|
+
protected getClientId(): string;
|
|
45
|
+
protected getCallbackPorts(): Array<number>;
|
|
46
|
+
protected getScopes(requestedScopes: OAuthScopes): OAuthScopes;
|
|
47
|
+
}
|