Skip to content

Commit 9fd5b32

Browse files
committed
fixes
1 parent da51243 commit 9fd5b32

File tree

17 files changed

+75
-45
lines changed

17 files changed

+75
-45
lines changed

crypt/dev/30_wb.sh

8 Bytes
Binary file not shown.

lib/node_core/node_core-v0.1.0.tgz

746 Bytes
Binary file not shown.

lib/node_core/src/db/db_permission_fetch_client_profile_permissions_sql.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// istanbul ignore file
2-
31
export const value = `
42
(
53
SELECT permission_name

lib/node_core/src/server.ts

+29-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// -- bootstrap
33

44
import {createServer, IncomingMessage, Server, ServerResponse} from 'http';
5-
import {contentHandlerType, ctxType, wsHandlerType, serverSettingsType, ctxWsType} from './server.type';
5+
import {contentHandlerType, ctxType, wsHandlerType, serverSettingsType, ctxWsType, ctxReqType} from './server.type';
66
import {ctxCtor} from './ctx';
77
import {gauthContinueCtor, gauthInitCtor, gauthOnUserData} from './gauth';
88
import {sessionInfoCtor, sessionInitCtor, sessionSetCtor} from './session';
@@ -22,7 +22,7 @@ export function server(
2222
wsOnConnectHandler?: (ctxWs: ctxWsType) => Promise<serializableType>,
2323
wsOnCloseHandler?: (ctxWs: ctxWsType) => Promise<serializableType>,
2424
onUserData?: gauthOnUserData,
25-
): { server: Server, ws: wsType } {
25+
): { server: Server, ws?: wsType } {
2626
if (!wsHandlerRegistry) {
2727
wsHandlerRegistry = readonlyRegistryCtor<wsHandlerType>([]);
2828
}
@@ -50,14 +50,21 @@ export function server(
5050
res.end(`500 Server Error:\n${e}`);
5151
}
5252

53-
const sessionInit = sessionInitCtor(settings);
54-
const sessionSet = sessionSetCtor(settings);
55-
const sessionInfo = sessionInfoCtor(settings);
53+
let sessionInit: contentHandlerType | undefined = undefined;
54+
let sessionSet: contentHandlerType | undefined = undefined;
55+
let sessionInfo: contentHandlerType | undefined = undefined;
56+
57+
if (settings.mode) {
58+
sessionInit = sessionInitCtor(settings);
59+
sessionSet = sessionSetCtor(settings);
60+
sessionInfo = sessionInfoCtor(settings);
61+
}
5662

5763
let gauthInit: (ctx: ctxType) => Promise<void>;
5864
let gauthContinue: (ctx: ctxType) => Promise<void>;
5965

60-
if (settings.google && onUserData) {
66+
// you must set mode to use gauth
67+
if (settings.google && onUserData && settings.mode) {
6168
gauthInit = gauthInitCtor({
6269
google: settings.google,
6370
},
@@ -72,9 +79,16 @@ export function server(
7279
onUserData,
7380
axios.post,
7481
);
75-
ha = [sessionInit, sessionSet, gauthInit, gauthContinue, sessionInfo, ...handlerArray];
82+
// istanbul ignore next: these must be defined by the logic above, but the compiler is not that smart.
83+
if (sessionInit && sessionSet && sessionInfo) {
84+
ha = [sessionInit, sessionSet, gauthInit, gauthContinue, sessionInfo, ...handlerArray];
85+
}
7686
} else {
77-
ha = [sessionInit, sessionSet, sessionInfo, ...handlerArray];
87+
if (sessionInit && sessionSet && sessionInfo) {
88+
ha = [sessionInit, sessionSet, sessionInfo, ...handlerArray];
89+
} else {
90+
ha = handlerArray;
91+
}
7892
}
7993

8094
const dbProvider = dbProviderCtor(settings.dbConnectionString);
@@ -113,7 +127,12 @@ export function server(
113127

114128
server.listen(+settings.port, settings.host);
115129

116-
const ws = wsInit(wsHandlerRegistry, server, settings, sessionInit, dbProvider, wsOnConnectHandler, wsOnCloseHandler);
117-
130+
let ws: wsType | undefined;
131+
if (settings.mode) {
132+
// istanbul ignore next: these must be defined by the logic above, but the compiler is not that smart.
133+
if (sessionInit) {
134+
ws = wsInit(wsHandlerRegistry, server, settings, sessionInit, dbProvider, wsOnConnectHandler, wsOnCloseHandler);
135+
}
136+
}
118137
return {server, ws};
119138
}

lib/node_core/src/server.type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export type serverSettingsType = {
8787
host: string;
8888
port: string | number;
8989
schema: string;
90-
mode: 'client' | 'staff',
90+
mode?: 'client' | 'staff',
9191
google?: {
9292
secret: string;
9393
redirectUri: string;
-4 Bytes
Binary file not shown.
3 Bytes
Binary file not shown.

nginx/nginx.conf

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ http {
2121
hostnames;
2222

2323
default 0;
24+
api.cdash.cidi.xxx 8800;
25+
*.api.cdash.cidi.xxx 8800;
2426
api.formation.xxx 8205;
2527
*.api.formation.xxx 8205;
2628
app.formation.xxx 8201;

procfile_cdash.dev

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nginx: node ./nginx/nginx.conf.js && nginx -c $(pwd)/nginx/nginx.conf
2+
api_cdash_cidi: cd project/cidi/site/api.cdash && ./dev

project/cidi/site/api.cdash/dev

-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
#!/usr/bin/env bash
2-
pushd ../../../../lib/ts_agnostic
3-
./build
4-
popd
5-
pushd ../../../../lib/node_core
6-
./build
7-
popd
8-
pushd ../../../../lib/node_script
9-
./build
10-
popd
112
PORT=$(cat .port) yarn dev

project/cidi/site/api.cdash/readme.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# manual testing
2+
3+
## Start the server running
4+
This assumes you have the local Wealthbar DB set up, and you've set up the local `*.xxx` DNS resolution to localhost.
5+
6+
```
7+
# in the polestar root:
8+
. ./config.sh dev
9+
overmind s -N -f procfile_cdash.dev
10+
```
11+
12+
## Use curl to call the api
13+
14+
Get the production or demo token from 'CDASH_BEARER_MAPPING'. Use id `00050000-4000-8000-0000-000000000001` for demo data.
15+
16+
```
17+
curl -H 'Authorization: Bearer <token>' 'http://api.cdash.cidi.xxx/v1/user_info?cidi_id=<id>' -o -
18+
curl -H 'Authorization: Bearer aba3fa38eab0c7c0d802514855c04a2867339aa4a0571b5892e4f169bc8016ed5ca27cf07d5aa563d79630820f438ec111bbd52c31cc6b2b0a9edf40fc80e1cf' 'http://api.cdash.cidi.xxx/v1/user_info?cidi_id=00050000-4000-8000-0000-000000000001' -o -
19+
```

project/cidi/site/api.cdash/src/content_handler/v1/user_info.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM
55
billing_user_daily_cad_values biudcv
66
JOIN users u ON biudcv.user_id = u.id
77
WHERE
8-
u.ci_id = $(ciId)::uuid
8+
u.cidi_id = $(cidiId)::uuid
99
AND biudcv.date >= ($(asOf)::date - INTERVAL '5 days')
1010
ORDER BY
1111
biudcv.date DESC

project/cidi/site/api.cdash/src/content_handler/v1/user_info.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('userInfoV1Handler', () => {
8787
} = getStubs({
8888
db,
8989
path: '/v1/user_info',
90-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
90+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
9191
authorization: prodAuthorization,
9292
});
9393

@@ -108,7 +108,7 @@ describe('userInfoV1Handler', () => {
108108
} = getStubs({
109109
db,
110110
path: '/v1/user_info',
111-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
111+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
112112
authorization: prodAuthorization,
113113
});
114114

@@ -129,7 +129,7 @@ describe('userInfoV1Handler', () => {
129129
} = getStubs({
130130
db,
131131
path: '/v1/user_info',
132-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
132+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
133133
authorization: prodAuthorization,
134134
});
135135

@@ -149,7 +149,7 @@ describe('userInfoV1Handler', () => {
149149
} = getStubs({
150150
db,
151151
path: '/v1/user_info',
152-
params: [['ci_id', '00050000-4000-8000-0000-100000000001']] as [string, string][],
152+
params: [['cidi_id', '00050000-4000-8000-0000-100000000001']] as [string, string][],
153153
authorization: prodAuthorization,
154154
});
155155

@@ -161,15 +161,15 @@ describe('userInfoV1Handler', () => {
161161
sinon.assert.calledWith(ctx.res.end, `{"res":{}}`);
162162
}));
163163

164-
it('handles v1/user_info request missing ci_id', () => setup(async (db: dbType) => {
164+
it('handles v1/user_info request missing cidi_id', () => setup(async (db: dbType) => {
165165
const {
166166
currentDate,
167167
ctx,
168168
userInfoV1Handler,
169169
} = getStubs({
170170
db,
171171
path: '/v1/user_info',
172-
params: [['ciid', '00050000-4000-8000-0000-000000000001']] as [string, string][],
172+
params: [['cidiId', '00050000-4000-8000-0000-000000000001']] as [string, string][],
173173
authorization: prodAuthorization,
174174
});
175175

@@ -189,7 +189,7 @@ describe('userInfoV1Handler', () => {
189189
} = getStubs({
190190
db,
191191
path: '/v1/user_info',
192-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
192+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
193193
authorization: demoAuthorization,
194194
});
195195

@@ -209,7 +209,7 @@ describe('userInfoV1Handler', () => {
209209
} = getStubs({
210210
db,
211211
path: '/v1/user_info',
212-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
212+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
213213
});
214214

215215
currentDate.returns('2021-02-02');
@@ -228,7 +228,7 @@ describe('userInfoV1Handler', () => {
228228
} = getStubs({
229229
db,
230230
path: '/v1/user_info',
231-
params: [['ci_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
231+
params: [['cidi_id', '00050000-4000-8000-0000-000000000001']] as [string, string][],
232232
authorization: 'Bearer Bob',
233233
});
234234

project/cidi/site/api.cdash/src/content_handler/v1/user_info.test_sql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const value = `
22
INSERT INTO
33
users
4-
(id, ci_id)
4+
(id, cidi_id)
55
VALUES
66
(1, '00050000-4000-8000-0000-000000000001'),
77
(2, '00050000-4000-8000-0000-000000000002'),

project/cidi/site/api.cdash/src/content_handler/v1/user_info.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export const userInfoV1HandlerCtor = (
1414
assumes:
1515
1616
ALTER TABLE users
17-
ADD COLUMN ci_id uuid;
17+
ADD COLUMN cidi_id uuid;
1818
19-
CREATE INDEX users_ci_id ON users (ci_id);
19+
CREATE INDEX users_cidi_id ON users (cidi_id);
2020
2121
*/
2222
const errForbidden = JSON.stringify({err: "Forbidden"});
@@ -31,12 +31,12 @@ export const userInfoV1HandlerCtor = (
3131

3232
const firstOrUndefined = <T>(ts: T[]) => ts.length > 0 ? ts[0] : undefined;
3333

34-
const prodHandler = async (db: dbProviderCtxType, ciId: string) =>
34+
const prodHandler = async (db: dbProviderCtxType, cidiId: string) =>
3535
db(
3636
async (db) =>
3737
firstOrUndefined(
3838
(
39-
await db.any(userInfoSql, {ciId, asOf: currentDate()})
39+
await db.any(userInfoSql, {cidiId, asOf: currentDate()})
4040
).map(
4141
fromDbUserInfo
4242
)
@@ -50,9 +50,9 @@ export const userInfoV1HandlerCtor = (
5050
}
5151
};
5252

53-
const demoHandler = async (_: dbProviderCtxType, ciId: string) => demoData[ciId];
53+
const demoHandler = async (_: dbProviderCtxType, cidiId: string) => demoData[cidiId];
5454

55-
const bearerMapping: Record<string, (db: dbProviderCtxType, ciId: string) => Promise<Record<string, string> | undefined>> = {
55+
const bearerMapping: Record<string, (db: dbProviderCtxType, cidiId: string) => Promise<Record<string, string> | undefined>> = {
5656
"p": prodHandler,
5757
"d": demoHandler
5858
};
@@ -79,14 +79,14 @@ export const userInfoV1HandlerCtor = (
7979
}
8080

8181
const mode = settings.bearerMapping[token].toLowerCase();
82-
const ciId = ctx.url.params.find(x => x[0] === 'ci_id')?.[1];
82+
const cidiId = ctx.url.params.find(x => x[0] === 'cidi_id')?.[1];
8383

84-
if (!mode || !ciId || !modes.includes(mode)) {
84+
if (!mode || !cidiId || !modes.includes(mode)) {
8585
res.end(errInvalid);
8686
return resolvedVoid;
8787
}
8888

89-
const userInfo = await bearerMapping[mode](ctx.db, ciId);
89+
const userInfo = await bearerMapping[mode](ctx.db, cidiId);
9090

9191
if (userInfo) {
9292
res.end(serialize({

project/cidi/site/api.cdash/src/settings.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export const settings: serverSettingsType & { bearerMapping: typeof bearerMappin
2121
host: process.env.HOST || '0.0.0.0',
2222
port: process.env.PORT || 8000,
2323
schema: 'http://', // we should be able to get the forwarder to tell us this.
24-
mode: 'client',
25-
appUrl: `app.formation.${process.env.HOST_POSTFIX}`,
24+
appUrl: `api.cdash.cidi.${process.env.HOST_POSTFIX}`,
2625
dbConnectionString: process.env.DB_WB_CLIENT_URL || 'postgres://postgres@localhost:5432/wealthbar_dev',
2726
secret: process.env.CDASH_SECRET,
2827
bearerMapping,

project/formation/site/app/src/app/v1/flow/test.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineComponent({
2121
props: {wf: {type: Object, required: true}},
2222
setup({wf}: { wf: wfType }) {
2323
const steps = {init, done};
24-
return {wf, steps};
24+
return {steps};
2525
},
2626
});
2727

0 commit comments

Comments
 (0)