mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
refactor: update per review
This commit is contained in:
parent
40173bb5e0
commit
3c39c618a1
7 changed files with 20 additions and 19 deletions
|
@ -117,14 +117,18 @@ assert.deepStrictEqual(...manifests);
|
||||||
const queryDatabaseData = async (database) => {
|
const queryDatabaseData = async (database) => {
|
||||||
const pool = new pg.Pool({ database, user: 'postgres', password: 'postgres' });
|
const pool = new pg.Pool({ database, user: 'postgres', password: 'postgres' });
|
||||||
const result = await Promise.all(manifests[0].tables
|
const result = await Promise.all(manifests[0].tables
|
||||||
// system configs are usually generated or time-relative, ignore for now
|
|
||||||
.filter(({ table_name }) => !['logto_configs', '_logto_configs', 'systems'].includes(table_name))
|
|
||||||
.map(async ({ table_name }) => {
|
.map(async ({ table_name }) => {
|
||||||
const { rows } = await pool.query(/* sql */`select * from ${table_name};`);
|
const { rows } = await pool.query(/* sql */`select * from ${table_name};`);
|
||||||
|
|
||||||
// check config rows except the value column
|
// check config rows except the value column
|
||||||
if (['logto_configs', '_logto_configs', 'systems'].includes(table_name)) {
|
if (['logto_configs', '_logto_configs', 'systems'].includes(table_name)) {
|
||||||
return [table_name, omitArray(rows, 'value')];
|
return [table_name, omitArray(rows, 'value').sort((a, b) => {
|
||||||
|
if (a.tenant_id === b.tenant_id) {
|
||||||
|
return a.key.localeCompare(b.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.tenant_id.localeCompare(b.tenant_id);
|
||||||
|
})];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [table_name, omitArray(
|
return [table_name, omitArray(
|
||||||
|
|
|
@ -19,14 +19,14 @@ import { throwNotLoadedError } from './throw-errors.js';
|
||||||
export enum UserApps {
|
export enum UserApps {
|
||||||
Api = 'api',
|
Api = 'api',
|
||||||
Oidc = 'oidc',
|
Oidc = 'oidc',
|
||||||
Console = 'console',
|
|
||||||
DemoApp = 'demo-app',
|
DemoApp = 'demo-app',
|
||||||
Welcome = 'welcome',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Apps (also paths) ONLY for the admin tenant. */
|
/** Apps (also paths) ONLY for the admin tenant. */
|
||||||
export enum AdminApps {
|
export enum AdminApps {
|
||||||
Me = 'me',
|
Me = 'me',
|
||||||
|
Console = 'console',
|
||||||
|
Welcome = 'welcome',
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTenantEndpoint = (id: string) => {
|
const getTenantEndpoint = (id: string) => {
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe('koaSpaProxy middleware', () => {
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
for (const app of Object.values(UserApps)) {
|
for (const app of Object.values(mountedApps)) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
||||||
it(`${app} path should not call dev proxy`, async () => {
|
it(`${app} path should not call dev proxy`, async () => {
|
||||||
const ctx = createContextWithRouteParameters({
|
const ctx = createContextWithRouteParameters({
|
||||||
|
|
|
@ -39,10 +39,7 @@ export default function koaSpaProxy<StateT, ContextT extends IRouterParamContext
|
||||||
const requestPath = ctx.request.path;
|
const requestPath = ctx.request.path;
|
||||||
|
|
||||||
// Route has been handled by one of mounted apps
|
// Route has been handled by one of mounted apps
|
||||||
if (
|
if (!prefix && mountedApps.some((app) => app !== prefix && requestPath.startsWith(`/${app}`))) {
|
||||||
!prefix &&
|
|
||||||
Object.values(mountedApps).some((app) => app !== prefix && requestPath.startsWith(`/${app}`))
|
|
||||||
) {
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,8 @@ export default class Tenant implements TenantContext {
|
||||||
app.use(koaConsoleRedirectProxy(queries));
|
app.use(koaConsoleRedirectProxy(queries));
|
||||||
app.use(
|
app.use(
|
||||||
mount(
|
mount(
|
||||||
'/' + UserApps.Console,
|
'/' + AdminApps.Console,
|
||||||
koaSpaProxy(mountedApps, UserApps.Console, 5002, UserApps.Console)
|
koaSpaProxy(mountedApps, AdminApps.Console, 5002, AdminApps.Console)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ export const checkRowLevelSecurity = async (client: QueryClient) => {
|
||||||
`Found following table(s) without RLS: ${rlsDisabled
|
`Found following table(s) without RLS: ${rlsDisabled
|
||||||
.map((row) => conditionalString(isKeyInObject(row, 'tablename') && String(row.tablename)))
|
.map((row) => conditionalString(isKeyInObject(row, 'tablename') && String(row.tablename)))
|
||||||
.join(', ')}\n\n` +
|
.join(', ')}\n\n` +
|
||||||
'Did you forget to run `npm cli db multi-tenancy enable`?'
|
'Did you forget to run `npm cli db alteration deploy`?'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,6 +47,12 @@ const defaultTenantId = 'default';
|
||||||
|
|
||||||
const alteration: AlterationScript = {
|
const alteration: AlterationScript = {
|
||||||
up: async (pool) => {
|
up: async (pool) => {
|
||||||
|
// Init admin OIDC configs
|
||||||
|
await updateConfigByKey(pool, adminTenantId, 'oidc.privateKeys', [
|
||||||
|
await generateOidcPrivateKey(),
|
||||||
|
]);
|
||||||
|
await updateConfigByKey(pool, adminTenantId, 'oidc.cookieKeys', [generateOidcCookieKey()]);
|
||||||
|
|
||||||
// Skipped tables:
|
// Skipped tables:
|
||||||
// applications_roles, applications, connectors, custom_phrases, logto_configs,
|
// applications_roles, applications, connectors, custom_phrases, logto_configs,
|
||||||
// passcodes, resources, roles_scopes, roles, scopes, sign_in_experiences,
|
// passcodes, resources, roles_scopes, roles, scopes, sign_in_experiences,
|
||||||
|
@ -134,12 +140,6 @@ const alteration: AlterationScript = {
|
||||||
sql`,`
|
sql`,`
|
||||||
)};
|
)};
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Init admin OIDC configs
|
|
||||||
await updateConfigByKey(pool, adminTenantId, 'oidc.privateKeys', [
|
|
||||||
await generateOidcPrivateKey(),
|
|
||||||
]);
|
|
||||||
await updateConfigByKey(pool, adminTenantId, 'oidc.cookieKeys', [generateOidcCookieKey()]);
|
|
||||||
},
|
},
|
||||||
down: async (pool) => {
|
down: async (pool) => {
|
||||||
const { rows } = await pool.query<{ id: string }>(sql`select id from tenants;`);
|
const { rows } = await pool.query<{ id: string }>(sql`select id from tenants;`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue