Skip to content

Commit d19f13f

Browse files
committed
fix(naming): allow -internal as a suffix for internal services
1 parent f913df4 commit d19f13f

File tree

6 files changed

+105
-156
lines changed

6 files changed

+105
-156
lines changed

__tests__/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('configuration loader', () => {
1818
expect(config.get('envswitchon')).toBeTruthy();
1919

2020
expect(config.get('servicetype')).toBeTruthy();
21+
expect(config.get('oservicetype')).toBeTruthy();
2122
expect(config.get('notservicetype')).toBeFalsy();
2223

2324
const orig = ['a', 'b', 'd'];

__tests__/fake-serv/config/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"envswitchoff": "env_switch:ENV_VAR_DOESNT_EXIST",
77
"envswitchon": "env_switch:!ENV_VAR_DOESNT_EXIST",
88
"servicetype": "servicetype:serv",
9+
"oservicetype": "servicetype:internal",
910
"notservicetype": "servicetype:api",
1011
"server": {
1112
"metrics": {

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@opentelemetry/sdk-node": "^0.39.1",
7373
"@opentelemetry/semantic-conventions": "^1.13.0",
7474
"cookie-parser": "^1.4.6",
75-
"dotenv": "^16.0.3",
75+
"dotenv": "^16.3.0",
7676
"eventsource": "^1.1.2",
7777
"express": "next",
7878
"express-openapi-validator": "^5.0.4",
@@ -87,20 +87,20 @@
8787
"shortstop-yaml": "^1.0.0"
8888
},
8989
"devDependencies": {
90-
"@commitlint/cli": "^17.6.3",
91-
"@commitlint/config-conventional": "^17.6.3",
92-
"@openapi-typescript-infra/coconfig": "^3.0.1",
90+
"@commitlint/cli": "^17.6.5",
91+
"@commitlint/config-conventional": "^17.6.5",
92+
"@openapi-typescript-infra/coconfig": "^3.0.2",
9393
"@types/cookie-parser": "^1.4.3",
9494
"@types/eventsource": "1.1.11",
9595
"@types/express": "^4.17.17",
9696
"@types/glob": "^8.1.0",
97-
"@types/jest": "^29.5.1",
97+
"@types/jest": "^29.5.2",
9898
"@types/lodash": "^4.14.195",
9999
"@types/minimist": "^1.2.2",
100100
"@types/node": "^18.16.15",
101101
"@types/supertest": "^2.0.12",
102-
"coconfig": "^0.10.1",
103-
"eslint": "^8.41.0",
102+
"coconfig": "^0.12.0",
103+
"eslint": "^8.43.0",
104104
"eslint-config-gasbuddy": "^7.2.0",
105105
"eslint-config-prettier": "^8.8.0",
106106
"eslint-plugin-jest": "^27.2.1",
@@ -112,7 +112,7 @@
112112
"supertest": "^6.3.3",
113113
"ts-jest": "^29.1.0",
114114
"ts-node": "^10.9.1",
115-
"typescript": "^5.0.4"
115+
"typescript": "^5.1.3"
116116
},
117117
"packageManager": "[email protected]"
118118
}

src/config/shortstops.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ function betterRequire(basepath: string) {
2929
};
3030
}
3131

32+
function canonicalizeServiceSuffix(suffix?: string) {
33+
if (!suffix) {
34+
return 'internal';
35+
}
36+
return { serv: 'internal' }[suffix] || suffix;
37+
}
38+
3239
/**
3340
* Our convention is that service names end with:
34-
* -serv - a back end service not callable by the outside world and where no authorization occurs
41+
* -serv or -internal - a back end service not callable by the outside world and where no authorization occurs (canonicalized to internal)
3542
* -api - a non-UI front end service that exposes swagger and sometimes non-swagger APIs
3643
* -web - a UI front end service
3744
* -worker - a scheduled job or queue processor
@@ -41,7 +48,7 @@ function betterRequire(basepath: string) {
4148
* whether it's NOT of any of the specified types
4249
*/
4350
function serviceTypeFactory(name: string) {
44-
const type = name.split('-').pop();
51+
const type = canonicalizeServiceSuffix(name.split('-').pop());
4552

4653
return function serviceType(v: string) {
4754
let checkValue = v;
@@ -50,7 +57,7 @@ function serviceTypeFactory(name: string) {
5057
matchIsGood = false;
5158
checkValue = checkValue.substring(1);
5259
}
53-
const values = checkValue.split(',');
60+
const values = checkValue.split(',').map(canonicalizeServiceSuffix);
5461
// Welp, there's no XOR so here we are.
5562
return type && values.includes(type) ? matchIsGood : !matchIsGood;
5663
};

src/express-app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export async function startApp<
168168
// so that the req can decide whether to save the raw request body or not.
169169
const attachServiceLocals: RequestHandler = (req, res, next) => {
170170
res.locals.logger = logger;
171-
let maybePromise: Promise<void> | void;
171+
let maybePromise: Promise<void> | void | undefined;
172172
try {
173173
maybePromise = serviceImpl.onRequest?.(
174174
req as RequestWithApp<SLocals>,

0 commit comments

Comments
 (0)