@jambonz/speech-utils 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,16 +5,16 @@ const EXPIRY = 3600;
5
5
 
6
6
  async function getAwsAuthToken(
7
7
  logger, createHash, retrieveHash,
8
- awsAccessKeyId, awsSecretAccessKey, awsRegion, roleArn = null) {
8
+ {accessKeyId, secretAccessKey, region, roleArn}) {
9
9
  logger = logger || noopLogger;
10
10
  try {
11
- const key = makeAwsKey(roleArn || awsAccessKeyId);
11
+ const key = makeAwsKey(roleArn || accessKeyId);
12
12
  const obj = await retrieveHash(key);
13
13
  if (obj) return {...obj, servedFromCache: true};
14
14
 
15
15
  let data;
16
16
  if (roleArn) {
17
- const stsClient = new STSClient({ region: awsRegion});
17
+ const stsClient = new STSClient({ region });
18
18
  const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz_Speech', DurationSeconds: EXPIRY};
19
19
  const command = new AssumeRoleCommand(roleToAssume);
20
20
 
@@ -22,10 +22,10 @@ async function getAwsAuthToken(
22
22
  } else {
23
23
  /* access token not found in cache, so generate it using STS */
24
24
  const stsClient = new STSClient({
25
- region: awsRegion,
25
+ region,
26
26
  credentials: {
27
- accessKeyId: awsAccessKeyId,
28
- secretAccessKey: awsSecretAccessKey,
27
+ accessKeyId,
28
+ secretAccessKey,
29
29
  }
30
30
  });
31
31
  const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
@@ -107,7 +107,12 @@ const getAwsVoices = async(_client, createHash, retrieveHash, logger, credential
107
107
  } else if (roleArn) {
108
108
  client = new PollyClient({
109
109
  region,
110
- credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
110
+ credentials: await getAwsAuthToken(
111
+ logger, createHash, retrieveHash,
112
+ {
113
+ region,
114
+ roleArn
115
+ }),
111
116
  });
112
117
  } else {
113
118
  client = new PollyClient({region});
@@ -281,7 +281,12 @@ const synthPolly = async(createHash, retrieveHash, logger,
281
281
  } else if (roleArn) {
282
282
  polly = new PollyClient({
283
283
  region,
284
- credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
284
+ credentials: await getAwsAuthToken(
285
+ logger, createHash, retrieveHash,
286
+ {
287
+ region,
288
+ roleArn
289
+ }),
285
290
  });
286
291
  } else {
287
292
  // AWS RoleArn assigned to Instance profile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/speech-utils",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "TTS-related speech utilities for jambonz",
5
5
  "main": "index.js",
6
6
  "author": "Dave Horton",
package/test/aws.js CHANGED
@@ -19,12 +19,20 @@ test('AWS - create and cache auth token', async(t) => {
19
19
  return;
20
20
  }
21
21
  try {
22
- let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
22
+ let obj = await getAwsAuthToken({
23
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
24
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
25
+ region: process.env.AWS_REGION
26
+ });
23
27
  //console.log({obj}, 'received auth token from AWS');
24
28
  t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
25
29
 
26
30
  await sleep(250);
27
- obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
31
+ obj = await getAwsAuthToken({
32
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
33
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
34
+ region: process.env.AWS_REGION
35
+ });
28
36
  //console.log({obj}, 'received auth token from AWS - second request');
29
37
  t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
30
38