Skip to content

Commit 2428657

Browse files
committed
Add realm limit settings (#151)
1 parent 73d3668 commit 2428657

File tree

15 files changed

+160
-13
lines changed

15 files changed

+160
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
99
- Introduce new administrative channel management endpoints `/admin/v1/realms/{realmId}/channels`.
1010
- Introduce new administrative subscription management endpoints `/admin/v1/realms/{realmId}/subscriptions`.
1111
- Introduce new administrative endpoint for deleting auth tokens `DELETE /admin/v1/realms/{realmId}/tokens/{tokenId}`
12+
- Introduce limit settings on realm level ([#151]).
1213

1314
### Changed
1415
- Add support for upgraded verneMQ broker. This requires the acceptance of their [EULA](https://vernemq.com/end-user-license-agreement/),
@@ -20,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2021
- Hide secret `auth.token` from all responses, except token creation, to avoid access right escalation. ([#138])
2122

2223
[#138]: https://github.com/realmq/realmq-platform/issues/138
24+
[#151]: https://github.com/realmq/realmq-platform/issues/151
2325

2426
## [0.2.0] - 2023-03-09
2527

src/api/admin/v1/mappers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const authList = require('./auth-list');
33
const channel = require('./channel');
44
const channelList = require('./channel-list');
55
const realm = require('./realm');
6+
const realmDetails = require('./realm-details');
67
const realmList = require('./realm-list');
78
const subscription = require('./subscription');
89
const subscriptionList = require('./subscription-list');
@@ -18,6 +19,7 @@ module.exports = {
1819
channel,
1920
channelList,
2021
realm,
22+
realmDetails,
2123
realmList,
2224
subscription,
2325
subscriptionList,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const mapRealm = require('./realm');
2+
const mapGenericEntity = require('../../../../lib/mappers/generic-entity');
3+
4+
/**
5+
* @class RealmViewModel
6+
* @property {string} id
7+
* @property {string} name
8+
* @property {Date} createdAt
9+
* @property {Date} updatedAt
10+
*/
11+
/**
12+
* Map a realm to detail response view model
13+
* @param {object} args
14+
* @param {RealmModel} args.realm The realm entity
15+
* @param {RealmLimitsModel} args.realmLimits The realm limits entity
16+
* @return {RealmViewModel} The realm view model
17+
*/
18+
module.exports = ({realm, realmLimits}) => ({
19+
...mapRealm(realm),
20+
limits: mapGenericEntity({
21+
entity: realmLimits,
22+
propertyMap: {
23+
maxConnections: 'maxConnections',
24+
sessionMaxMessageRate: 'sessionMaxMessageRate',
25+
sessionMaxConnectionLifetime: 'sessionMaxConnectionLifetime',
26+
sessionMaxMessageSize: 'sessionMaxMessageSize',
27+
}
28+
}),
29+
});
30+

src/api/admin/v1/mappers/realm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mapGenericEntity = require('../../../../lib/mappers/generic-entity');
88
* @property {Date} updatedAt
99
*/
1010
/**
11-
* Map an realm to response view model
11+
* Map a realm to response view model
1212
* @param {RealmModel} realm The realm entity
1313
* @return {RealmViewModel} The realm view model
1414
*/

src/api/admin/v1/openapi/definitions.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,39 @@ TimestampsTrait:
7474
Realm:
7575
allOf:
7676
- $ref: '#/definitions/BaseEntity'
77-
- properties:
77+
- type: object
78+
properties:
7879
name:
7980
type: string
8081
required:
8182
- name
8283
- $ref: '#/definitions/TimestampsTrait'
8384

85+
RealmDetails:
86+
allOf:
87+
- $ref: '#/definitions/Realm'
88+
- type: object
89+
properties:
90+
limits:
91+
$ref: '#/definitions/RealmLimits'
92+
93+
RealmLimits:
94+
type: object
95+
properties:
96+
maxConnections:
97+
description: Maximum number of simultaneously online connections
98+
type: integer
99+
sessionMaxMessageRate:
100+
description: Maximum incoming publish rate per session per second
101+
type: integer
102+
sessionMaxConnectionLifetime:
103+
description: Maximum lifetime of a connection in seconds
104+
type: integer
105+
sessionMaxMessageSize:
106+
description: Maximum size of a message payload in bytes
107+
type: integer
108+
additionalProperties: false
109+
84110
RealmList:
85111
allOf:
86112
- $ref: '#/definitions/BaseList'

src/api/admin/v1/routes/realms.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ module.exports = (tasks, mappers) => ({
1616
},
1717

1818
async post(request, response) {
19-
const {body: {name}} = request;
20-
const {ok, result: realm, error} = await tasks.admin.createRealm({name});
19+
const {body: {name, limits = {}}} = request;
20+
const {ok, result, error} = await tasks.admin.createRealm({name, limits});
2121

2222
if (!ok) {
2323
throw error;
2424
}
2525

26-
return response.status(201).json(mappers.realm(realm));
26+
return response.status(201).json(mappers.realm({
27+
realm: result.realm,
28+
realmLimits: result.realmLimits
29+
}));
2730
},
2831
});

src/api/admin/v1/routes/realms.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
name:
4141
description: The name of the real, eg. project/org name
4242
type: string
43+
limits:
44+
$ref: '#/definitions/RealmLimits'
4345
responses:
4446
201:
4547
description: Realm was successfully created.
4648
schema:
47-
$ref: '#/definitions/Realm'
49+
$ref: '#/definitions/RealmDetails'
4850
400:
4951
description: Request validation failed.
5052
401:

src/bootstrap/repositories.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = async ({db}) => {
1212
channelCollection,
1313
messageCollection,
1414
realmCollection,
15+
realmLimitsCollection,
1516
realtimeConnectionCollection,
1617
subscriptionCollection,
1718
userCollection,
@@ -20,6 +21,7 @@ module.exports = async ({db}) => {
2021
db.collection('channels'),
2122
db.collection('messages'),
2223
db.collection('realms'),
24+
db.collection('realm-limits'),
2325
db.collection('realtime-connections'),
2426
db.collection('subscriptions'),
2527
db.collection('users'),
@@ -29,6 +31,7 @@ module.exports = async ({db}) => {
2931
channelCollection,
3032
messageCollection,
3133
realmCollection,
34+
realmLimitsCollection,
3235
realtimeConnectionCollection,
3336
subscriptionCollection,
3437
userCollection,

src/bootstrap/tasks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = ({
2626
channel: channelRepository,
2727
message: messageRepository,
2828
realm: realmRepository,
29+
realmLimits: realmLimitsRepository,
2930
realtimeConnection: realtimeConnectionRepository,
3031
subscription: subscriptionRepository,
3132
user: userRepository,
@@ -44,6 +45,7 @@ module.exports = ({
4445
authRepository,
4546
channelRepository,
4647
realmRepository,
48+
realmLimitsRepository,
4749
subscriptionRepository,
4850
userRepository,
4951
sendSubscriptionSyncMessage,
@@ -54,6 +56,7 @@ module.exports = ({
5456
authRepository,
5557
channelRepository,
5658
subscriptionRepository,
59+
realmLimitsRepository,
5760
realtimeConnectionRepository,
5861
messageRepository,
5962
userRepository,

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ const createLogger = require('./lib/logger');
3434
process.exit(1);
3535
}
3636
})();
37+

0 commit comments

Comments
 (0)