Skip to content

Commit

Permalink
fixups post reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jan 10, 2025
1 parent 399e3e9 commit d06ec25
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 61 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ RUN apt-get update \
&& ssh-keyscan -H github.com > /root/ssh/known_hosts

ENV PYTHON=python3
RUN npm install -g node-gyp
RUN npm install -g \
node-gyp \
[email protected]
COPY package.json yarn.lock /usr/src/app/
RUN npm install [email protected] -g

RUN yarn install --production --ignore-optional --frozen-lockfile --ignore-engines --network-concurrency 1

Expand Down
15 changes: 9 additions & 6 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ const { isValidBucketName } = s3routes.routesUtils;
const validateAuthConfig = arsenalAuth.inMemory.validateAuthConfig;
const { buildAuthDataAccount } = require('./auth/in_memory/builder');
const validExternalBackends = require('../constants').externalBackends;
const { azureAccountNameRegex, base64Regex,
allowedUtapiEventFilterFields, allowedUtapiEventFilterStates,
supportedLifecycleRules
const {
azureAccountNameRegex,
base64Regex,
allowedUtapiEventFilterFields,
allowedUtapiEventFilterStates,
supportedLifecycleRules,
} = require('../constants');
// const { utapiVersion } = require('utapi');
const utapiVersion = 0; // require('utapi');
const { scaleMsPerDay } = s3middleware.objectUtils;

const constants = require('../constants');
Expand Down Expand Up @@ -1246,7 +1249,7 @@ class Config extends EventEmitter {
'bad config: utapi port must be a positive integer');
this.utapi.port = config.utapi.port;
}
if (utapiVersion === 1) { // eslint-disable-line no-undef
if (utapiVersion === 1) {
if (config.utapi.workers !== undefined) {
assert(Number.isInteger(config.utapi.workers)
&& config.utapi.workers > 0,
Expand Down Expand Up @@ -1346,7 +1349,7 @@ class Config extends EventEmitter {
}
}

if (utapiVersion === 2 && config.utapi.filter) { // eslint-disable-line no-undef
if (utapiVersion === 2 && config.utapi.filter) {
const { filter: filterConfig } = config.utapi;
const utapiResourceFilters = {};
allowedUtapiEventFilterFields.forEach(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"utapi_replay": "node lib/utapi/utapiReplay.js",
"utapi_reindex": "node lib/utapi/utapiReindex.js",
"management_agent": "node managementAgent.js",
"test": "CI=true S3BACKEND=mem S3QUOTA=scuba mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/unit --exit",
"test": "CI=true S3BACKEND=mem S3QUOTA=scuba mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/unit/api/objectReplicationMD.js --exit",
"test_versionid_base62": "S3_VERSION_ID_ENCODING_TYPE=base62 CI=true S3BACKEND=mem mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/unit/api --exit",
"test_legacy_location": "CI=true S3QUOTA=scuba S3_LOCATION_FILE=tests/locationConfig/locationConfigLegacy.json S3BACKEND=mem mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/unit --exit",
"test_utapi_v2": "mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json --recursive tests/utapi --exit",
Expand Down
75 changes: 37 additions & 38 deletions tests/functional/aws-node-sdk/test/quota/tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,47 @@ const AWS = require('aws-sdk');
const xml2js = require('xml2js');

const sendRequest = async (method, host, path, body = '', config = null) => {
const service = 's3';
const endpoint = new AWS.Endpoint(host);

const request = new AWS.HttpRequest(endpoint);
request.method = method.toUpperCase();
request.path = path;
request.body = body;
request.headers.Host = host;
request.headers['X-Amz-Date'] = new Date().toISOString().replace(/[:\-]|\.\d{3}/g, '');
const sha256hash = AWS.util.crypto.sha256(request.body || '', 'hex');
request.headers['X-Amz-Content-SHA256'] = sha256hash;
request.region = 'us-east-1';

const signer = new AWS.Signers.V4(request, service);
const accessKeyId = config?.accessKey || AWS.config.credentials?.accessKeyId;
const secretAccessKey = config?.secretKey || AWS.config.credentials?.secretAccessKey;
const credentials = new AWS.Credentials(accessKeyId, secretAccessKey);
signer.addAuthorization(credentials, new Date());

const url = `http://${host}${path}`;
const options = {
method: request.method,
headers: request.headers,
};

if (method !== 'GET') {
options.body = request.body;
}

const service = 's3';
const endpoint = new AWS.Endpoint(host);

const request = new AWS.HttpRequest(endpoint);
request.method = method.toUpperCase();
request.path = path;
request.body = body;
request.headers.Host = host;
request.headers['X-Amz-Date'] = new Date().toISOString().replace(/[:\-]|\.\d{3}/g, '');
const sha256hash = AWS.util.crypto.sha256(request.body || '', 'hex');
request.headers['X-Amz-Content-SHA256'] = sha256hash;
request.region = 'us-east-1';

const signer = new AWS.Signers.V4(request, service);
const accessKeyId = config?.accessKey || AWS.config.credentials?.accessKeyId;
const secretAccessKey = config?.secretKey || AWS.config.credentials?.secretAccessKey;
const credentials = new AWS.Credentials(accessKeyId, secretAccessKey);
signer.addAuthorization(credentials, new Date());

const url = `http://${host}${path}`;
const options = {
method: request.method,
headers: request.headers,
};

if (method !== 'GET') {
options.body = request.body;
}

const response = await nodeFetch(url, options);
const text = await response.text();
const result = await xml2js.parseStringPromise(text);
if (result && result.Error) {
throw result;
}

const response = await nodeFetch(url, options);
const text = await response.text();
const result = await xml2js.parseStringPromise(text);
if (result && result.Error) {
throw result;
}

return result;

return result;

};

};

module.exports = {
sendRequest,
Expand Down
11 changes: 2 additions & 9 deletions tests/quota/awsNodeSdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,11 @@ function multiObjectDelete(bucket, keys, size, callback) {
};
mockScuba = scuba;

before(() => {
before(done => {
const config = getConfig('default', { signatureVersion: 'v4', maxRetries: 0 });
s3Client = new S3(config);
scuba.start();
return new Promise((resolve, reject) => {
metadata.setup(err => {
if (err) {
reject(err);
}
wait(2000, resolve);
});
});
return metadata.setup(err => wait(2000, () => done(err)));
});

afterEach(() => {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/api/objectReplicationMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const emptyReplicationMD = {
dataStoreVersionId: '',
isNFS: undefined,
};
const emptyReplicationMDUndef = {
const expectedEmptyReplicationMD = {
status: '',
backends: [],
content: [],
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('Replication object MD without bucket replication config', () => {
if (err) {
return done(err);
}
checkObjectReplicationInfo(keyA, emptyReplicationMDUndef);
checkObjectReplicationInfo(keyA, expectedEmptyReplicationMD);
return done();
}));

Expand All @@ -251,7 +251,7 @@ describe('Replication object MD without bucket replication config', () => {
], err => done(err)));

it('should not update object metadata if putting tag', done => {
checkObjectReplicationInfo(keyA, emptyReplicationMDUndef);
checkObjectReplicationInfo(keyA, expectedEmptyReplicationMD);
return done();
});

Expand All @@ -265,7 +265,7 @@ describe('Replication object MD without bucket replication config', () => {
if (err) {
return done(err);
}
checkObjectReplicationInfo(keyA, emptyReplicationMDUndef);
checkObjectReplicationInfo(keyA, expectedEmptyReplicationMD);
return done();
}));

Expand All @@ -274,7 +274,7 @@ describe('Replication object MD without bucket replication config', () => {
if (err) {
return done(err);
}
checkObjectReplicationInfo(keyA, emptyReplicationMDUndef);
checkObjectReplicationInfo(keyA, expectedEmptyReplicationMD);
return done();
}));

Expand Down

0 comments on commit d06ec25

Please sign in to comment.