Skip to content

Commit

Permalink
Add ssl support
Browse files Browse the repository at this point in the history
  • Loading branch information
regadas committed Mar 3, 2023
1 parent 0f354d3 commit ed62126
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios, {AxiosRequestConfig, RawAxiosRequestHeaders} from 'axios';
import * as https from 'https'
import * as https from 'https';
import * as tls from 'tls';

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

// Trino headers
const TRINO_HEADER_PREFIX = 'X-Trino-';
Expand Down Expand Up @@ -45,6 +45,10 @@ const encodeAsString = (obj: {[key: string]: string}) => {
.join(',');
};

export type SecureContextOptions = tls.SecureContextOptions & {
readonly rejectUnauthorized?: boolean;
};

export type ConnectionOptions = {
readonly server?: string;
readonly source?: string;
Expand All @@ -53,7 +57,7 @@ export type ConnectionOptions = {
readonly auth?: Auth;
readonly session?: Session;
readonly extraCredential?: ExtraCredential;
readonly verifySSLCert?: boolean;
readonly ssl?: SecureContextOptions;
};

export type QueryStage = {
Expand Down Expand Up @@ -167,9 +171,7 @@ class Client {
) {}

static create(options: ConnectionOptions): Client {
const agent = new https.Agent({
rejectUnauthorized: options.verifySSLCert ?? DEFAULT_VERIFY_SSL_CERT
});
const agent = new https.Agent(options.ssl ?? {});

const clientConfig: AxiosRequestConfig = {
baseURL: options.server ?? DEFAULT_SERVER,
Expand Down

0 comments on commit ed62126

Please sign in to comment.