Skip to content

Commit ed62126

Browse files
committed
Add ssl support
1 parent 0f354d3 commit ed62126

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import axios, {AxiosRequestConfig, RawAxiosRequestHeaders} from 'axios';
2-
import * as https from 'https'
2+
import * as https from 'https';
3+
import * as tls from 'tls';
34

45
const DEFAULT_SERVER = 'http://localhost:8080';
56
const DEFAULT_SOURCE = 'trino-js-client';
67
const DEFAULT_USER = process.env.USER;
7-
const DEFAULT_VERIFY_SSL_CERT = true;
88

99
// Trino headers
1010
const TRINO_HEADER_PREFIX = 'X-Trino-';
@@ -45,6 +45,10 @@ const encodeAsString = (obj: {[key: string]: string}) => {
4545
.join(',');
4646
};
4747

48+
export type SecureContextOptions = tls.SecureContextOptions & {
49+
readonly rejectUnauthorized?: boolean;
50+
};
51+
4852
export type ConnectionOptions = {
4953
readonly server?: string;
5054
readonly source?: string;
@@ -53,7 +57,7 @@ export type ConnectionOptions = {
5357
readonly auth?: Auth;
5458
readonly session?: Session;
5559
readonly extraCredential?: ExtraCredential;
56-
readonly verifySSLCert?: boolean;
60+
readonly ssl?: SecureContextOptions;
5761
};
5862

5963
export type QueryStage = {
@@ -167,9 +171,7 @@ class Client {
167171
) {}
168172

169173
static create(options: ConnectionOptions): Client {
170-
const agent = new https.Agent({
171-
rejectUnauthorized: options.verifySSLCert ?? DEFAULT_VERIFY_SSL_CERT
172-
});
174+
const agent = new https.Agent(options.ssl ?? {});
173175

174176
const clientConfig: AxiosRequestConfig = {
175177
baseURL: options.server ?? DEFAULT_SERVER,

0 commit comments

Comments
 (0)