Skip to content

Commit

Permalink
feat(http): ignore meaningless x-oada-ensure-link
Browse files Browse the repository at this point in the history
no longer results in 422 on non-PUT/POST
  • Loading branch information
awlayton committed Oct 10, 2024
1 parent 54ace69 commit 1ccd758
Show file tree
Hide file tree
Showing 19 changed files with 1,151 additions and 1,123 deletions.
2 changes: 1 addition & 1 deletion oada/libs/lib-arangodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@types/deep-equal": "^1.0.4",
"@types/flat": "^5.0.5",
"@types/json-pointer": "^1.0.34",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"ava": "6.1.3",
"type-fest": "^4.26.1"
},
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-kafka/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/uuid": "^10.0.0",
"ava": "6.1.3"
},
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/lib-prom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@types/convict": "^6.1.6",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/ws": "^8.5.12",
"ava": "6.1.3",
"fastify-plugin": "^5.0.1"
Expand Down
2 changes: 1 addition & 1 deletion oada/libs/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"node": "22.5.1"
},
"devDependencies": {
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"jose": "^5.9.3"
}
}
4 changes: 2 additions & 2 deletions oada/libs/pino-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3"
"@types/node": "^22.7.5"
},
"peerDependencies": {
"debug": "*"
},
"volta": {
"node": "22.5.1"
}
}
}
37 changes: 19 additions & 18 deletions oada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/compat": "^1.1.1",
"@eslint/compat": "^1.2.0",
"@eslint/config-inspector": "^0.5.4",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"@eslint/js": "^9.12.0",
"@tsconfig/node20": "^20.1.4",
"@types/eslint": "^9.6.1",
"@types/mocha": "^10.0.8",
"@types/node": "^22.7.3",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"@types/mocha": "^10.0.9",
"@types/node": "^22.7.5",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@yarnpkg/sdks": "^3.2.0",
"browserslist": "^4.24.0",
"c8": "^10.1.2",
"eslint": "^9.11.1",
"eslint": "^9.12.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.46.0",
"eslint-config-xo-typescript": "^7.0.0",
Expand All @@ -42,8 +42,8 @@
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^5.0.2",
"eslint-plugin-i18n-text": "^1.0.1",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-no-constructor-bind": "^2.0.4",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-no-secrets": "^1.0.2",
Expand All @@ -53,23 +53,24 @@
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-sonarjs": "^2.0.2",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-sonarjs": "^2.0.3",
"eslint-plugin-unicorn": "^56.0.0",
"get-port": "^7.1.0",
"prettier": "^3.3.3",
"tslib": "2.7.0",
"typescript": "5.6.2",
"typescript-eslint": "^8.7.0",
"update-browserslist-db": "^1.1.0",
"zx": "^8.1.8"
"typescript": "5.6.3",
"typescript-eslint": "^8.8.1",
"update-browserslist-db": "^1.1.1",
"zx": "^8.1.9"
},
"dependencies": {
"pino-pretty": "^11.2.2"
},
"resolutions": {
"@fastify/jwt": "^8.0.0",
"fastify-plugin": "4.0.0",
"tslib": "2.6.2"
"@fastify/jwt": "^9.0.1",
"fastify-jwt-jwks": "https:/nearform/fastify-jwt-jwks.git",
"fastify-plugin": "^5.0.1",
"tslib": "2.7.0"
},
"engines": {
"node": ">=20.0.0"
Expand Down
2 changes: 1 addition & 1 deletion oada/services/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@fastify/helmet": "^12.0.1",
"@fastify/jwt": "^9.0.1",
"@fastify/passport": "^3.0.1",
"@fastify/rate-limit": "^10.1.0",
"@fastify/rate-limit": "^10.1.1",
"@fastify/request-context": "^6.0.1",
"@fastify/secure-session": "^8.1.0",
"@fastify/sensible": "^6.0.1",
Expand Down
16 changes: 8 additions & 8 deletions oada/services/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { mixins, pino } from '@oada/pino-debug';
import { mixins } from '@oada/pino-debug';

import { config, domainConfigs } from './config.js';

Expand Down Expand Up @@ -355,15 +355,17 @@ export async function start(): Promise<void> {
jwt: serializeJwt,
id_token: serializeJwt,
};
const logger = pino({ serializers });

mixins.push(() => ({
reqId: requestContext.get('id'),
}));

const fastify = Fastify({
trustProxy,
logger,
logger: {
// @ts-expect-error fastify types bs
serializers,
},
ignoreTrailingSlash: true,
ajv: {
customOptions: {
Expand Down Expand Up @@ -400,10 +402,8 @@ export async function start(): Promise<void> {
port,
host: '::',
});
if (logger.isLevelEnabled('debug')) {
const routes = fastify.printRoutes();
fastify.log.debug({ fastify }, `Server running\n${routes}`);
}
const routes = fastify.printRoutes();
fastify.log.debug({ fastify }, `Server running\n${routes}`);
} catch (error: unknown) {
fastify.log.fatal(error, 'Failed to start server');
throw error;
Expand All @@ -414,7 +414,7 @@ if (esMain(import.meta)) {
try {
await start();
} catch (error: unknown) {

console.error(error);
// eslint-disable-next-line unicorn/no-process-exit, n/no-process-exit
process.exit(1);
Expand Down
10 changes: 5 additions & 5 deletions oada/services/http-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@fastify/bearer-auth": "^10.0.1",
"@fastify/cors": "^10.0.1",
"@fastify/helmet": "^12.0.1",
"@fastify/rate-limit": "^10.1.0",
"@fastify/rate-limit": "^10.1.1",
"@fastify/request-context": "^6.0.1",
"@fastify/sensible": "^6.0.1",
"@fastify/websocket": "^11.0.1",
Expand All @@ -56,7 +56,7 @@
"@oada/permissions-handler": "workspace:^",
"@oada/pino-debug": "workspace:^",
"@oada/types": "^4.0.0",
"cacache": "^19.0.0",
"cacache": "^19.0.1",
"debug": "^4.3.7",
"es-main": "^1.3.0",
"eventemitter3": "^5.0.1",
Expand All @@ -79,13 +79,13 @@
"@oada/write-handler": "workspace:^",
"@types/cacache": "^17.0.2",
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/type-is": "^1.6.6",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.12",
"connect": "^3.7.0",
"find-my-way": "^9.0.1",
"light-my-request": "^6.0.0",
"find-my-way": "^9.1.0",
"light-my-request": "^6.1.0",
"type-fest": "^4.26.1"
},
"volta": {
Expand Down
6 changes: 3 additions & 3 deletions oada/services/http-handler/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function parseETag(etag: string): { id?: string; rev: number } {
*/
// eslint-disable-next-line @typescript-eslint/require-await
const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {

// @ts-expect-error null is allowed the types are wrong
fastify.decorateRequest('oadaPath', null);

Expand Down Expand Up @@ -483,8 +483,8 @@ const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {
url: '*',
method: ['HEAD', 'GET', 'DELETE'],
// eslint-disable-next-line @typescript-eslint/require-await
async handler(_request, reply) {
void reply.badRequest('X-OADA-Ensure-Link not allowed for this method');
async handler(request) {
request.log.warn('X-OADA-Ensure-Link header not allowed for this method');
},
});

Expand Down
9 changes: 6 additions & 3 deletions oada/services/http-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { mixins, pino } from '@oada/pino-debug';
import { mixins } from '@oada/pino-debug';

import { config } from './config.js';

Expand Down Expand Up @@ -102,7 +102,6 @@ const serializers = {
};
},
};
const logger = pino({ serializers });
// HACK: fastify overrides existing serializers. This circumvents that...
// logger.serializers = serializers;

Expand All @@ -114,7 +113,10 @@ const trustProxy = config.get('trustProxy');

export const fastify = Fastify({
trustProxy,
logger,
logger: {
// @ts-expect-error fastify types bs
serializers,
},
ignoreTrailingSlash: true,
constraints: {
oadaEnsureLink: {
Expand Down Expand Up @@ -261,6 +263,7 @@ await fastify.register(fastifyHealthcheck, {
*/
const { errorHandler } = fastify;
fastify.setErrorHandler(async (error, request, reply) => {
// @ts-expect-error fastify types bs
errorHandler(error, request, reply);
// TODO: Make kafka plugin for server?
if (error instanceof KafkaError) {
Expand Down
2 changes: 1 addition & 1 deletion oada/services/permissions-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/type-is": "^1.6.6"
},
"volta": {
Expand Down
4 changes: 2 additions & 2 deletions oada/services/rev-graph-update/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
},
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@oada/client": "^5.1.0",
"@oada/client": "^5.2.2",
"@oada/write-handler": "workspace:^",
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/randomstring": "^1.3.0",
"ava": "6.1.3",
"type-fest": "^4.26.1"
Expand Down
2 changes: 1 addition & 1 deletion oada/services/startup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3"
"@types/node": "^22.7.5"
},
"volta": {
"node": "22.5.1"
Expand Down
4 changes: 2 additions & 2 deletions oada/services/sync-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"@oada/lib-prom": "workspace:^",
"@oada/pino-debug": "workspace:^",
"debug": "^4.3.7",
"got": "^14.4.2",
"got": "^14.4.3",
"tslib": "2.7.0"
},
"devDependencies": {
"@oada/write-handler": "workspace:^",
"@types/debug": "^4.1.12",
"@types/node": "^22.7.3"
"@types/node": "^22.7.5"
},
"volta": {
"node": "22.5.1"
Expand Down
2 changes: 1 addition & 1 deletion oada/services/webhooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@oada/lib-prom": "workspace:^",
"@oada/pino-debug": "workspace:^",
"debug": "^4.3.7",
"got": "^14.4.2",
"got": "^14.4.3",
"tslib": "2.7.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion oada/services/well-known/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"cors": "^2.8.5",
"debug": "^4.3.7",
"fastify": "^5.0.0",
"got": "^14.4.2",
"got": "^14.4.3",
"openid-client": "^5.7.0",
"tslib": "2.7.0"
},
Expand Down
4 changes: 2 additions & 2 deletions oada/services/write-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
},
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@oada/client": "^5.1.0",
"@oada/client": "^5.2.2",
"@oada/types": "^4.0.0",
"@types/debug": "^4.1.12",
"@types/json-pointer": "^1.0.34",
"@types/node": "^22.7.3",
"@types/node": "^22.7.5",
"@types/object-assign-deep": "^0.4.3",
"ava": "6.1.3"
},
Expand Down
Loading

0 comments on commit 1ccd758

Please sign in to comment.