mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): add third-party application creation quota guard (#5348)
add third-party application creation quota guard
This commit is contained in:
parent
0a87ffd609
commit
f53a14d7a8
5 changed files with 22 additions and 4 deletions
|
@ -93,7 +93,7 @@
|
|||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@logto/cloud": "0.2.5-c6ed487",
|
||||
"@logto/cloud": "0.2.5-faca9a9",
|
||||
"@silverhand/eslint-config": "5.0.0",
|
||||
"@silverhand/ts-config": "5.0.0",
|
||||
"@types/debug": "^4.1.7",
|
||||
|
|
|
@ -23,7 +23,7 @@ export const createQuotaLibrary = (
|
|||
connectorLibrary: ConnectorLibrary
|
||||
) => {
|
||||
const {
|
||||
applications: { countAllApplications, countM2mApplications },
|
||||
applications: { countThirdPartyApplications, countAllApplications, countM2mApplications },
|
||||
resources: { findTotalNumberOfResources },
|
||||
hooks: { getTotalNumberOfHooks },
|
||||
roles: { countRoles },
|
||||
|
@ -38,6 +38,7 @@ export const createQuotaLibrary = (
|
|||
(queryKey?: string) => Promise<{ count: number }>
|
||||
> = {
|
||||
applicationsLimit: countAllApplications,
|
||||
thirdPartyApplicationsLimit: countThirdPartyApplications,
|
||||
hooksLimit: getTotalNumberOfHooks,
|
||||
machineToMachineLimit: countM2mApplications,
|
||||
resourcesLimit: async () => {
|
||||
|
|
|
@ -161,6 +161,16 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => {
|
|||
return { count: Number(count) };
|
||||
};
|
||||
|
||||
const countThirdPartyApplications = async () => {
|
||||
const { count } = await pool.one<{ count: string }>(sql`
|
||||
select count(*)
|
||||
from ${table}
|
||||
where ${fields.isThirdParty} = true
|
||||
`);
|
||||
|
||||
return { count: Number(count) };
|
||||
};
|
||||
|
||||
const countM2mApplicationsByIds = async (search: Search, applicationIds: string[]) => {
|
||||
if (applicationIds.length === 0) {
|
||||
return { count: 0 };
|
||||
|
@ -228,6 +238,7 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => {
|
|||
|
||||
return {
|
||||
countApplications,
|
||||
countThirdPartyApplications,
|
||||
findApplications,
|
||||
findTotalNumberOfApplications,
|
||||
findApplicationById,
|
||||
|
|
|
@ -151,6 +151,12 @@ export default function applicationRoutes<T extends AuthedRouter>(
|
|||
if (rest.type === ApplicationType.MachineToMachine) {
|
||||
await quota.guardKey('machineToMachineLimit');
|
||||
}
|
||||
|
||||
// Guard third party application limit
|
||||
if (rest.isThirdParty) {
|
||||
await quota.guardKey('thirdPartyApplicationsLimit');
|
||||
}
|
||||
|
||||
await quota.guardKey('applicationsLimit');
|
||||
|
||||
assertThat(
|
||||
|
|
|
@ -3327,8 +3327,8 @@ importers:
|
|||
version: 3.22.4
|
||||
devDependencies:
|
||||
'@logto/cloud':
|
||||
specifier: 0.2.5-c6ed487
|
||||
version: 0.2.5-c6ed487(zod@3.22.4)
|
||||
specifier: 0.2.5-faca9a9
|
||||
version: 0.2.5-faca9a9(zod@3.22.4)
|
||||
'@silverhand/eslint-config':
|
||||
specifier: 5.0.0
|
||||
version: 5.0.0(eslint@8.44.0)(prettier@3.0.0)(typescript@5.3.3)
|
||||
|
|
Loading…
Reference in a new issue