Skip to content

Commit

Permalink
Fixup post review
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 24, 2024
1 parent 2fc70ad commit 7f6e5b4
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 54 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 };

24 changes: 12 additions & 12 deletions lib/hdcontroller.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
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");
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 {
constructor() {
super(...arguments);
Expand All @@ -33,7 +33,7 @@ function _createRequest(req, log, callback) {
return callback(error);
}
return callback(undefined, response);
}).on('error', (err) => {
}).on('error', err => {
if (!callbackCalled) {
callbackCalled = true;
return callback(err);
Expand Down Expand Up @@ -189,7 +189,7 @@ class HDProxydClient {
._failover(method, stream, size, key, counter, log, callback, params);
}
receivedResponse = true;
log.debug('request received response');
log.end('request received response');
return callback(err, ret);
}, args, payload);
}
Expand All @@ -198,7 +198,7 @@ class HDProxydClient {
* creation and its sending.
*/
_handleRequest(method, stream, size, key, log, callback, params, payload) {
//tslint:disable-next-line:no-any
const headers = (params.headers ? params.headers : {});
const req = this._createRequestHeader(method, headers, key, params, log);
const host = this.getCurrentBootstrap();
Expand Down Expand Up @@ -352,7 +352,7 @@ class HDProxydClient {
done(err);
}
}, {}, payload);
}, (err) => {
}, err => {
if (err) {
callback(err);
}
Expand All @@ -374,7 +374,7 @@ class HDProxydClient {
hostname: currentBootstrap[0],
port: currentBootstrap[1],
method: 'GET',
path: '/metrics', // XXX
path: '/metrics',
headers: {
'X-Scal-Request-Uids': logger.getSerializedUids(),
},
Expand Down
11 changes: 3 additions & 8 deletions lib/shuffle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
exports.shuffle = shuffle;
const cryptoLib = require("crypto");
const cryptoLib = require('crypto');
const randomBytes = cryptoLib.randomBytes;
/*
* This set of function allows us to create an efficient shuffle
Expand All @@ -23,12 +23,7 @@ function nextBytes(numBytes) {
return randomBytes(numBytes);
}
catch (ex) {
if (ex instanceof Error) {
throw new Error(`Insufficient entropy: ${ex.message}`);
}
else {
throw new Error('Insufficient entropy: Unknown error');
}
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : 'Unknown error'}`);
}
}
/*
Expand Down
38 changes: 31 additions & 7 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "tsc --strict ",
"coverage": "nyc --check-coverage --exclude 'tests/*' --lines=90 --reporter=text --reporter=html --reporter=lcov npm test tests/",
"jsdoc": "jsdoc src/ tests/ -d docs/jsdoc",
"lint": "eslint $(git ls-files '*.ts')",
"lint": "eslint $(git ls-files '*.ts' '*.js')",
"test": "mocha --require ts-node/register --use_strict --check-leaks --recursive tests/**/*.ts",
"get-version": "echo $npm_package_version"
},
Expand Down 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
17 changes: 5 additions & 12 deletions src/hdcontroller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict';

import * as assert from 'assert';
import * as async from 'async';
Expand Down 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 @@ -186,9 +181,7 @@ export class HDProxydClient {
reqHeaders['X-Scal-Request-Uids'] = reqUids;
reqHeaders['X-Scal-Trace-Ids'] = reqUids;
if (params && params.range) {

reqHeaders.Range = `bytes=${params.range[0]}-${params.range[1]}`;

}
let realPath: string;
if (key === '/job/delete') {
Expand Down Expand Up @@ -237,7 +230,7 @@ export class HDProxydClient {
callback, params);
}
receivedResponse = true;
log.debug('request received response');
log.end('request received response');
return callback(err, ret);
}, args, payload);
}
Expand All @@ -250,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 Expand Up @@ -430,7 +423,7 @@ export class HDProxydClient {
hostname: currentBootstrap[0],
port: currentBootstrap[1],
method: 'GET',
path: '/metrics', // XXX
path: '/metrics',
headers: {
'X-Scal-Request-Uids': logger.getSerializedUids(),
},
Expand Down
6 changes: 1 addition & 5 deletions src/shuffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ function nextBytes(numBytes: number): Buffer {
try {
return randomBytes(numBytes);
} catch (ex) {
if (ex instanceof Error) {
throw new Error(`Insufficient entropy: ${ex.message}`);
} else {
throw new Error('Insufficient entropy: Unknown error');
}
throw new Error(`Insufficient entropy: ${ex instanceof Error ? ex.message : 'Unknown error'}`);
}
}

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

0 comments on commit 7f6e5b4

Please sign in to comment.