Skip to content

Commit

Permalink
feat(1958): Upgrade to @hapi/hapi v20x.x. BREAKING CHANGE: new major …
Browse files Browse the repository at this point in the history
…data-schema

feat(1958): Upgrade to @hapi/hapi v20x.x. BREAKING CHANGE: new major data-schema
  • Loading branch information
pritamstyz4ever authored Sep 1, 2020
2 parents d91ad6b + 9fdabb7 commit b6713b0
Show file tree
Hide file tree
Showing 17 changed files with 436 additions and 285 deletions.
7 changes: 5 additions & 2 deletions bin/server
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ const strategyModule = `catbox-${strategyConfig.plugin}`;

// eslint-disable-next-line import/no-dynamic-require
const strategy = require(strategyModule);
const cache = Object.assign({ engine: strategy }, strategyConfig[strategyConfig.plugin]);

const cache = {
engine: new strategy({
...strategyConfig[strategyConfig.plugin]
})
};
const httpd = config.get('httpd');
const auth = config.get('auth');
const builds = config.get('builds');
Expand Down
5 changes: 3 additions & 2 deletions helpers/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const AWS = require('aws-sdk');
const stream = require('stream');
const Boom = require('boom');
const Boom = require('@hapi/boom');
const logger = require('screwdriver-logger');

class AwsClient {
Expand Down Expand Up @@ -179,8 +179,9 @@ class AwsClient {
req.on('httpHeaders', (statusCode) => {
if (statusCode >= 400) {
logger.error(`Fetch ${cacheKey} request failed: ${statusCode}`);
const error = new Error('Fetch cache request failed');

return reject(new Boom('Fetch cache request failed', { statusCode }));
return reject(Boom.boomify(error, { statusCode }));
}

return resolve(s3stream);
Expand Down
8 changes: 4 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');
const CORE_PLUGINS = [
'inert',
'vision',
'@hapi/inert',
'@hapi/vision',
'../plugins/status',
'../plugins/swagger',
'../plugins/logging',
Expand Down Expand Up @@ -56,7 +56,7 @@ module.exports = async (config) => {
router: {
stripTrailingSlash: true
},
cache: config.cache,
cache: [config.cache],
...config.httpd
});

Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "screwdriver-store",
"version": "1.0.0",
"version": "4.0.0",
"description": "Pluggable Artifact Store (for logs, shared steps, templates, etc).",
"main": "index.js",
"scripts": {
"pretest": "eslint .",
"test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --recursive --timeout 4000 --retries 1 --exit --allow-uncaught true --color true",
"start": "./bin/server",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"debug": "node --nolazy --inspect-brk=9229 ./bin/server"
"debug": "node --nolazy ./bin/server"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -59,27 +59,27 @@
"sinon": "^7.0.0"
},
"dependencies": {
"@hapi/boom": "^9.1.0",
"@hapi/catbox": "^11.1.0",
"@hapi/catbox-memory": "^5.0.0",
"@hapi/good": "^9.0.0",
"@hapi/good-console": "^9.0.0",
"@hapi/good-squeeze": "^6.0.0",
"@hapi/hapi": "^20.0.0",
"@hapi/hoek": "^9.0.4",
"@hapi/inert": "^6.0.1",
"@hapi/vision": "^6.0.0",
"aws-sdk": "^2.361.0",
"boom": "^7.2.2",
"catbox": "^10.0.5",
"catbox-disk": "^3.0.0",
"catbox-memory": "^3.1.4",
"catbox-disk": "^3.0.2",
"catbox-s3": "^4.0.0",
"cheerio": "^1.0.0-rc.3",
"config": "^1.30.0",
"good": "^8.1.1",
"good-console": "^7.1.0",
"good-squeeze": "^5.0.2",
"hapi": "^17.7.0",
"hapi-auth-jwt2": "^8.1.0",
"hapi-swagger": "^9.1.3",
"hoek": "^5.0.3",
"inert": "^5.1.2",
"joi": "13.1.2",
"hapi-auth-jwt2": "^10.1.0",
"hapi-swagger": "^13.0.2",
"joi": "^17.2.0",
"mime-types": "^2.1.25",
"request": "^2.88.0",
"screwdriver-data-schema": "^18.34.2",
"screwdriver-logger": "^1.0.0",
"vision": "^5.4.3"
"screwdriver-data-schema": "^20.0.0",
"screwdriver-logger": "^1.0.0"
}
}
16 changes: 8 additions & 8 deletions plugins/builds.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const joi = require('joi');
const boom = require('boom');
const boom = require('@hapi/boom');
const config = require('config');
const cheerio = require('cheerio');

Expand All @@ -13,7 +13,7 @@ const { getMimeFromFileExtension, displableMimes, knownMimes } = require('../hel
const SCHEMA_BUILD_ID = joi.number().integer().positive().label('Build ID');
const SCHEMA_ARTIFACT_ID = joi.string().label('Artifact ID');
const TYPE = joi.string().optional()
.valid(['download', 'preview'])
.valid('download', 'preview')
.label('Flag to trigger type either to download or preview');
const TOKEN = joi.string().label('Auth Token');
const DEFAULT_TTL = 24 * 60 * 60 * 1000; // 1 day
Expand Down Expand Up @@ -132,14 +132,14 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
id: SCHEMA_BUILD_ID,
artifact: SCHEMA_ARTIFACT_ID
},
query: {
}),
query: joi.object({
type: TYPE,
token: TOKEN
}
})
}
}
}, {
Expand Down Expand Up @@ -225,10 +225,10 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
id: SCHEMA_BUILD_ID,
artifact: SCHEMA_ARTIFACT_ID
}
})
}
}
}]);
Expand Down
20 changes: 10 additions & 10 deletions plugins/caches.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const joi = require('joi');
const boom = require('boom');
const boom = require('@hapi/boom');
const config = require('config');
const AwsClient = require('../helpers/aws');
const { streamToBuffer } = require('../helpers/helper');

const SCHEMA_SCOPE_NAME = joi.string().valid(['events', 'jobs', 'pipelines']).label('Scope Name');
const SCHEMA_SCOPE_NAME = joi.string().valid('events', 'jobs', 'pipelines').label('Scope Name');
const SCHEMA_SCOPE_ID = joi.number().integer().positive().label('Event/Job/Pipeline ID');
const SCHEMA_CACHE_NAME = joi.string().label('Cache Name');

Expand Down Expand Up @@ -153,11 +153,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
scope: SCHEMA_SCOPE_NAME,
id: SCHEMA_SCOPE_ID,
cacheName: SCHEMA_CACHE_NAME
}
})
}
}
}, {
Expand Down Expand Up @@ -283,11 +283,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
scope: SCHEMA_SCOPE_NAME,
id: SCHEMA_SCOPE_ID,
cacheName: SCHEMA_CACHE_NAME
}
})
}
}
}, {
Expand Down Expand Up @@ -363,11 +363,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
scope: SCHEMA_SCOPE_NAME,
id: SCHEMA_SCOPE_ID,
cacheName: SCHEMA_CACHE_NAME
}
})
}
}
}, {
Expand Down Expand Up @@ -414,10 +414,10 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
scope: SCHEMA_SCOPE_NAME,
id: SCHEMA_SCOPE_ID
}
})
}
}
}]);
Expand Down
15 changes: 8 additions & 7 deletions plugins/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const boom = require('boom');
const joi = require('joi');
const boom = require('@hapi/boom');
const schema = require('screwdriver-data-schema');
const SCHEMA_COMMAND_NAMESPACE = schema.config.command.namespace;
const SCHEMA_COMMAND_NAME = schema.config.command.name;
Expand Down Expand Up @@ -66,11 +67,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
namespace: SCHEMA_COMMAND_NAMESPACE,
name: SCHEMA_COMMAND_NAME,
version: SCHEMA_COMMAND_VERSION
}
})
}
}
}, {
Expand Down Expand Up @@ -124,11 +125,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
namespace: SCHEMA_COMMAND_NAMESPACE,
name: SCHEMA_COMMAND_NAME,
version: SCHEMA_COMMAND_VERSION
}
})
}
}
}, {
Expand Down Expand Up @@ -163,11 +164,11 @@ exports.plugin = {
}
},
validate: {
params: {
params: joi.object({
namespace: SCHEMA_COMMAND_NAMESPACE,
name: SCHEMA_COMMAND_NAME,
version: SCHEMA_COMMAND_VERSION
}
})
}
}
}]);
Expand Down
6 changes: 3 additions & 3 deletions plugins/logging.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';

const good = require('good');
const good = require('@hapi/good');

const options = {
ops: {
interval: 1000
},
reporters: {
console: [{
module: 'good-squeeze',
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [{ error: '*', log: '*', response: '*', request: '*' }]
}, {
module: 'good-console'
module: '@hapi/good-console'
}, 'stdout']
}
};
Expand Down
10 changes: 7 additions & 3 deletions test/lib/server.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { assert } = require('chai');
const engine = require('catbox-memory');
const Catbox = require('@hapi/catbox-memory');

describe('server case', function () {
// Time not important. Only life important.
Expand Down Expand Up @@ -35,7 +35,9 @@ describe('server case', function () {
httpd: {
port: 12347
},
cache: { engine },
cache: {
engine: new Catbox()
},
auth: {
jwtPublicKey: '12345'
},
Expand Down Expand Up @@ -71,7 +73,9 @@ describe('server case', function () {
httpd: {
port: 12347
},
cache: { engine },
cache: {
engine: new Catbox()
},
commands: {},
ecosystem
})
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { assert } = require('chai');
const sinon = require('sinon');
const Hapi = require('hapi');
const Hapi = require('@hapi/hapi');
const jwt = require('jsonwebtoken');
const fs = require('fs');
const path = require('path');
Expand Down
Loading

0 comments on commit b6713b0

Please sign in to comment.