Skip to content

Commit c7c2125

Browse files
wip: moved mbe ping enclave to api-ts
Ticket: WP-4593
1 parent 7778f2f commit c7c2125

File tree

4 files changed

+122
-4
lines changed

4 files changed

+122
-4
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"body-parser": "^1.20.3",
2323
"connect-timeout": "^1.9.0",
2424
"debug": "^3.1.0",
25+
"@api-ts/io-ts-http": "^3.2.1",
26+
"@api-ts/express-wrapper": "^1.0.33",
27+
"@api-ts/response": "^2.1.0",
28+
"io-ts": "~2.1.3",
2529
"express": "4.17.3",
2630
"lodash": "^4.17.20",
2731
"morgan": "^1.9.1",

src/api.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as t from 'io-ts';
2+
import * as h from '@api-ts/io-ts-http';
3+
4+
export const PingEnclavedExpressRequest = h.httpRoute({
5+
path: '/ping/enclavedExpress',
6+
method: 'POST',
7+
request: h.httpRequest({}),
8+
response: {
9+
200: t.type({
10+
status: t.string,
11+
enclavedResponse: t.type({
12+
status: t.string,
13+
timeStamp: t.string,
14+
}),
15+
}),
16+
500: t.unknown,
17+
},
18+
});
19+
20+
export const API = h.apiSpec({
21+
'api.v1.pingEnclavedExpress': {
22+
post: PingEnclavedExpressRequest,
23+
},
24+
});

src/masterExpressApp.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import debug from 'debug';
66
import https from 'https';
77
import http from 'http';
88
import superagent from 'superagent';
9+
10+
import { createServer as createExpressApp, routeHandler } from '@api-ts/express-wrapper';
11+
import { Response } from '@api-ts/response';
912
import { BitGo, BitGoOptions } from 'bitgo';
1013
import { BitGoBase } from '@bitgo/sdk-core';
1114
import { version } from 'bitgo/package.json';
@@ -28,6 +31,7 @@ import { ProxyAgent } from 'proxy-agent';
2831
import { promiseWrapper } from './routes';
2932
import pjson from '../package.json';
3033
import { handleGenerateWalletOnPrem } from './masterBitgoExpress/generateWallet';
34+
import { API } from './api';
3135

3236
const debugLogger = debug('master-express:express');
3337
const BITGOEXPRESS_USER_AGENT = `BitGoExpress/${pjson.version} BitGoJS/${version}`;
@@ -224,7 +228,41 @@ function setupMasterExpressRoutes(app: express.Application): void {
224228
export function app(cfg: MasterExpressConfig): express.Application {
225229
debugLogger('master express app is initializing');
226230

227-
const app = express();
231+
const app = createExpressApp(API, (_app) => {
232+
return {
233+
'api.v1.pingEnclavedExpress': {
234+
post: routeHandler({
235+
handler: async () => {
236+
try {
237+
console.log('Pinging enclaved express');
238+
239+
const response = await superagent
240+
.post(`${cfg.enclavedExpressUrl}/ping`)
241+
.ca(cfg.enclavedExpressSSLCert)
242+
.agent(
243+
new https.Agent({
244+
rejectUnauthorized: cfg.enableSSL,
245+
ca: cfg.enclavedExpressSSLCert,
246+
}),
247+
)
248+
.send();
249+
250+
return Response.ok({
251+
status: 'Successfully pinged enclaved express',
252+
enclavedResponse: response.body,
253+
});
254+
} catch (error) {
255+
debugLogger('Failed to ping enclaved express:', error);
256+
return Response.internalError({
257+
error: 'Failed to ping enclaved express',
258+
details: error instanceof Error ? error.message : String(error),
259+
});
260+
}
261+
},
262+
}),
263+
},
264+
};
265+
});
228266

229267
setupLogging(app, cfg);
230268
debugLogger('logging setup');

yarn.lock

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,43 @@
1010
"@jridgewell/gen-mapping" "^0.3.5"
1111
"@jridgewell/trace-mapping" "^0.3.24"
1212

13+
"@api-ts/express-wrapper@^1.0.33":
14+
version "1.0.33"
15+
resolved "https://registry.yarnpkg.com/@api-ts/express-wrapper/-/express-wrapper-1.0.33.tgz#666632b6a008fc358ffbfc0aa53001bfe7788ef2"
16+
integrity sha512-Bn8JYmAMKF8gjj2sRpM5t+rvNUCbCU3g22rlryOEOXDYLu/OH30LYNpubREi6A4iGFv8B6TMLCtoWHrAgZg5sw==
17+
dependencies:
18+
"@api-ts/io-ts-http" "3.2.1"
19+
"@api-ts/typed-express-router" "1.1.13"
20+
express "4.21.2"
21+
fp-ts "^2.0.0"
22+
io-ts "2.1.3"
23+
24+
"@api-ts/[email protected]", "@api-ts/io-ts-http@^3.2.1":
25+
version "3.2.1"
26+
resolved "https://registry.yarnpkg.com/@api-ts/io-ts-http/-/io-ts-http-3.2.1.tgz#a6fd62f71a60a3d7c8e0dcf30c32c64a537408f3"
27+
integrity sha512-W18Oed6u1M8xu4jpemnh5V2cLbXqM7wPk8p2qQ39onC6+tBhaZmUBZ3dWhyM70ZdlANY4RqZRQ6ITuBwGiL7BA==
28+
dependencies:
29+
"@api-ts/response" "2.1.0"
30+
fp-ts "^2.0.0"
31+
io-ts "2.1.3"
32+
io-ts-types "^0.5.15"
33+
34+
"@api-ts/[email protected]", "@api-ts/response@^2.1.0":
35+
version "2.1.0"
36+
resolved "https://registry.yarnpkg.com/@api-ts/response/-/response-2.1.0.tgz#9691128e02949cdc9b2cd3277133b2c7e68220b8"
37+
integrity sha512-x9yt3IShvz9shSw4owsgC39zmPEBh9ha7MOXSMYFDsdZT7NCP4730w6fsGkYTkbQLpF3oNTMFqZONxOwE1aK5Q==
38+
39+
40+
version "1.1.13"
41+
resolved "https://registry.yarnpkg.com/@api-ts/typed-express-router/-/typed-express-router-1.1.13.tgz#baf8d2859b7742c07f7885181f31acb4a68d68d3"
42+
integrity sha512-r5EwzsjyZlEspVRjMQbAIaaBrtuDoLah6r4c0uT/LOL2zPPKuk8IHvvIhsx5ttz2bdRPKQE+jsh68adXeMpTNg==
43+
dependencies:
44+
"@api-ts/io-ts-http" "3.2.1"
45+
"@types/express" "4.17.21"
46+
express "4.21.2"
47+
fp-ts "^2.0.0"
48+
io-ts "2.1.3"
49+
1350
"@aptos-labs/aptos-cli@^1.0.2":
1451
version "1.0.2"
1552
resolved "https://registry.yarnpkg.com/@aptos-labs/aptos-cli/-/aptos-cli-1.0.2.tgz#91bd1368cf808f715d102822b7d4032388cdad79"
@@ -4739,7 +4776,7 @@
47394776
resolved "https://registry.yarnpkg.com/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5"
47404777
integrity sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg==
47414778

4742-
"@types/express-serve-static-core@^4.17.18":
4779+
"@types/express-serve-static-core@^4.17.18", "@types/express-serve-static-core@^4.17.33":
47434780
version "4.19.6"
47444781
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.19.6.tgz#e01324c2a024ff367d92c66f48553ced0ab50267"
47454782
integrity sha512-N4LZ2xG7DatVqhCZzOGb1Yi5lMbXSZcmdLDe9EzSndPV2HpWYWzRbaerl2n27irrm94EPpprqa8KpskPT085+A==
@@ -4778,6 +4815,16 @@
47784815
"@types/qs" "*"
47794816
"@types/serve-static" "*"
47804817

4818+
4819+
version "4.17.21"
4820+
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.21.tgz#c26d4a151e60efe0084b23dc3369ebc631ed192d"
4821+
integrity sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==
4822+
dependencies:
4823+
"@types/body-parser" "*"
4824+
"@types/express-serve-static-core" "^4.17.33"
4825+
"@types/qs" "*"
4826+
"@types/serve-static" "*"
4827+
47814828
"@types/graceful-fs@^4.1.3":
47824829
version "4.1.9"
47834830
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.9.tgz#2a06bc0f68a20ab37b3e36aa238be6abdf49e8b4"
@@ -8069,7 +8116,7 @@ [email protected]:
80698116
utils-merge "1.0.1"
80708117
vary "~1.1.2"
80718118

8072-
express@^4.14.0:
8119+
express@4.21.2, express@^4.14.0:
80738120
version "4.21.2"
80748121
resolved "https://registry.yarnpkg.com/express/-/express-4.21.2.tgz#cf250e48362174ead6cea4a566abef0162c1ec32"
80758122
integrity sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==
@@ -8980,7 +9027,7 @@ invariant@^2.2.4:
89809027
dependencies:
89819028
loose-envify "^1.0.0"
89829029

8983-
io-ts-types@^0.5.16:
9030+
io-ts-types@^0.5.15, io-ts-types@^0.5.16:
89849031
version "0.5.19"
89859032
resolved "https://registry.yarnpkg.com/io-ts-types/-/io-ts-types-0.5.19.tgz#9c04fa73f15992436605218a5686b610efa7a5d3"
89869033
integrity sha512-kQOYYDZG5vKre+INIDZbLeDJe+oM+4zLpUkjXyTMyUfoCpjJNyi29ZLkuEAwcPufaYo3yu/BsemZtbdD+NtRfQ==
@@ -8990,6 +9037,11 @@ [email protected]:
89909037
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.1.tgz#1261c12f915c2f48d16393a36966636b48a45aa1"
89919038
integrity sha512-RezD+WcCfW4VkMkEcQWL/Nmy/nqsWTvTYg7oUmTGzglvSSV2P9h2z1PVeREPFf0GWNzruYleAt1XCMQZSg1xxQ==
89929039

9040+
[email protected], io-ts@~2.1.3:
9041+
version "2.1.3"
9042+
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.1.3.tgz#02c03c375d14079496f0c046ef8a9aad4fbaeb74"
9043+
integrity sha512-QFMR2QEBSP6w1TPmkpfca6xkzBbXO+K7ubdbV26GlCGI7CP9LV59bfty422JYtWgbBITuL/zBb1+mziv9f5Wfg==
9044+
89939045
"io-ts@npm:@bitgo-forks/[email protected]":
89949046
version "2.1.4"
89959047
resolved "https://registry.yarnpkg.com/@bitgo-forks/io-ts/-/io-ts-2.1.4.tgz#a7431bb5473c5d5f9a94de8f8b058e189a298423"

0 commit comments

Comments
 (0)