Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add realm limit settings (#151) #152

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lint issues (#151)
baranga committed Aug 2, 2023
commit 5c66989bd12d925f2a4f49952f3467221dc61a0e
4 changes: 2 additions & 2 deletions src/api/admin/v1/mappers/realm-details.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mapRealm = require('./realm');
const mapGenericEntity = require('../../../../lib/mappers/generic-entity');
const mapRealm = require('./realm');

/**
* @class RealmViewModel
@@ -24,7 +24,7 @@ module.exports = ({realm, realmLimits}) => ({
sessionMaxMessageRate: 'sessionMaxMessageRate',
sessionMaxConnectionLifetime: 'sessionMaxConnectionLifetime',
sessionMaxMessageSize: 'sessionMaxMessageSize',
}
},
}),
});

2 changes: 1 addition & 1 deletion src/api/admin/v1/routes/realms.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ module.exports = (tasks, mappers) => ({

return response.status(201).json(mappers.realmDetails({
realm: result.realm,
realmLimits: result.realmLimits
realmLimits: result.realmLimits,
}));
},
});
2 changes: 1 addition & 1 deletion src/api/admin/v1/routes/realms/{id}.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ module.exports = (tasks, mappers) => ({

response.json(mappers.realmDetails({
realm: result.realm,
realmLimits: result.realmLimits
realmLimits: result.realmLimits,
}));
},
});
1 change: 1 addition & 0 deletions src/api/broker/v1/routes/vmq/auth-on-register.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ module.exports = ({authorizeRegister}) =>
}

const modifiers = stripUndefined({
// eslint-disable-next-line camelcase
max_message_size: realmLimits?.sessionMaxMessageSize,
});

2 changes: 1 addition & 1 deletion src/repositories/realm-limits.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ module.exports = ({collection, createModel = createRealmLimitsModel}) => {
*/
async findOneByRealmId(realmId) {
return mongoRepo.findOne({realmId});
}
},
};
};

2 changes: 1 addition & 1 deletion src/tasks/admin/create-realm.js
Original file line number Diff line number Diff line change
@@ -18,4 +18,4 @@ module.exports = ({realmRepository, realmLimitsRepository}) =>
const realm = await realmRepository.create({name});
const realmLimits = await realmLimitsRepository.create({realmId: realm.id, ...limits});
return success({realm, realmLimits});
}
};
4 changes: 2 additions & 2 deletions src/tasks/admin/fetch-realm.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ module.exports = ({realmRepository, realmLimitsRepository}) =>
async ({id}) => {
const [realm, realmLimits] = await Promise.all([
realmRepository.findOne({id}),
realmLimitsRepository.findOneByRealmId(id)
realmLimitsRepository.findOneByRealmId(id),
]);
return success({realm, realmLimits});
}
};
14 changes: 7 additions & 7 deletions src/tasks/broker/authorize-register.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
module.exports = ({
authenticateClient,
realmLimitsRepository,
realtimeConnectionRepository
realtimeConnectionRepository,
}) =>
/**
* Authorize client connection
@@ -21,22 +21,22 @@ module.exports = ({
return {authorized: false};
}

const [realmLimits, numOfRealmConnections] = await Promise.all([
const [realmLimits, numberOfRealmConnections] = await Promise.all([
realmLimitsRepository.findOneByRealmId(client.realmId),
realtimeConnectionRepository.countByRealmId(client.realmId),
]);

if (
realmLimits &&
isFinite(realmLimits.maxConnections) &&
realmLimits.maxConnections > 0 &&
realmLimits.maxConnections < numOfRealmConnections
realmLimits
&& Number.isFinite(realmLimits.maxConnections)
&& realmLimits.maxConnections > 0
&& realmLimits.maxConnections < numberOfRealmConnections
) {
return {authorized: false};
}

return {
authorized: true,
realmLimits,
}
};
};
2 changes: 1 addition & 1 deletion src/tasks/broker/index.js
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ module.exports = ({
initAuthorizeRegister({
authenticateClient,
realmLimitsRepository,
realtimeConnectionRepository
realtimeConnectionRepository,
}),
authorizeSubscribe:
initAuthorizeSubscribe({loadTopicPermissions, rewriteTopicToInternal}),