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"
|
"zod": "^3.22.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@logto/cloud": "0.2.5-c6ed487",
|
"@logto/cloud": "0.2.5-faca9a9",
|
||||||
"@silverhand/eslint-config": "5.0.0",
|
"@silverhand/eslint-config": "5.0.0",
|
||||||
"@silverhand/ts-config": "5.0.0",
|
"@silverhand/ts-config": "5.0.0",
|
||||||
"@types/debug": "^4.1.7",
|
"@types/debug": "^4.1.7",
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const createQuotaLibrary = (
|
||||||
connectorLibrary: ConnectorLibrary
|
connectorLibrary: ConnectorLibrary
|
||||||
) => {
|
) => {
|
||||||
const {
|
const {
|
||||||
applications: { countAllApplications, countM2mApplications },
|
applications: { countThirdPartyApplications, countAllApplications, countM2mApplications },
|
||||||
resources: { findTotalNumberOfResources },
|
resources: { findTotalNumberOfResources },
|
||||||
hooks: { getTotalNumberOfHooks },
|
hooks: { getTotalNumberOfHooks },
|
||||||
roles: { countRoles },
|
roles: { countRoles },
|
||||||
|
@ -38,6 +38,7 @@ export const createQuotaLibrary = (
|
||||||
(queryKey?: string) => Promise<{ count: number }>
|
(queryKey?: string) => Promise<{ count: number }>
|
||||||
> = {
|
> = {
|
||||||
applicationsLimit: countAllApplications,
|
applicationsLimit: countAllApplications,
|
||||||
|
thirdPartyApplicationsLimit: countThirdPartyApplications,
|
||||||
hooksLimit: getTotalNumberOfHooks,
|
hooksLimit: getTotalNumberOfHooks,
|
||||||
machineToMachineLimit: countM2mApplications,
|
machineToMachineLimit: countM2mApplications,
|
||||||
resourcesLimit: async () => {
|
resourcesLimit: async () => {
|
||||||
|
|
|
@ -161,6 +161,16 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => {
|
||||||
return { count: Number(count) };
|
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[]) => {
|
const countM2mApplicationsByIds = async (search: Search, applicationIds: string[]) => {
|
||||||
if (applicationIds.length === 0) {
|
if (applicationIds.length === 0) {
|
||||||
return { count: 0 };
|
return { count: 0 };
|
||||||
|
@ -228,6 +238,7 @@ export const createApplicationQueries = (pool: CommonQueryMethods) => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
countApplications,
|
countApplications,
|
||||||
|
countThirdPartyApplications,
|
||||||
findApplications,
|
findApplications,
|
||||||
findTotalNumberOfApplications,
|
findTotalNumberOfApplications,
|
||||||
findApplicationById,
|
findApplicationById,
|
||||||
|
|
|
@ -151,6 +151,12 @@ export default function applicationRoutes<T extends AuthedRouter>(
|
||||||
if (rest.type === ApplicationType.MachineToMachine) {
|
if (rest.type === ApplicationType.MachineToMachine) {
|
||||||
await quota.guardKey('machineToMachineLimit');
|
await quota.guardKey('machineToMachineLimit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guard third party application limit
|
||||||
|
if (rest.isThirdParty) {
|
||||||
|
await quota.guardKey('thirdPartyApplicationsLimit');
|
||||||
|
}
|
||||||
|
|
||||||
await quota.guardKey('applicationsLimit');
|
await quota.guardKey('applicationsLimit');
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
|
@ -3327,8 +3327,8 @@ importers:
|
||||||
version: 3.22.4
|
version: 3.22.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@logto/cloud':
|
'@logto/cloud':
|
||||||
specifier: 0.2.5-c6ed487
|
specifier: 0.2.5-faca9a9
|
||||||
version: 0.2.5-c6ed487(zod@3.22.4)
|
version: 0.2.5-faca9a9(zod@3.22.4)
|
||||||
'@silverhand/eslint-config':
|
'@silverhand/eslint-config':
|
||||||
specifier: 5.0.0
|
specifier: 5.0.0
|
||||||
version: 5.0.0(eslint@8.44.0)(prettier@3.0.0)(typescript@5.3.3)
|
version: 5.0.0(eslint@8.44.0)(prettier@3.0.0)(typescript@5.3.3)
|
||||||
|
|
Loading…
Reference in a new issue