mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-07-04 19:32:03 +00:00
centralize envs
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
|
||||
/* MYSQL */
|
||||
const JAMBONES_MYSQL_HOST = process.env.JAMBONES_MYSQL_HOST;
|
||||
const JAMBONES_MYSQL_USER = process.env.JAMBONES_MYSQL_USER;
|
||||
const JAMBONES_MYSQL_PORT = process.env.JAMBONES_MYSQL_PORT;
|
||||
const JAMBONES_MYSQL_PASSWORD = process.env.JAMBONES_MYSQL_PASSWORD;
|
||||
const JAMBONES_MYSQL_DATABASE = process.env.JAMBONES_MYSQL_DATABASE;
|
||||
const JAMBONES_MYSQL_CONNECTION_LIMIT = process.env.JAMBONES_MYSQL_CONNECTION_LIMIT;
|
||||
|
||||
/* Redis */
|
||||
const JAMBONES_REDIS_SENTINELS = process.env.JAMBONES_REDIS_SENTINELS;
|
||||
const JAMBONES_REDIS_SENTINEL_MASTER_NAME = process.env.JAMBONES_REDIS_SENTINEL_MASTER_NAME;
|
||||
const JAMBONES_REDIS_HOST = process.env.JAMBONES_REDIS_HOST;
|
||||
const JAMBONES_REDIS_PORT = process.env.JAMBONES_REDIS_PORT;
|
||||
|
||||
/* DRACHTIO */
|
||||
const DRACHTIO_HOST = process.env.DRACHTIO_HOST;
|
||||
const DRACHTIO_PORT = process.env.DRACHTIO_PORT;
|
||||
const DRACHTIO_SECRET = process.env.DRACHTIO_SECRET;
|
||||
|
||||
/* Application */
|
||||
const JAMBONES_TIME_SERIES_HOST = process.env.JAMBONES_TIME_SERIES_HOST;
|
||||
const JAMBONES_LOGLEVEL = process.env.JAMBONES_LOGLEVEL;
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
const SBC_PUBLIC_ADDRESS_KEEP_ALIVE_IN_MILISECOND = process.env.SBC_PUBLIC_ADDRESS_KEEP_ALIVE_IN_MILISECOND;
|
||||
const JAMBONES_HOSTING = process.env.JAMBONES_HOSTING;
|
||||
const EXPIRES_INTERVAL = process.env.EXPIRES_INTERVAL;
|
||||
const CHECK_EXPIRES_INTERVAL = process.env.CHECK_EXPIRES_INTERVAL;
|
||||
const JAMBONES_CLUSTER_ID = process.env.JAMBONES_CLUSTER_ID ;
|
||||
const JAMBONES_REGBOT_CONTACT_USE_IP = process.env.JAMBONES_REGBOT_CONTACT_USE_IP;
|
||||
|
||||
module.exports = {
|
||||
JAMBONES_MYSQL_HOST,
|
||||
JAMBONES_MYSQL_USER,
|
||||
JAMBONES_MYSQL_PORT,
|
||||
JAMBONES_MYSQL_PASSWORD,
|
||||
JAMBONES_MYSQL_DATABASE,
|
||||
JAMBONES_MYSQL_CONNECTION_LIMIT,
|
||||
JAMBONES_REDIS_SENTINELS,
|
||||
JAMBONES_REDIS_SENTINEL_MASTER_NAME,
|
||||
JAMBONES_REDIS_HOST,
|
||||
JAMBONES_REDIS_PORT,
|
||||
DRACHTIO_HOST,
|
||||
DRACHTIO_PORT,
|
||||
DRACHTIO_SECRET,
|
||||
JAMBONES_TIME_SERIES_HOST,
|
||||
JAMBONES_LOGLEVEL,
|
||||
NODE_ENV,
|
||||
SBC_PUBLIC_ADDRESS_KEEP_ALIVE_IN_MILISECOND,
|
||||
JAMBONES_HOSTING,
|
||||
EXPIRES_INTERVAL,
|
||||
CHECK_EXPIRES_INTERVAL,
|
||||
JAMBONES_CLUSTER_ID,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP
|
||||
};
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
const parseUri = require('drachtio-srf').parseUri;
|
||||
const debug = require('debug')('jambonz:sbc-registrar');
|
||||
const {NAT_EXPIRES} = require('./utils');
|
||||
const { JAMBONES_HOSTING } = require('./config');
|
||||
|
||||
const initLocals = (req, res, next) => {
|
||||
req.locals = req.locals || {};
|
||||
@@ -77,13 +78,13 @@ const checkAccountLimits = async(req, res, next) => {
|
||||
};
|
||||
debug(account, `checkAccountLimits: retrieved account for realm: ${realm}`);
|
||||
}
|
||||
else if (process.env.JAMBONES_HOSTING) {
|
||||
else if (JAMBONES_HOSTING) {
|
||||
logger.debug(`checkAccountLimits: unknown sip realm ${realm}`);
|
||||
logger.info(`checkAccountLimits: rejecting register for unknown sip realm: ${realm}`);
|
||||
return res.send(403);
|
||||
}
|
||||
|
||||
if ('unregister' === req.registration.type || !process.env.JAMBONES_HOSTING) return next();
|
||||
if ('unregister' === req.registration.type || !JAMBONES_HOSTING) return next();
|
||||
|
||||
/* only check limits on the jambonz hosted platform */
|
||||
const {account_sid} = account;
|
||||
|
||||
+10
-5
@@ -1,4 +1,9 @@
|
||||
const debug = require('debug')('jambonz:sbc-options-handler');
|
||||
const {
|
||||
EXPIRES_INTERVAL,
|
||||
CHECK_EXPIRES_INTERVAL,
|
||||
JAMBONES_CLUSTER_ID,
|
||||
} = require('./config');
|
||||
const fsServers = new Map();
|
||||
const fsServiceUrls = new Map();
|
||||
const rtpServers = new Map();
|
||||
@@ -6,14 +11,14 @@ const rtpServers = new Map();
|
||||
module.exports = ({srf, logger}) => {
|
||||
const {stats, addToSet, removeFromSet, isMemberOfSet, retrieveSet} = srf.locals;
|
||||
|
||||
const setNameFs = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-fs`;
|
||||
const setNameRtp = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:active-rtp`;
|
||||
const setNameFsSeriveUrl = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:fs-service-url`;
|
||||
const setNameFs = `${(JAMBONES_CLUSTER_ID || 'default')}:active-fs`;
|
||||
const setNameRtp = `${(JAMBONES_CLUSTER_ID || 'default')}:active-rtp`;
|
||||
const setNameFsSeriveUrl = `${(JAMBONES_CLUSTER_ID || 'default')}:fs-service-url`;
|
||||
|
||||
/* check for expired servers every so often */
|
||||
setInterval(async() => {
|
||||
const now = Date.now();
|
||||
const expires = process.env.EXPIRES_INTERVAL || 60000;
|
||||
const expires = EXPIRES_INTERVAL || 60000;
|
||||
for (const [key, value] of fsServers) {
|
||||
const duration = now - value;
|
||||
if (duration > expires) {
|
||||
@@ -44,7 +49,7 @@ module.exports = ({srf, logger}) => {
|
||||
logger.info({members}, `expired member ${key} from ${setNameRtp} we now have ${countOfMembers}`);
|
||||
}
|
||||
}
|
||||
}, process.env.CHECK_EXPIRES_INTERVAL || 20000);
|
||||
}, CHECK_EXPIRES_INTERVAL || 20000);
|
||||
|
||||
/* retrieve the initial list of servers, if any, so we can watch them as well */
|
||||
const _init = async() => {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
const debug = require('debug')('jambonz:sbc-registrar');
|
||||
const {
|
||||
JAMBONES_CLUSTER_ID,
|
||||
JAMBONES_REGBOT_CONTACT_USE_IP
|
||||
} = require('./config');
|
||||
const assert = require('assert');
|
||||
const short = require('short-uuid');
|
||||
const DEFAULT_EXPIRES = 3600;
|
||||
const MAX_INITIAL_DELAY = 15;
|
||||
const REGBOT_STATUS_CHECK_INTERVAL = 60;
|
||||
const regbotKey = `${(process.env.JAMBONES_CLUSTER_ID || 'default')}:regbot-token`;
|
||||
const regbotKey = `${(JAMBONES_CLUSTER_ID || 'default')}:regbot-token`;
|
||||
const waitFor = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
let initialized = false;
|
||||
|
||||
@@ -38,7 +42,7 @@ class Regbot {
|
||||
this.sip_realm = opts.sip_realm || opts.ipv4;
|
||||
this.ipv4 = opts.ipv4;
|
||||
this.port = opts.port;
|
||||
this.use_public_ip_in_contact = opts.use_public_ip_in_contact || process.env.JAMBONES_REGBOT_CONTACT_USE_IP;
|
||||
this.use_public_ip_in_contact = opts.use_public_ip_in_contact || JAMBONES_REGBOT_CONTACT_USE_IP;
|
||||
|
||||
this.fromUser = opts.from_user || this.username;
|
||||
const fromDomain = opts.from_domain || this.sip_realm;
|
||||
|
||||
Reference in New Issue
Block a user