From defa62eeb430094a9d4cd7e784d357062374edef Mon Sep 17 00:00:00 2001 From: chulanovskyi Date: Thu, 18 Jul 2024 14:22:07 +0300 Subject: [PATCH 1/2] feat: added fetch-http-handler --- package-lock.json | 105 ++++++++++++++++++ package.json | 1 + .../helpers/connectionHelper.js | 28 ++--- 3 files changed, 121 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec5fad5..2c39f15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.2.2", "dependencies": { "@aws-sdk/client-glue": "3.613.0", + "@aws-sdk/fetch-http-handler": "3.374.0", "antlr4": "4.8.0", "lodash": "4.17.21" }, @@ -494,6 +495,110 @@ "@aws-sdk/client-sts": "^3.609.0" } }, + "node_modules/@aws-sdk/fetch-http-handler": { + "version": "3.374.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/fetch-http-handler/-/fetch-http-handler-3.374.0.tgz", + "integrity": "sha512-Xt+4F6tGi/q9Z32kLo8SSm9krLlCY2oTLxCfP3/1SKY2wqWKHjAgpLmPD+GW7fdMjAwhDqzW5ZhcSmvHNvoD/w==", + "deprecated": "This package has moved to @smithy/fetch-http-handler", + "dependencies": { + "@smithy/fetch-http-handler": "^1.0.1", + "tslib": "^2.5.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/fetch-http-handler": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-1.1.0.tgz", + "integrity": "sha512-N22C9R44u5WGlcY+Wuv8EXmCAq62wWwriRAuoczMEwAIjPbvHSthyPSLqI4S7kAST1j6niWg8kwpeJ3ReAv3xg==", + "dependencies": { + "@smithy/protocol-http": "^1.2.0", + "@smithy/querystring-builder": "^1.1.0", + "@smithy/types": "^1.2.0", + "@smithy/util-base64": "^1.1.0", + "tslib": "^2.5.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/is-array-buffer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-1.1.0.tgz", + "integrity": "sha512-twpQ/n+3OWZJ7Z+xu43MJErmhB/WO/mMTnqR6PwWQShvSJ/emx5d1N59LQZk6ZpTAeuRWrc+eHhkzTp9NFjNRQ==", + "dependencies": { + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/protocol-http": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-1.2.0.tgz", + "integrity": "sha512-GfGfruksi3nXdFok5RhgtOnWe5f6BndzYfmEXISD+5gAGdayFGpjWu5pIqIweTudMtse20bGbc+7MFZXT1Tb8Q==", + "dependencies": { + "@smithy/types": "^1.2.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/querystring-builder": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-1.1.0.tgz", + "integrity": "sha512-gDEi4LxIGLbdfjrjiY45QNbuDmpkwh9DX4xzrR2AzjjXpxwGyfSpbJaYhXARw9p17VH0h9UewnNQXNwaQyYMDA==", + "dependencies": { + "@smithy/types": "^1.2.0", + "@smithy/util-uri-escape": "^1.1.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/types": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-1.2.0.tgz", + "integrity": "sha512-z1r00TvBqF3dh4aHhya7nz1HhvCg4TRmw51fjMrh5do3h+ngSstt/yKlNbHeb9QxJmFbmN8KEVSWgb1bRvfEoA==", + "dependencies": { + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/util-base64": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/util-base64/-/util-base64-1.1.0.tgz", + "integrity": "sha512-FpYmDmVbOXAxqvoVCwqehUN0zXS+lN8V7VS9O7I8MKeVHdSTsZzlwiMEvGoyTNOXWn8luF4CTDYgNHnZViR30g==", + "dependencies": { + "@smithy/util-buffer-from": "^1.1.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/util-buffer-from": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-1.1.0.tgz", + "integrity": "sha512-9m6NXE0ww+ra5HKHCHig20T+FAwxBAm7DIdwc/767uGWbRcY720ybgPacQNB96JMOI7xVr/CDa3oMzKmW4a+kw==", + "dependencies": { + "@smithy/is-array-buffer": "^1.1.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/fetch-http-handler/node_modules/@smithy/util-uri-escape": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-1.1.0.tgz", + "integrity": "sha512-/jL/V1xdVRt5XppwiaEU8Etp5WHZj609n0xMTuehmCqdoOFbId1M+aEeDWZsQ+8JbEB/BJ6ynY2SlYmOaKtt8w==", + "dependencies": { + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@aws-sdk/middleware-host-header": { "version": "3.609.0", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.609.0.tgz", diff --git a/package.json b/package.json index 432d521..b14ea0e 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "description": "Hackolade plugin for AWS Glue Data Catalog", "dependencies": { "@aws-sdk/client-glue": "3.613.0", + "@aws-sdk/fetch-http-handler": "3.374.0", "antlr4": "4.8.0", "lodash": "4.17.21" }, diff --git a/reverse_engineering/helpers/connectionHelper.js b/reverse_engineering/helpers/connectionHelper.js index 6d7806d..b196e0f 100644 --- a/reverse_engineering/helpers/connectionHelper.js +++ b/reverse_engineering/helpers/connectionHelper.js @@ -5,6 +5,7 @@ const { GetDatabaseCommand, GetDatabasesCommand, } = require('@aws-sdk/client-glue'); +const { FetchHttpHandler } = require('@aws-sdk/fetch-http-handler'); const fs = require('fs'); const https = require('https'); const { mapTableData } = require('./tablePropertiesHelper'); @@ -28,6 +29,7 @@ const readCertificateFile = path => { }); }); }; + const getSslOptions = async connectionInfo => { switch (connectionInfo.sslType) { case 'Server validation': { @@ -57,17 +59,18 @@ const getSslOptions = async connectionInfo => { const createConnection = async connectionInfo => { const { accessKeyId, secretAccessKey, region, sessionToken } = connectionInfo; const sslOptions = await getSslOptions(connectionInfo); - const httpOptions = sslOptions.ssl - ? { - httpOptions: { - agent: new https.Agent({ - rejectUnauthorized: true, - ...sslOptions, - }), - }, - ...sslOptions, - } - : {}; + + const agent = new https.Agent({ + rejectUnauthorized: true, + ...sslOptions, + }); + + const httpHandler = new FetchHttpHandler({ + httpAgent: agent, + httpsAgent: agent, + // UtilityProcess.fork() creates a Chromium child process and Chromium does provide the Fetch API. + fetch: fetch, + }); return new GlueClient({ region, @@ -76,8 +79,7 @@ const createConnection = async connectionInfo => { secretAccessKey, sessionToken, }, - // TODO: verify ssl options to be applied correctly - ...httpOptions, + requestHandler: httpHandler, }); }; const connect = async connectionInfo => { From 0cc7d641adc79bb3279e927a391ba1b9fcca64d1 Mon Sep 17 00:00:00 2001 From: chulanovskyi-bs Date: Thu, 18 Jul 2024 18:09:08 +0300 Subject: [PATCH 2/2] chore: move HttpHandler to its own place --- reverse_engineering/helpers/connectionHelper.js | 11 +++-------- reverse_engineering/httpHandler/HttpHandler.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 reverse_engineering/httpHandler/HttpHandler.js diff --git a/reverse_engineering/helpers/connectionHelper.js b/reverse_engineering/helpers/connectionHelper.js index b196e0f..65d5970 100644 --- a/reverse_engineering/helpers/connectionHelper.js +++ b/reverse_engineering/helpers/connectionHelper.js @@ -5,10 +5,10 @@ const { GetDatabaseCommand, GetDatabasesCommand, } = require('@aws-sdk/client-glue'); -const { FetchHttpHandler } = require('@aws-sdk/fetch-http-handler'); const fs = require('fs'); const https = require('https'); const { mapTableData } = require('./tablePropertiesHelper'); +const { HttpHandler } = require('../httpHandler/HttpHandler'); let connection; let databaseLoadContinuationToken; @@ -65,12 +65,7 @@ const createConnection = async connectionInfo => { ...sslOptions, }); - const httpHandler = new FetchHttpHandler({ - httpAgent: agent, - httpsAgent: agent, - // UtilityProcess.fork() creates a Chromium child process and Chromium does provide the Fetch API. - fetch: fetch, - }); + const httpHandler = new HttpHandler(agent); return new GlueClient({ region, @@ -79,7 +74,7 @@ const createConnection = async connectionInfo => { secretAccessKey, sessionToken, }, - requestHandler: httpHandler, + requestHandler: httpHandler.handler, }); }; const connect = async connectionInfo => { diff --git a/reverse_engineering/httpHandler/HttpHandler.js b/reverse_engineering/httpHandler/HttpHandler.js new file mode 100644 index 0000000..c08bfac --- /dev/null +++ b/reverse_engineering/httpHandler/HttpHandler.js @@ -0,0 +1,16 @@ +const { FetchHttpHandler } = require('@aws-sdk/fetch-http-handler'); + +class HttpHandler { + handler = null; + + constructor(agent) { + this.agent = agent; + this.handler = new FetchHttpHandler(); + } + + get() { + return this.handler; + } +} + +module.exports = { HttpHandler };