Skip to content

Commit

Permalink
prettier v2 formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
leontastic committed Mar 4, 2021
1 parent 6083bd8 commit eaa43c3
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 293 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Example in mocha:
const S3rver = require('s3rver');
let instance;

before(function(done) {
before(function (done) {
instance = new S3rver({
port: 4569,
hostname: 'localhost',
Expand All @@ -163,7 +163,7 @@ before(function(done) {
}).run(done);
});

after(function(done) {
after(function (done) {
instance.close(done);
});
```
Expand Down Expand Up @@ -209,10 +209,10 @@ const instance = new S3rver({
});

const s3Events = fromEvent(instance, 'event');
s3Events.subscribe(event => console.log(event));
s3Events.subscribe((event) => console.log(event));
s3Events
.pipe(filter(event => event.Records[0].eventName == 'ObjectCreated:Copy'))
.subscribe(event => console.log(event));
.pipe(filter((event) => event.Records[0].eventName == 'ObjectCreated:Copy'))
.subscribe((event) => console.log(event));
```

## Using [s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse) with S3rver
Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ exports.getBucket = async function getBucket(ctx) {
MaxKeys: ctx.query['max-keys'] || 1000, // S3 has a hard limit at 1000 but will still echo back the original input
Delimiter: options.delimiter || undefined, // omit when "" or undefined
IsTruncated: result.isTruncated || false,
Contents: result.objects.map(object => ({
Contents: result.objects.map((object) => ({
Key: object.key,
LastModified: object.lastModifiedDate.toISOString(),
ETag: object.metadata.etag,
Expand All @@ -276,7 +276,7 @@ exports.getBucket = async function getBucket(ctx) {
: undefined,
StorageClass: 'STANDARD',
})),
CommonPrefixes: result.commonPrefixes.map(prefix => ({
CommonPrefixes: result.commonPrefixes.map((prefix) => ({
Prefix: prefix,
})),
},
Expand Down
14 changes: 7 additions & 7 deletions lib/controllers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function xmlBodyParser(ctx) {
const { req } = ctx;
const xmlString = await new Promise((resolve, reject) => {
let payload = '';
req.on('data', data => (payload += data.toString('utf8')));
req.on('data', (data) => (payload += data.toString('utf8')));
req.on('end', () => resolve(payload));
req.on('error', reject);
});
Expand All @@ -29,7 +29,7 @@ async function xmlBodyParser(ctx) {
);
}
ctx.request.body = xmlParser.parse(xmlString, {
tagValueProcessor: a => he.decode(a),
tagValueProcessor: (a) => he.decode(a),
});
}

Expand Down Expand Up @@ -76,9 +76,9 @@ exports.deleteMultipleObjects = async function deleteMultipleObjects(ctx) {
'our published schema.',
);
}
const keys = [].concat(ctx.request.body.Delete.Object).map(o => o.Key);
const keys = [].concat(ctx.request.body.Delete.Object).map((o) => o.Key);
await Promise.all(
keys.map(async key => {
keys.map(async (key) => {
const objectExists = await ctx.store.existsObject(ctx.params.bucket, key);
if (!objectExists) return;

Expand All @@ -93,7 +93,7 @@ exports.deleteMultipleObjects = async function deleteMultipleObjects(ctx) {
ctx.body = {
DeleteResult: {
'@': { xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/' },
Deleted: keys.map(k => ({ Key: k })),
Deleted: keys.map((k) => ({ Key: k })),
},
};
};
Expand Down Expand Up @@ -286,7 +286,7 @@ exports.postObject = async function postObject(ctx) {
let key;
const metadata = {};

const errorHandler = err => {
const errorHandler = (err) => {
busboy.off('field', fieldHandler);
busboy.off('file', fileHandler);
reject(err);
Expand Down Expand Up @@ -632,7 +632,7 @@ exports.completeMultipartUpload = async function completeMultipartUpload(ctx) {
}
const parts = []
.concat(ctx.request.body.CompleteMultipartUpload.Part)
.map(part => ({
.map((part) => ({
number: Number(part.PartNumber),
// S3 removes all double quotes when comparing etags
etag: part.ETag.replace(/"/g, ''),
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.getService = async function getService(ctx) {
DisplayName: DUMMY_ACCOUNT.displayName,
},
Buckets: {
Bucket: buckets.map(bucket => ({
Bucket: buckets.map((bucket) => ({
Name: bucket.name,
CreationDate: bucket.creationDate.toISOString(),
})),
Expand Down
24 changes: 8 additions & 16 deletions lib/middleware/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ module.exports = () =>
.join('&');

const canonicalizedAmzHeaders = Object.keys(ctx.headers)
.filter(headerName => headerName.startsWith('x-amz-'))
.filter((headerName) => headerName.startsWith('x-amz-'))
.sort()
.map(
headerName =>
(headerName) =>
`${headerName}:${ctx.get(headerName).replace(/ +/g, ' ')}`,
);

Expand Down Expand Up @@ -314,7 +314,7 @@ function parseHeader(headers) {
components
.join('')
.split(',')
.map(component => {
.map((component) => {
const [key, ...value] = component.split('=');
return [key, value.join('=')];
}),
Expand Down Expand Up @@ -528,7 +528,7 @@ function getStringToSignV2(canonicalRequest) {
*/
function getStringToSignV4(canonicalRequest, { credential, signedHeaders }) {
const canonicalHeaders = signedHeaders
.map(header => `${header}:${canonicalRequest.headers[header]}\n`)
.map((header) => `${header}:${canonicalRequest.headers[header]}\n`)
.join('');

// skip computing content sha
Expand All @@ -554,9 +554,7 @@ function getStringToSignV4(canonicalRequest, { credential, signedHeaders }) {
credential.service,
credential.termination,
].join('/'),
createHash('sha256')
.update(canonicalRequestString)
.digest('hex'),
createHash('sha256').update(canonicalRequestString).digest('hex'),
].join('\n');
}

Expand Down Expand Up @@ -589,19 +587,13 @@ function calculateSignatureV4(stringToSign, secretKey, date, region, service) {
.update(date)
.digest();

const regionKey = createHmac('sha256', dateKey)
.update(region)
.digest();
const regionKey = createHmac('sha256', dateKey).update(region).digest();

const serviceKey = createHmac('sha256', regionKey)
.update(service)
.digest();
const serviceKey = createHmac('sha256', regionKey).update(service).digest();

const signingKey = createHmac('sha256', serviceKey)
.update('aws4_request')
.digest();

return createHmac('sha256', signingKey)
.update(stringToSign)
.digest('hex');
return createHmac('sha256', signingKey).update(stringToSign).digest('hex');
}
8 changes: 5 additions & 3 deletions lib/middleware/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ module.exports = () =>

const allowedHeaders = matchedRule
? requestHeaders
.map(header => header.trim().toLowerCase())
.filter(header =>
matchedRule.allowedHeaders.some(pattern => pattern.test(header)),
.map((header) => header.trim().toLowerCase())
.filter((header) =>
matchedRule.allowedHeaders.some((pattern) =>
pattern.test(header),
),
)
: [];

Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { createLogger, format, transports } = require('winston');
/**
* Creates and assigns a Winston logger instance to an app and returns
*/
module.exports = function(app, silent) {
module.exports = function (app, silent) {
const logger = createLogger({
transports: [
new transports.Console({
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ exports = module.exports = () =>
// Only 404s are supported for RoutingRules right now, this may be a deviation from S3 behaviour but we don't
// have a reproduction of a scenario where S3 does a redirect on a status code other than 404. If you're
// reading this comment and you have a use-case, please raise an issue with details of your scenario. Thanks!
const routingRule = (config.routingRules || []).find(rule =>
const routingRule = (config.routingRules || []).find((rule) =>
rule.shouldRedirect(key, 404),
);
if (!routingRule) {
Expand Down Expand Up @@ -141,8 +141,8 @@ function redirect(url) {
const { res } = this;
res
.getHeaderNames()
.filter(name => !name.match(/^access-control-|vary|x-amz-/i))
.forEach(name => res.removeHeader(name));
.filter((name) => !name.match(/^access-control-|vary|x-amz-/i))
.forEach((name) => res.removeHeader(name));

this.set('Location', url);

Expand Down Expand Up @@ -197,8 +197,8 @@ async function onerror(err) {
// first unset all headers
res
.getHeaderNames()
.filter(name => !name.match(/^access-control-|vary|x-amz-/i))
.forEach(name => res.removeHeader(name));
.filter((name) => !name.match(/^access-control-|vary|x-amz-/i))
.forEach((name) => res.removeHeader(name));

// (the presence of x-amz-error-* headers needs additional research)
// this.set(err.headers);
Expand Down
18 changes: 9 additions & 9 deletions lib/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,34 @@ class S3CorsConfiguration extends S3ConfigBase {
constructor(config) {
super('cors', config);
const { CORSConfiguration = {} } = this.rawConfig;
this.rules = [].concat(CORSConfiguration.CORSRule || []).map(rule => ({
this.rules = [].concat(CORSConfiguration.CORSRule || []).map((rule) => ({
hasWildcardOrigin: [].concat(rule.AllowedOrigin || []).includes('*'),
allowedOrigins: []
.concat(rule.AllowedOrigin || [])
.map(o => S3CorsConfiguration.createWildcardRegExp(o)),
.map((o) => S3CorsConfiguration.createWildcardRegExp(o)),
allowedMethods: [].concat(rule.AllowedMethod || []),
allowedHeaders: []
.concat(rule.AllowedHeader || [])
.map(h => S3CorsConfiguration.createWildcardRegExp(h, 'i')),
.map((h) => S3CorsConfiguration.createWildcardRegExp(h, 'i')),
exposeHeaders: [].concat(rule.ExposeHeader || []),
maxAgeSeconds: rule.MaxAgeSeconds,
}));
}

matchRule(origin, method) {
return this.rules.find(
rule =>
rule.allowedOrigins.some(pattern => pattern.test(origin)) &&
(rule) =>
rule.allowedOrigins.some((pattern) => pattern.test(origin)) &&
rule.allowedMethods.includes(method.toUpperCase()),
);
}

getAllowedHeaders(rule, requestHeaders) {
if (!requestHeaders) return [];
return requestHeaders
.map(header => header.trim().toLowerCase())
.filter(header =>
rule.allowedHeaders.some(pattern => pattern.test(header)),
.map((header) => header.trim().toLowerCase())
.filter((header) =>
rule.allowedHeaders.some((pattern) => pattern.test(header)),
);
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ class S3WebsiteConfiguration extends S3ConfigBase {
)
? WebsiteConfiguration.RoutingRules.RoutingRule
: [WebsiteConfiguration.RoutingRules.RoutingRule];
this.routingRules = routingRules.map(config => new RoutingRule(config));
this.routingRules = routingRules.map((config) => new RoutingRule(config));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/models/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class S3Error extends Error {

toXML() {
const parser = new j2xParser({
tagValueProcessor: a =>
tagValueProcessor: (a) =>
he.encode(a.toString(), { useNamedReferences: true }),
});
return [
Expand All @@ -49,7 +49,7 @@ class S3Error extends Error {
}

toHTML() {
const encode = a => he.encode(a.toString(), { useNamedReferences: true });
const encode = (a) => he.encode(a.toString(), { useNamedReferences: true });
return [
// Real S3 doesn't respond with DOCTYPE
'<html>',
Expand All @@ -65,7 +65,7 @@ class S3Error extends Error {
.join('\n'),
'</ul>',
(this.errors || [])
.map(error =>
.map((error) =>
[
`<h3>${encode(error.description)}</h3>`,
'<ul>',
Expand Down
4 changes: 1 addition & 3 deletions lib/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class S3Event {
let eventName = '';
const s3Object = {
key: eventData.S3Item.key,
sequencer: Date.now()
.toString(16)
.toUpperCase(),
sequencer: Date.now().toString(16).toUpperCase(),
};
switch (eventData.eventType) {
case 'Copy':
Expand Down
Loading

0 comments on commit eaa43c3

Please sign in to comment.