Skip to content

Commit

Permalink
Merge pull request #25 from shutterstock/dependencies-upgrade
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
fabrice404 authored Dec 13, 2021
2 parents 96879cc + b1037a3 commit f82b34f
Show file tree
Hide file tree
Showing 6 changed files with 2,099 additions and 2,853 deletions.
11 changes: 6 additions & 5 deletions lib/driver/aws-sigv4-driver-remote-connection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const debug = require('debug')('gremlin-aws-sigv4:driver');
const gremlin = require('gremlin');
const request = require('request');
const { getUrlAndHeaders, uuid } = require('../utils');
const { getUrlAndHeaders, uuid, request } = require('../utils');

class AwsSigV4DriverRemoteConnection extends gremlin.driver.RemoteConnection {
constructor(host, port, options = {}, cbConnected = null, cbDisconnected = null, cbError = null) {
Expand Down Expand Up @@ -37,9 +36,11 @@ class AwsSigV4DriverRemoteConnection extends gremlin.driver.RemoteConnection {
this.try += 1;
const { url, headers } = getUrlAndHeaders(this.host, this.port, this.options, '/status', this.secure ? 'https' : 'http');
debug(`get Neptune status: ${JSON.stringify(url, headers)} (try #${this.try})`);
request.get({ url, headers, timeout: 3000 }, (error, response, body) => {
this._statusCallback(error, response, body);
});
request(
url,
{ headers, timeout: 3000 },
(err, response, body) => { this._statusCallback(err, response, body); },
);
}

_statusCallback(error, response, body) {
Expand Down
25 changes: 23 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-bitwise */

const aws4 = require('aws4');
const crypto = require('crypto');
const debug = require('debug')('gremlin-aws-sigv4:utils');
const aws4 = require('aws4');
const http = require('http');
const https = require('https');

/**
* Generates a random uuid
Expand Down Expand Up @@ -56,6 +58,25 @@ const getUrlAndHeaders = (host, port, credentials, canonicalUri, protocol) => {
};
};

/**
* Callbackify native http(s) get
*/
const request = (url, options, cb) => {
debug(`Requesting: ${url}`);
(url.match('https://') ? https.get : http.get)(url, options, (response) => {
let body = '';
response.on('data', (d) => {
body += d;
});
response.on('end', () => {
cb(null, response, body);
});
})
.on('error', (err) => {
cb(err, null, null);
});
};

module.exports = {
uuid, getUrlAndHeaders,
uuid, getUrlAndHeaders, request,
};
Loading

0 comments on commit f82b34f

Please sign in to comment.