Skip to content

Commit

Permalink
Feature/retrieve registered users (#243)
Browse files Browse the repository at this point in the history
* add GET /Accounts/:sid/RegisteredSipUsers

* fix vulnerabilities
  • Loading branch information
davehorton authored Oct 22, 2023
1 parent a1c302f commit 7b80513
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 311 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rateLimit = require('express-rate-limit');
const cors = require('cors');
const passport = require('passport');
const routes = require('./lib/routes');
const Registrar = require('@jambonz/mw-registrar');

assert.ok(process.env.JAMBONES_MYSQL_HOST &&
process.env.JAMBONES_MYSQL_USER &&
Expand Down Expand Up @@ -35,6 +36,7 @@ const {
logger, process.env.JAMBONES_TIME_SERIES_HOST
);
const {
client,
retrieveCall,
deleteCall,
listCalls,
Expand Down Expand Up @@ -81,6 +83,7 @@ passport.use(authStrategy);
app.locals = app.locals || {};
app.locals = {
...app.locals,
registrar: new Registrar(logger, client),
logger,
retrieveCall,
deleteCall,
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers/realtimedb-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const JAMBONES_REDIS_SENTINELS = process.env.JAMBONES_REDIS_SENTINELS ? {
} : null;

const {
client,
retrieveCall,
deleteCall,
listCalls,
Expand All @@ -42,6 +43,7 @@ const {
}, logger);

module.exports = {
client,
retrieveCall,
deleteCall,
listCalls,
Expand Down
15 changes: 15 additions & 0 deletions lib/routes/api/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ router.post('/:sid/VoipCarriers', async(req, res) => {
sysError(logger, res, err);
}
});
router.get('/:sid/RegisteredSipUsers', async(req, res) => {
const {logger, registrar} = req.app.locals;
try {
const account_sid = parseAccountSid(req);
await validateRequest(req, account_sid);
const result = await Account.retrieve(account_sid);
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`account not found for sid ${account_sid}`);
}
const users = await registrar.getRegisteredUsersForRealm(result[0].sip_realm);
res.status(200).json(users.map((u) => `${u}@${result[0].sip_realm}`));
} catch (err) {
sysError(logger, res, err);
}
});

function coerceNumbers(callInfo) {
if (Array.isArray(callInfo)) {
Expand Down
22 changes: 22 additions & 0 deletions lib/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,28 @@ paths:
type: string
length:
type: string
/Accounts/{AccountSid}/RegisteredSipUsers:
parameters:
- name: AccountSid
in: path
required: true
schema:
type: string
format: uuid
get:
tags:
- Accounts
summary: retrieve online sip users for an account
operationId: listQueues

This comment has been minimized.

Copy link
@avoylenko

avoylenko Oct 22, 2023

Contributor

should be unique value

responses:
200:
description: retrieve online sip users for an account
content:
application/json:
schema:
type: array
items:
type: string
/Lcrs:
post:
tags:
Expand Down
Loading

0 comments on commit 7b80513

Please sign in to comment.