0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

Merge pull request #2885 from logto-io/gao-log-5125-core-library-factory-logto-config

refactor(core): migrate logto config library to factory mode
This commit is contained in:
Gao Sun 2023-01-10 13:27:31 +08:00 committed by GitHub
commit 76bd2bc7d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 24 deletions

View file

@ -5,7 +5,7 @@ import type { PostgreSql } from '@withtyped/postgres';
import type { QueryClient } from '@withtyped/server'; import type { QueryClient } from '@withtyped/server';
import type { DatabasePool } from 'slonik'; import type { DatabasePool } from 'slonik';
import { getOidcConfigs } from '#src/libraries/logto-config.js'; import { createLogtoConfigLibrary } from '#src/libraries/logto-config.js';
import { appendPath } from '#src/utils/url.js'; import { appendPath } from '#src/utils/url.js';
import { checkAlterationState } from './check-alteration-state.js'; import { checkAlterationState } from './check-alteration-state.js';
@ -108,7 +108,8 @@ class EnvSet {
this.#pool = pool; this.#pool = pool;
this.#queryClient = createQueryClient(this.databaseUrl, this.isTest); this.#queryClient = createQueryClient(this.databaseUrl, this.isTest);
const [, oidcConfigs] = await Promise.all([checkAlterationState(pool), getOidcConfigs(pool)]); const { getOidcConfigs } = createLogtoConfigLibrary(pool);
const [, oidcConfigs] = await Promise.all([checkAlterationState(pool), getOidcConfigs()]);
this.#oidc = await loadOidcValues( this.#oidc = await loadOidcValues(
appendPath(this.values.endpoint, '/oidc').toString(), appendPath(this.values.endpoint, '/oidc').toString(),
oidcConfigs oidcConfigs

View file

@ -15,8 +15,10 @@ const { privateKey } = generateKeyPairSync('rsa', {
}, },
}); });
export const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({ const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({
[LogtoOidcConfigKey.PrivateKeys]: [privateKey], [LogtoOidcConfigKey.PrivateKeys]: [privateKey],
[LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'], [LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'],
[LogtoOidcConfigKey.RefreshTokenReuseInterval]: 3, [LogtoOidcConfigKey.RefreshTokenReuseInterval]: 3,
}); });
export const createLogtoConfigLibrary = () => ({ getOidcConfigs });

View file

@ -5,7 +5,8 @@ import chalk from 'chalk';
import type { CommonQueryMethods } from 'slonik'; import type { CommonQueryMethods } from 'slonik';
import { z, ZodError } from 'zod'; import { z, ZodError } from 'zod';
export const getOidcConfigs = async (pool: CommonQueryMethods): Promise<LogtoOidcConfigType> => { export const createLogtoConfigLibrary = (pool: CommonQueryMethods) => {
const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => {
try { try {
const { rows } = await getRowsByKeys(pool, Object.values(LogtoOidcConfigKey)); const { rows } = await getRowsByKeys(pool, Object.values(LogtoOidcConfigKey));
@ -31,4 +32,7 @@ export const getOidcConfigs = async (pool: CommonQueryMethods): Promise<LogtoOid
); );
throw new Error('Failed to get configs'); throw new Error('Failed to get configs');
} }
};
return { getOidcConfigs };
}; };