Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Sep 30, 2024
1 parent 19a82f1 commit 2c82399
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 318 deletions.
28 changes: 23 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

import tseslint from 'typescript-eslint';


const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
Expand All @@ -11,9 +14,24 @@ const compat = new FlatCompat({
allConfig: js.configs.all
});

export default [...compat.extends("scality"), {
languageOptions: {
ecmaVersion: 2020,
sourceType: "script",
export default tseslint.config(
...compat.extends('scality'),
...tseslint.configs.recommended,
{
ignores: [
'**/.vscode',
'**/vendor/*.js',
'**/build',
'**/coverage',
'**/dist',
'**/node_modules',
'**/package',
'**/lib',
'**/scripts',
'**/eslint.config.mjs',
],
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
}];
);
2 changes: 0 additions & 2 deletions lib/RequestLogger.js

This file was deleted.

20 changes: 9 additions & 11 deletions lib/hdcontroller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'; // eslint-disable-line strict
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.HDProxydClient = exports.HDProxydError = void 0;
const assert = require("assert");
Expand All @@ -19,7 +19,7 @@ exports.HDProxydError = HDProxydError;
*/
function _createRequest(req, log, callback) {
let callbackCalled = false;
const request = http.request(req, (response) => {
const request = http.request(req, response => {
callbackCalled = true;
// Get range returns a 206
// Concurrent deletes on hdproxyd/immutable keys returns 423
Expand All @@ -41,6 +41,7 @@ function _createRequest(req, log, callback) {
if (err.code !== 'ERR_SOCKET_TIMEOUT') {
log.error('got socket error after response', { err });
}
return null;
});
// disable nagle algorithm
request.setNoDelay(true);
Expand All @@ -55,7 +56,7 @@ function _createRequest(req, log, callback) {
* maintain.
*/
function _parseBootstrapList(list) {
return list.map((value) => value.split(':'));
return list.map(value => value.split(':'));
}
class HDProxydClient {
/**
Expand Down Expand Up @@ -144,9 +145,7 @@ class HDProxydClient {
reqHeaders['X-Scal-Request-Uids'] = reqUids;
reqHeaders['X-Scal-Trace-Ids'] = reqUids;
if (params && params.range) {
/* eslint-disable dot-notation */
reqHeaders.Range = `bytes=${params.range[0]}-${params.range[1]}`;
/* eslint-enable dot-notation */
}
let realPath;
if (key === '/job/delete') {
Expand Down Expand Up @@ -227,7 +226,7 @@ class HDProxydClient {
contentLength: size,
}));
stream.pipe(request);
stream.on('error', (err) => {
stream.on('error', err => {
log.error('error from readable stream', {
error: err,
method: '_handleRequest',
Expand Down Expand Up @@ -278,9 +277,8 @@ class HDProxydClient {
return callback(new HDProxydError('no key returned'));
}
const key = response.headers['scal-key'];
response.on('end', () => {
return callback(undefined, key);
});
response.on('end', () => callback(undefined, key));
return null;
}, params);
}
/**
Expand Down Expand Up @@ -332,7 +330,7 @@ class HDProxydClient {
*/
batchDelete(list, reqUids, callback) {
assert.strictEqual(typeof list, 'object');
assert(list.keys.every((k) => typeof k === 'string'));
assert(list.keys.every(k => typeof k === 'string'));
// split the list into batches of 1000 each
const batches = [];
while (list.keys.length > 0) {
Expand Down Expand Up @@ -375,7 +373,7 @@ class HDProxydClient {
hostname: currentBootstrap[0],
port: currentBootstrap[1],
method: 'GET',
path: '/metrics',
path: '/metrics', // XXX
headers: {
'X-Scal-Request-Uids': logger.getSerializedUids(),
},
Expand Down
16 changes: 10 additions & 6 deletions lib/shuffle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'; // eslint-disable-line strict
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.shuffle = void 0;
const crypto = require("crypto");
const randomBytes = crypto.randomBytes;
exports.shuffle = shuffle;
const cryptoLib = require("crypto");
const randomBytes = cryptoLib.randomBytes;
/*
* This set of function allows us to create an efficient shuffle
* of our array, since Math.random() will not be enough (32 bits of
Expand All @@ -23,7 +23,12 @@ function nextBytes(numBytes) {
return randomBytes(numBytes);
}
catch (ex) {
throw new Error('Insufficient entropy');
if (ex instanceof Error) {
throw new Error(`Insufficient entropy: ${ex.message}`);
}
else {
throw new Error('Insufficient entropy: Unknown error');
}
}
}
/*
Expand Down Expand Up @@ -68,4 +73,3 @@ function shuffle(array) {
}
return array;
}
exports.shuffle = shuffle;
5 changes: 3 additions & 2 deletions 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 '*.js')",
"lint": "eslint $(git ls-files '*.ts')",
"test": "mocha --require ts-node/register --use_strict --check-leaks --recursive tests/**/*.ts",
"get-version": "echo $npm_package_version"
},
Expand Down Expand Up @@ -55,7 +55,8 @@
"nyc": "^17.1.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"typescript-eslint": "^8.7.0"
},
"license": "Apache-2.0",
"bugs": {
Expand Down
18 changes: 8 additions & 10 deletions scripts/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* eslint-disable strict */
/* eslint-disable prefer-destructuring */
/* eslint-disable no-bitwise */
/* eslint-disable no-console */

'use strict';

/**
Expand All @@ -16,10 +11,11 @@
* curl -XGET http://host:port/mybucket/myboject
*/

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

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

/* On DELETE, should we remove the object from the
* in-memory index?
Expand All @@ -29,6 +25,8 @@ import { hdcontroller } from '../index';
*/
let removeMemIndexOnDelete = true;

const log = new werelogs.Logger('server');

function getHyperdriveClient(config) {
return new hdcontroller.HDProxydClient(config);
}
Expand Down Expand Up @@ -162,7 +160,7 @@ function loadConfig(file) {
function main() {
const args = process.argv;
if (args.length < 4) {
console.error(`Usage: <port> <conf path> <memindexnodel>
log.error(`Usage: <port> <conf path> <memindexnodel>
{Number} port to listen on
{String} path to HyperdriveClient json config
{*} don't remove in-memory keys on DELETE (used to check
Expand All @@ -183,7 +181,7 @@ function main() {
const server = createServer(
(req, res) => serverCallback(client, object2rawkey, req, res),
);
server.listen(port, () => console.log('Listening on %d',
server.listen(port, () => log.info('Listening on %d',
server.address().port));
server.on('connection', socket => socket.setNoDelay(true));
}
Expand Down
11 changes: 0 additions & 11 deletions src/RequestLogger.ts

This file was deleted.

Loading

0 comments on commit 2c82399

Please sign in to comment.