|
|
|
|
@@ -126,7 +126,8 @@ const encryptCredential = (obj) => {
|
|
|
|
|
instance_id,
|
|
|
|
|
custom_stt_url,
|
|
|
|
|
custom_tts_url,
|
|
|
|
|
auth_token = ''
|
|
|
|
|
auth_token = '',
|
|
|
|
|
cobalt_server_uri
|
|
|
|
|
} = obj;
|
|
|
|
|
|
|
|
|
|
switch (vendor) {
|
|
|
|
|
@@ -196,6 +197,11 @@ const encryptCredential = (obj) => {
|
|
|
|
|
const sonioxData = JSON.stringify({api_key});
|
|
|
|
|
return encrypt(sonioxData);
|
|
|
|
|
|
|
|
|
|
case 'cobalt':
|
|
|
|
|
assert(cobalt_server_uri, 'invalid cobalt speech credential: cobalt_server_uri is required');
|
|
|
|
|
const cobaltData = JSON.stringify({cobalt_server_uri});
|
|
|
|
|
return encrypt(cobaltData);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (vendor.startsWith('custom:')) {
|
|
|
|
|
const customData = JSON.stringify({auth_token, custom_stt_url, custom_tts_url});
|
|
|
|
|
@@ -253,6 +259,72 @@ router.post('/', async(req, res) => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function decryptCredential(obj, credential, logger) {
|
|
|
|
|
if ('google' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
const key_header = '-----BEGIN PRIVATE KEY-----\n';
|
|
|
|
|
const obscured = {
|
|
|
|
|
...o,
|
|
|
|
|
private_key: `${key_header}${obscureKey(o.private_key.slice(key_header.length, o.private_key.length))}`
|
|
|
|
|
};
|
|
|
|
|
obj.service_key = obscured;
|
|
|
|
|
}
|
|
|
|
|
else if ('aws' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.access_key_id = o.access_key_id;
|
|
|
|
|
obj.secret_access_key = obscureKey(o.secret_access_key);
|
|
|
|
|
obj.aws_region = o.aws_region;
|
|
|
|
|
logger.info({obj, o}, 'retrieving aws speech credential');
|
|
|
|
|
}
|
|
|
|
|
else if ('microsoft' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
obj.region = o.region;
|
|
|
|
|
obj.use_custom_tts = o.use_custom_tts;
|
|
|
|
|
obj.custom_tts_endpoint = o.custom_tts_endpoint;
|
|
|
|
|
obj.custom_tts_endpoint_url = o.custom_tts_endpoint_url;
|
|
|
|
|
obj.use_custom_stt = o.use_custom_stt;
|
|
|
|
|
obj.custom_stt_endpoint = o.custom_stt_endpoint;
|
|
|
|
|
obj.custom_stt_endpoint_url = o.custom_stt_endpoint_url;
|
|
|
|
|
logger.info({obj, o}, 'retrieving azure speech credential');
|
|
|
|
|
}
|
|
|
|
|
else if ('wellsaid' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('nuance' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.client_id = o.client_id;
|
|
|
|
|
obj.secret = o.secret ? obscureKey(o.secret) : null;
|
|
|
|
|
}
|
|
|
|
|
else if ('deepgram' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('ibm' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.tts_api_key = obscureKey(o.tts_api_key);
|
|
|
|
|
obj.tts_region = o.tts_region;
|
|
|
|
|
obj.stt_api_key = obscureKey(o.stt_api_key);
|
|
|
|
|
obj.stt_region = o.stt_region;
|
|
|
|
|
obj.instance_id = o.instance_id;
|
|
|
|
|
} else if ('nvidia' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.riva_server_uri = o.riva_server_uri;
|
|
|
|
|
} else if ('cobalt' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.cobalt_server_uri = o.cobalt_server_uri;
|
|
|
|
|
} else if ('soniox' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
} else if (obj.vendor.startsWith('custom:')) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.auth_token = obscureKey(o.auth_token);
|
|
|
|
|
obj.custom_stt_url = o.custom_stt_url;
|
|
|
|
|
obj.custom_tts_url = o.custom_tts_url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* retrieve all speech credentials for an account
|
|
|
|
|
*/
|
|
|
|
|
@@ -279,68 +351,7 @@ router.get('/', async(req, res) => {
|
|
|
|
|
res.status(200).json(creds.map((c) => {
|
|
|
|
|
const {credential, ...obj} = c;
|
|
|
|
|
|
|
|
|
|
if ('google' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
const key_header = '-----BEGIN PRIVATE KEY-----\n';
|
|
|
|
|
const obscured = {
|
|
|
|
|
...o,
|
|
|
|
|
private_key: `${key_header}${obscureKey(o.private_key.slice(key_header.length, o.private_key.length))}`
|
|
|
|
|
};
|
|
|
|
|
obj.service_key = obscured;
|
|
|
|
|
}
|
|
|
|
|
else if ('aws' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.access_key_id = o.access_key_id;
|
|
|
|
|
obj.secret_access_key = obscureKey(o.secret_access_key);
|
|
|
|
|
obj.aws_region = o.aws_region;
|
|
|
|
|
logger.info({obj, o}, 'retrieving aws speech credential');
|
|
|
|
|
}
|
|
|
|
|
else if ('microsoft' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
obj.region = o.region;
|
|
|
|
|
obj.use_custom_tts = o.use_custom_tts;
|
|
|
|
|
obj.custom_tts_endpoint = o.custom_tts_endpoint;
|
|
|
|
|
obj.custom_tts_endpoint_url = o.custom_tts_endpoint_url;
|
|
|
|
|
obj.use_custom_stt = o.use_custom_stt;
|
|
|
|
|
obj.custom_stt_endpoint = o.custom_stt_endpoint;
|
|
|
|
|
obj.custom_stt_endpoint_url = o.custom_stt_endpoint_url;
|
|
|
|
|
logger.info({obj, o}, 'retrieving azure speech credential');
|
|
|
|
|
}
|
|
|
|
|
else if ('wellsaid' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('nuance' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.client_id = o.client_id;
|
|
|
|
|
obj.secret = o.secret ? obscureKey(o.secret) : null;
|
|
|
|
|
}
|
|
|
|
|
else if ('deepgram' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('ibm' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.tts_api_key = obscureKey(o.tts_api_key);
|
|
|
|
|
obj.tts_region = o.tts_region;
|
|
|
|
|
obj.stt_api_key = obscureKey(o.stt_api_key);
|
|
|
|
|
obj.stt_region = o.stt_region;
|
|
|
|
|
obj.instance_id = o.instance_id;
|
|
|
|
|
} else if ('nvidia' == obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.riva_server_uri = o.riva_server_uri;
|
|
|
|
|
}
|
|
|
|
|
else if ('soniox' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if (obj.vendor.startsWith('custom:')) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.auth_token = obscureKey(o.auth_token);
|
|
|
|
|
obj.custom_stt_url = o.custom_stt_url;
|
|
|
|
|
obj.custom_tts_url = o.custom_tts_url;
|
|
|
|
|
}
|
|
|
|
|
decryptCredential(obj, credential, logger);
|
|
|
|
|
|
|
|
|
|
if (req.user.hasAccountAuth && obj.account_sid === null) {
|
|
|
|
|
delete obj.api_key;
|
|
|
|
|
@@ -370,68 +381,7 @@ router.get('/:sid', async(req, res) => {
|
|
|
|
|
await validateRetrieveUpdateDelete(req, cred);
|
|
|
|
|
|
|
|
|
|
const {credential, ...obj} = cred[0];
|
|
|
|
|
if ('google' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
const key_header = '-----BEGIN PRIVATE KEY-----\n';
|
|
|
|
|
const obscured = {
|
|
|
|
|
...o,
|
|
|
|
|
private_key: `${key_header}${obscureKey(o.private_key.slice(key_header.length, o.private_key.length))}`
|
|
|
|
|
};
|
|
|
|
|
obj.service_key = JSON.stringify(obscured);
|
|
|
|
|
}
|
|
|
|
|
else if ('aws' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.access_key_id = o.access_key_id;
|
|
|
|
|
obj.secret_access_key = obscureKey(o.secret_access_key);
|
|
|
|
|
obj.aws_region = o.aws_region;
|
|
|
|
|
}
|
|
|
|
|
else if ('microsoft' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
obj.region = o.region;
|
|
|
|
|
obj.use_custom_tts = o.use_custom_tts;
|
|
|
|
|
obj.custom_tts_endpoint = o.custom_tts_endpoint;
|
|
|
|
|
obj.custom_tts_endpoint_url = o.custom_tts_endpoint_url;
|
|
|
|
|
obj.use_custom_stt = o.use_custom_stt;
|
|
|
|
|
obj.custom_stt_endpoint = o.custom_stt_endpoint;
|
|
|
|
|
obj.custom_stt_endpoint_url = o.custom_stt_endpoint_url;
|
|
|
|
|
}
|
|
|
|
|
else if ('wellsaid' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('nuance' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.client_id = o.client_id;
|
|
|
|
|
obj.secret = o.secret ? obscureKey(o.secret) : null;
|
|
|
|
|
obj.nuance_tts_uri = o.nuance_tts_uri;
|
|
|
|
|
obj.nuance_stt_uri = o.nuance_stt_uri;
|
|
|
|
|
}
|
|
|
|
|
else if ('deepgram' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if ('ibm' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.tts_api_key = obscureKey(o.tts_api_key);
|
|
|
|
|
obj.tts_region = o.tts_region;
|
|
|
|
|
obj.stt_api_key = obscureKey(o.stt_api_key);
|
|
|
|
|
obj.stt_region = o.stt_region;
|
|
|
|
|
obj.instance_id = o.instance_id;
|
|
|
|
|
} else if ('nvidia' == obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.riva_server_uri = o.riva_server_uri;
|
|
|
|
|
}
|
|
|
|
|
else if ('soniox' === obj.vendor) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.api_key = obscureKey(o.api_key);
|
|
|
|
|
}
|
|
|
|
|
else if (obj.vendor.startsWith('custom:')) {
|
|
|
|
|
const o = JSON.parse(decrypt(credential));
|
|
|
|
|
obj.auth_token = obscureKey(o.auth_token);
|
|
|
|
|
obj.custom_stt_url = o.custom_stt_url;
|
|
|
|
|
obj.custom_tts_url = o.custom_tts_url;
|
|
|
|
|
}
|
|
|
|
|
decryptCredential(obj, credential, logger);
|
|
|
|
|
|
|
|
|
|
if (req.user.hasAccountAuth && obj.account_sid === null) {
|
|
|
|
|
delete obj.api_key;
|
|
|
|
|
@@ -503,7 +453,8 @@ router.put('/:sid', async(req, res) => {
|
|
|
|
|
custom_stt_endpoint,
|
|
|
|
|
custom_stt_endpoint_url,
|
|
|
|
|
custom_stt_url,
|
|
|
|
|
custom_tts_url
|
|
|
|
|
custom_tts_url,
|
|
|
|
|
cobalt_server_uri
|
|
|
|
|
} = req.body;
|
|
|
|
|
|
|
|
|
|
const newCred = {
|
|
|
|
|
@@ -523,7 +474,8 @@ router.put('/:sid', async(req, res) => {
|
|
|
|
|
nuance_stt_uri,
|
|
|
|
|
nuance_tts_uri,
|
|
|
|
|
custom_stt_url,
|
|
|
|
|
custom_tts_url
|
|
|
|
|
custom_tts_url,
|
|
|
|
|
cobalt_server_uri
|
|
|
|
|
};
|
|
|
|
|
logger.info({o, newCred}, 'updating speech credential with this new credential');
|
|
|
|
|
obj.credential = encryptCredential(newCred);
|
|
|
|
|
|