mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -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 pool = new pg.Pool({ database, user: 'postgres', password: 'postgres' });
|
||||
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 }) => {
|
||||
const { rows } = await pool.query(/* sql */`select * from ${table_name};`);
|
||||
|
||||
// check config rows except the value column
|
||||
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(
|
||||
|
|
|
@ -19,14 +19,14 @@ import { throwNotLoadedError } from './throw-errors.js';
|
|||
export enum UserApps {
|
||||
Api = 'api',
|
||||
Oidc = 'oidc',
|
||||
Console = 'console',
|
||||
DemoApp = 'demo-app',
|
||||
Welcome = 'welcome',
|
||||
}
|
||||
|
||||
/** Apps (also paths) ONLY for the admin tenant. */
|
||||
export enum AdminApps {
|
||||
Me = 'me',
|
||||
Console = 'console',
|
||||
Welcome = 'welcome',
|
||||
}
|
||||
|
||||
const getTenantEndpoint = (id: string) => {
|
||||
|
|
|
@ -35,7 +35,7 @@ describe('koaSpaProxy middleware', () => {
|
|||
|
||||
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
|
||||
it(`${app} path should not call dev proxy`, async () => {
|
||||
const ctx = createContextWithRouteParameters({
|
||||
|
|
|
@ -39,10 +39,7 @@ export default function koaSpaProxy<StateT, ContextT extends IRouterParamContext
|
|||
const requestPath = ctx.request.path;
|
||||
|
||||
// Route has been handled by one of mounted apps
|
||||
if (
|
||||
!prefix &&
|
||||
Object.values(mountedApps).some((app) => app !== prefix && requestPath.startsWith(`/${app}`))
|
||||
) {
|
||||
if (!prefix && mountedApps.some((app) => app !== prefix && requestPath.startsWith(`/${app}`))) {
|
||||
return next();
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,8 @@ export default class Tenant implements TenantContext {
|
|||
app.use(koaConsoleRedirectProxy(queries));
|
||||
app.use(
|
||||
mount(
|
||||
'/' + UserApps.Console,
|
||||
koaSpaProxy(mountedApps, UserApps.Console, 5002, UserApps.Console)
|
||||
'/' + AdminApps.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
|
||||
.map((row) => conditionalString(isKeyInObject(row, 'tablename') && String(row.tablename)))
|
||||
.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 = {
|
||||
up: async (pool) => {
|
||||
// Init admin OIDC configs
|
||||
await updateConfigByKey(pool, adminTenantId, 'oidc.privateKeys', [
|
||||
await generateOidcPrivateKey(),
|
||||
]);
|
||||
await updateConfigByKey(pool, adminTenantId, 'oidc.cookieKeys', [generateOidcCookieKey()]);
|
||||
|
||||
// Skipped tables:
|
||||
// applications_roles, applications, connectors, custom_phrases, logto_configs,
|
||||
// passcodes, resources, roles_scopes, roles, scopes, sign_in_experiences,
|
||||
|
@ -134,12 +140,6 @@ const alteration: AlterationScript = {
|
|||
sql`,`
|
||||
)};
|
||||
`);
|
||||
|
||||
// Init admin OIDC configs
|
||||
await updateConfigByKey(pool, adminTenantId, 'oidc.privateKeys', [
|
||||
await generateOidcPrivateKey(),
|
||||
]);
|
||||
await updateConfigByKey(pool, adminTenantId, 'oidc.cookieKeys', [generateOidcCookieKey()]);
|
||||
},
|
||||
down: async (pool) => {
|
||||
const { rows } = await pool.query<{ id: string }>(sql`select id from tenants;`);
|
||||
|
|
Loading…
Reference in a new issue