Skip to content

Commit

Permalink
fixup post reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 23, 2024
1 parent 139c6ed commit 48b96b8
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 44 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
hdcontroller: require('./lib/hdcontroller'),
shuffle: require('./lib/shuffle'),
};
import hdcontroller from './lib/hdcontroller';
import shuffle from './lib/shuffle';

export { hdcontroller, shuffle };

26 changes: 11 additions & 15 deletions lib/hdcontroller.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.HDProxydClient = exports.HDProxydError = void 0;
const assert = require("assert");
const async = require("async");
const http = require("http");
const werelogs = require("werelogs");
const httpagent_1 = require("httpagent");
const shuffle_1 = require("./shuffle");
class HDProxydError extends Error {
import * as assert from 'assert';
import * as async from 'async';
import * as http from 'http';
import * as werelogs from 'werelogs';
import { http as httpAgent } from 'httpagent';
import { shuffle } from './shuffle';
export class HDProxydError extends Error {
constructor() {
super(...arguments);
this.isExpected = false;
}
}
exports.HDProxydError = HDProxydError;
/*
* This handles the request, and the corresponding response default behaviour
*/
Expand Down Expand Up @@ -58,7 +55,7 @@ function _createRequest(req, log, callback) {
function _parseBootstrapList(list) {
return list.map(value => value.split(':'));
}
class HDProxydClient {
export class HDProxydClient {
/**
* This represent our interface with the hdproxyd server.
* @constructor
Expand All @@ -74,10 +71,10 @@ class HDProxydClient {
const options = opts || {};
this.bootstrap = opts.bootstrap === undefined ?
[['localhost', '18888']] : _parseBootstrapList(opts.bootstrap);
this.bootstrap = (0, shuffle_1.shuffle)(this.bootstrap);
this.bootstrap = shuffle(this.bootstrap);
this.path = '/store/';
this.setCurrentBootstrap(this.bootstrap[0]);
this.httpAgent = new httpagent_1.http.Agent({
this.httpAgent = new httpAgent.Agent({
freeSocketTimeout: 60 * 1000,
timeout: 2 * 60 * 1000,
});
Expand Down Expand Up @@ -198,7 +195,7 @@ class HDProxydClient {
* creation and its sending.
*/
_handleRequest(method, stream, size, key, log, callback, params, payload) {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const headers = (params.headers ? params.headers : {});
const req = this._createRequestHeader(method, headers, key, params, log);
const host = this.getCurrentBootstrap();
Expand Down Expand Up @@ -384,4 +381,3 @@ class HDProxydClient {
request.end();
}
}
exports.HDProxydClient = HDProxydClient;
8 changes: 3 additions & 5 deletions lib/shuffle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.shuffle = shuffle;
const cryptoLib = require("crypto");
import * as cryptoLib from 'crypto';
const randomBytes = cryptoLib.randomBytes;
/*
* This set of function allows us to create an efficient shuffle
Expand All @@ -23,7 +21,7 @@ function nextBytes(numBytes) {
return randomBytes(numBytes);
}
catch (ex) {
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : "Unknown error"}`);
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : 'Unknown error'}`);
}
}
/*
Expand Down Expand Up @@ -56,7 +54,7 @@ function randomRange(min, max) {
* @param {Array} array - Any type of array
* @return {Array} - The sorted array
*/
function shuffle(array) {
export function shuffle(array) {
if (array.length === 1) {
return array;
}
Expand Down
37 changes: 30 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"clinic": "^13.0.0",
"eslint": "^9.11.1",
"eslint-config-scality": "github:scality/Guidelines#8.3.0",
"globals": "^15.11.0",
"jsdoc": "^4.0.3",
"mocha": "^10.7.3",
"nock": "^13.5.5",
Expand Down
8 changes: 4 additions & 4 deletions scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* curl -XGET http://host:port/mybucket/myboject
*/

const { createServer } = require('http');
const { readFileSync } = require('fs');
const werelogs = require('werelogs');
import { createServer } from 'http';
import { readFileSync } from 'fs';
import * as werelogs from 'werelogs';

const { hdcontroller } = require('../index');
import { hdcontroller } from '../index';

/* On DELETE, should we remove the object from the
* in-memory index?
Expand Down
9 changes: 2 additions & 7 deletions src/hdcontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export interface HDProxydOptions {
logApi: typeof werelogs;
}

// tslint:disable-next-line: interface-name
interface Headers {
[key: string]: string;
}

export class HDProxydClient {
private path: string;
public bootstrap: string[][];
Expand Down Expand Up @@ -248,8 +243,8 @@ export class HDProxydClient {
size: number, key: string, log: werelogs.RequestLogger,
callback: HDProxydCallback, params: Params,
payload: object | undefined): void {
// tslint:disable-next-line:no-any
const headers = ( params.headers ? params.headers : {}) as { 'content-length'?: number; [key: string]: any };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const headers = (params.headers ? params.headers : {}) as { 'content-length'?: number; [key: string]: any };
const req = this._createRequestHeader(method, headers, key, params,
log);
const host = this.getCurrentBootstrap();
Expand Down
2 changes: 1 addition & 1 deletion src/shuffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function nextBytes(numBytes: number): Buffer {
try {
return randomBytes(numBytes);
} catch (ex) {
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : "Unknown error"}`);
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : 'Unknown error'}`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"target": "es2016",
"alwaysStrict": true,
"skipLibCheck": true,
"module": "commonjs"
"module": "esnext",
"moduleResolution": "node",
},
"include": [
"./src/*"
Expand Down

0 comments on commit 48b96b8

Please sign in to comment.