aws-core-utils
Advanced tools
Comparing version 4.0.0 to 5.0.0
158
arns.js
@@ -26,2 +26,3 @@ 'use strict'; | ||
const trimOrEmpty = Strings.trimOrEmpty; | ||
const isBlank = Strings.isBlank; | ||
const isNotBlank = Strings.isNotBlank; | ||
@@ -34,3 +35,2 @@ | ||
const ACCOUNT_ID_INDEX = 4; | ||
const RESOURCE_OR_TYPE_INDEX = 5; // index of a resource (without a resource type) or a resource type | ||
@@ -85,2 +85,13 @@ /** | ||
/** | ||
* ARN resource-related components | ||
* @typedef {Object} ArnResources | ||
* @property {string} resourceType - a resource type (for DynamoDB stream eventSourceARN's this contains "table") | ||
* @property {string} resource - a resource name (for DynamoDB stream eventSourceARN's this is the table name) | ||
* @property {string} subResourceType - a sub-resource type (for DynamoDB stream eventSourceARN's this contains "stream") | ||
* @property {string} subResource - a sub-resource name (for DynamoDB stream eventSourceARN's this is the stream timestamp) | ||
* @property {string} aliasOrVersion - a Lambda alias or version number | ||
* @property {string[]} others - any other components after a Lambda alias or version number | ||
*/ | ||
/** | ||
* Attempts to extract any and all resource-related components from the given ARN (if defined) and returns them as | ||
@@ -91,49 +102,122 @@ * an object containing resourceType, resource, aliasOrVersion and others (just in case there were even more components | ||
* Currently handles the following cases: | ||
* - arn:partition:service:region:account-id:resource | ||
* - arn:partition:service:region:account-id:resourcetype/resource | ||
* - arn:partition:service:region:account-id:resourcetype:resource | ||
* - arn:partition:service:region:account-id:resourcetype:resource:alias_or_version (e.g. Lambda invokedFunctionArns) | ||
* - arn:partition:service:region:account-id:resourcetype:resource:alias_or_version[:other]* (just in case more) | ||
* - CASE 1: arn:partition:service:region:account-id:resource | ||
* - CASE 2: arn:partition:service:region:account-id:resourcetype/resource | ||
* - CASE 3: arn:partition:service:region:account-id:resourcetype/resource/subResourceType/subResource | ||
* - CASE 4: arn:partition:service:region:account-id:resourcetype:resource | ||
* - CASE 5: arn:partition:service:region:account-id:resourcetype:resource:alias_or_version (e.g. Lambda invokedFunctionArns) | ||
* - CASE 6: arn:partition:service:region:account-id:resourcetype:resource:alias_or_version[:other]* (just in case more) | ||
* | ||
* e.g. of CASE 3: arn:aws:dynamodb:us-east-1:111111111111:table/test/stream/2020-10-10T08:18:22.385 | ||
* | ||
* @param {string} arn the ARN from which to extract the resource-related components | ||
* @returns {{resourceType: string, resource: string, aliasOrVersion: string, others: string[]}} an object containing | ||
* resourceType, resource, aliasOrVersion and others properties. | ||
* @returns {ArnResources} an object containing the resource-related components | ||
*/ | ||
function getArnResources(arn) { | ||
//return {resourceType: '', resource: '', aliasOrVersion: '', others: ['','']}; | ||
const components = isNotBlank(arn) ? trim(arn).split(':') : []; | ||
if (isBlank(arn)) { | ||
return {resourceType: '', resource: '', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
} | ||
const arn1 = trim(arn); | ||
const resourceIndex = Strings.nthIndexOf(arn1, ':', 5); | ||
if (resourceIndex === -1) { | ||
return {resourceType: '', resource: '', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
} | ||
const resourceSection = arn1.substring(resourceIndex + 1); | ||
const firstSlashIndex = resourceSection.indexOf('/'); | ||
const firstColonIndex = resourceSection.indexOf(':'); | ||
// Identify which case we are dealing with | ||
if (components.length === RESOURCE_OR_TYPE_INDEX + 1) { | ||
// Must be either only 'resource' or 'resourcetype/resource' case | ||
const resourceOrType = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX]); | ||
if (firstSlashIndex === -1 && firstColonIndex === -1) { | ||
// CASE 1: arn:partition:service:region:account-id:resource | ||
return { | ||
resourceType: '', | ||
resource: resourceSection, | ||
subResourceType: '', | ||
subResource: '', | ||
aliasOrVersion: '', | ||
others: [] | ||
}; | ||
} else if (firstSlashIndex !== -1 && (firstColonIndex === -1 || firstSlashIndex < firstColonIndex)) { | ||
// Slash cases | ||
const resourceType = trimOrEmpty(resourceSection.substring(0, firstSlashIndex)); | ||
const lastSlashPos = resourceOrType ? resourceOrType.lastIndexOf('/') : -1; | ||
if (lastSlashPos != -1) { | ||
// CASE: arn:partition:service:region:account-id:resourcetype/resource | ||
const resourceType = trimOrEmpty(resourceOrType.substring(0, lastSlashPos)); | ||
const resource = trimOrEmpty(resourceOrType.substring(lastSlashPos + 1)); | ||
return {resourceType: resourceType, resource: resource, aliasOrVersion: '', others: []}; | ||
const secondSlashIndex = Strings.nthIndexOf(resourceSection, '/', 2); | ||
const thirdSlashIndex = Strings.nthIndexOf(resourceSection, '/', 3); | ||
if (secondSlashIndex !== -1 && thirdSlashIndex !== -1) { | ||
// CASE 3: arn:partition:service:region:account-id:resourcetype/resource/subResourceType/subResource | ||
// e.g. arn:partition:service:region:account-id:table/{table_name}/stream/{2020-10-10T08:18:22.385} | ||
const resource = trimOrEmpty(resourceSection.substring(firstSlashIndex + 1, secondSlashIndex)); | ||
const subResourceType = trimOrEmpty(resourceSection.substring(secondSlashIndex + 1, thirdSlashIndex)); | ||
const subResource = trimOrEmpty(resourceSection.substring(thirdSlashIndex + 1)); | ||
return { | ||
resourceType: resourceType, | ||
resource: resource, | ||
subResourceType: subResourceType, | ||
subResource: subResource, | ||
aliasOrVersion: '', | ||
others: [] | ||
}; | ||
} else { | ||
// CASE: arn:partition:service:region:account-id:resource | ||
const resource = resourceOrType ? resourceOrType : ''; | ||
return {resourceType: '', resource: resource, aliasOrVersion: '', others: []} | ||
// CASE 2: arn:partition:service:region:account-id:resourcetype/resource | ||
const resource = trimOrEmpty(resourceSection.substring(firstSlashIndex + 1)); | ||
return { | ||
resourceType: resourceType, | ||
resource: resource, | ||
subResourceType: '', | ||
subResource: '', | ||
aliasOrVersion: '', | ||
others: [] | ||
}; | ||
} | ||
} else if (components.length === RESOURCE_OR_TYPE_INDEX + 2) { | ||
// CASE: arn:partition:service:region:account-id:resourcetype:resource | ||
const resourceType = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX]); | ||
const resource = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX + 1]); | ||
return {resourceType: resourceType, resource: resource, aliasOrVersion: '', others: []}; | ||
} else { | ||
// Colon cases | ||
const resourceType = trimOrEmpty(resourceSection.substring(0, firstColonIndex)); | ||
} else if (components.length > RESOURCE_OR_TYPE_INDEX + 2) { | ||
// CASE: arn:partition:service:region:account-id:resourcetype:resource[:aliasOrVersion] (e.g. Lambda invokedFunctionArns) | ||
const resourceType = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX]); | ||
const resource = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX + 1]); | ||
const aliasOrVersion = trimOrEmpty(components[RESOURCE_OR_TYPE_INDEX + 2]); | ||
const others = components.slice(RESOURCE_OR_TYPE_INDEX + 3).map(trim); | ||
return {resourceType: resourceType, resource: resource, aliasOrVersion: aliasOrVersion, others: others}; | ||
const secondColonIndex = Strings.nthIndexOf(resourceSection, ':', 2); | ||
if (secondColonIndex === -1) { | ||
// CASE 4: arn:partition:service:region:account-id:resourcetype:resource | ||
const resource = trimOrEmpty(resourceSection.substring(firstColonIndex + 1)); | ||
return { | ||
resourceType: resourceType, | ||
resource: resource, | ||
subResourceType: '', | ||
subResource: '', | ||
aliasOrVersion: '', | ||
others: [] | ||
}; | ||
} else { | ||
const resource = trimOrEmpty(resourceSection.substring(firstColonIndex + 1, secondColonIndex)); | ||
const thirdColonIndex = Strings.nthIndexOf(resourceSection, ':', 3); | ||
if (thirdColonIndex === -1) { | ||
// CASE 5: arn:partition:service:region:account-id:resourcetype:resource:alias_or_version (e.g. Lambda invokedFunctionArns) | ||
const aliasOrVersion = trimOrEmpty(resourceSection.substring(secondColonIndex + 1)); | ||
return { | ||
resourceType: resourceType, | ||
resource: resource, | ||
subResourceType: '', | ||
subResource: '', | ||
aliasOrVersion: aliasOrVersion, | ||
others: [] | ||
}; | ||
} else { | ||
// CASE 6: arn:partition:service:region:account-id:resourcetype:resource:alias_or_version[:other]* (just in case more) | ||
const aliasOrVersion = trimOrEmpty(resourceSection.substring(secondColonIndex + 1, thirdColonIndex)); | ||
const others = trimOrEmpty(resourceSection.substring(thirdColonIndex + 1)).split(':'); | ||
return { | ||
resourceType: resourceType, | ||
resource: resource, | ||
subResourceType: '', | ||
subResource: '', | ||
aliasOrVersion: aliasOrVersion, | ||
others: others | ||
}; | ||
} | ||
} | ||
} | ||
// No resource-related components available from which to extract anything | ||
return {resourceType: '', resource: '', aliasOrVersion: '', others: []}; | ||
} |
{ | ||
"name": "aws-core-utils", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.", | ||
@@ -14,4 +14,4 @@ "author": "Byron du Preez", | ||
"dependencies": { | ||
"core-functions": "^2.0.3", | ||
"logging-utils": "^2.0.4", | ||
"core-functions": "^2.0.5", | ||
"logging-utils": "^3.0.0", | ||
"deep-equal": "^1.0.1" | ||
@@ -18,0 +18,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# aws-core-utils v4.0.0 | ||
# aws-core-utils v5.0.0 | ||
@@ -173,6 +173,6 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc. | ||
const settings = undefined; // ... or your own custom settings | ||
const options = require('./config.json'); // ... or your own custom options | ||
const options = require('./stages-options.json'); // ... or your own custom options | ||
// ... EITHER using the default stage handling configuration partially customised via config.stageHandlingOptions | ||
stages.configureDefaultStageHandling(context, options.stageHandlingOptions, settings, options, forceConfiguration); | ||
stages.configureDefaultStageHandling(context, options.stageHandlingOptions, otherSettings, otherOptions, forceConfiguration); | ||
@@ -188,3 +188,3 @@ // ... OR using your own custom stage-handling configuration | ||
// stageHandlingSettings.extractStageFromResourceName = stages.DEFAULTS.extractStageFromSuffixedResourceName; | ||
stages.configureStageHandling(context, stageHandlingSettings, settings, options, forceConfiguration); | ||
stages.configureStageHandling(context, stageHandlingSettings, undefined, otherSettings, otherOptions, forceConfiguration); | ||
@@ -210,6 +210,6 @@ // ... OR using completely customised stage handling settings | ||
} | ||
stages.configureStageHandling(context, stageHandlingSettings2, settings, options, forceConfiguration); | ||
stages.configureStageHandling(context, stageHandlingSettings2, undefined, otherSettings, otherOptions, forceConfiguration); | ||
// ... OR using custom stage handling settings and/or options and configuring dependencies at the same time | ||
stages.configureStageHandlingAndDependencies(context, stageHandlingSettings, stageHandlingOptions, otherSettings, otherOptions, forceConfiguration); | ||
stages.configureStageHandling(context, stageHandlingSettings, stageHandlingOptions, otherSettings, otherOptions, forceConfiguration); | ||
@@ -251,7 +251,17 @@ // To check if stage handling is configured | ||
// To extract stream names form AWS event source ARNs | ||
// To extract event soure ARNs from AWS events | ||
const eventSourceARNs = streamEvents.getEventSourceARNs(event); | ||
const eventSourceStreamNames = streamEvents.getEventSourceStreamNames(event); | ||
const eventSourceStreamName = streamEvents.getEventSourceStreamName(record); | ||
// To extract Kinesis stream names from AWS events and event records | ||
const eventSourceStreamNames = streamEvents.getKinesisEventSourceStreamNames(event); | ||
const eventSourceStreamName = streamEvents.getKinesisEventSourceStreamName(record); | ||
// To extract DynamoDB table names from DynamoDB stream event records | ||
const dynamoDBEventSourceTableName = streamEvents.getDynamoDBEventSourceTableName(record); | ||
// To extract DynamoDB table names and stream timestamps/suffixes from DynamoDB stream event records | ||
const tableNameAndStreamTimestamp = streamEvents.getDynamoDBEventSourceTableNameAndStreamTimestamp(record); | ||
const dynamoDBEventSourceTableName1 = tableNameAndStreamTimestamp[0]; | ||
const dynamoDBEventSourceStreamTimestamp = tableNameAndStreamTimestamp[1]; | ||
// Simple checks to validate existance of some of the properties of Kinesis & DynamoDB stream event records | ||
@@ -288,2 +298,20 @@ try { | ||
### 5.0.0 | ||
- Changes to `arns.js` module: | ||
- Changed `getArnResources` function to support DynamoDB eventSourceARNs | ||
- Changes to `stream-events.js` module: | ||
- Renamed `getEventSourceStreamNames` function to `getKinesisEventSourceStreamNames` | ||
- Renamed `getEventSourceStreamName` function to `getKinesisEventSourceStreamName` | ||
- Added new `getDynamoDBEventSourceTableName` function | ||
- Added new `getDynamoDBEventSourceTableNameAndStreamTimestamp` function | ||
- Changes to `stages.js` module: | ||
- Renamed `configureStageHandling` function to `configureStageHandlingWithSettings` | ||
- Renamed `configureStageHandlingAndDependencies` function to `configureStageHandling` | ||
- Removed `configureDependenciesIfNotConfigured` function | ||
- Removed `configureDefaultStageHandlingIfNotConfigured` function | ||
- Removed `configureStageHandlingIfNotConfigured` function | ||
- Renamed `config.json` to `stages-options.json` | ||
- Updated `core-functions` dependency to version 2.0.5 | ||
- Updated `logging-utils` dependency to version 3.0.0 | ||
### 4.0.0 | ||
@@ -290,0 +318,0 @@ - Renamed `kinesis-utils` module to `kinesis-cache` to better reflect its actual purpose |
139
stages.js
@@ -34,2 +34,3 @@ 'use strict'; | ||
configureStageHandling: configureStageHandling, | ||
configureStageHandlingWithSettings: configureStageHandlingWithSettings, | ||
configureDefaultStageHandling: configureDefaultStageHandling, | ||
@@ -39,4 +40,2 @@ getDefaultStageHandlingSettings: getDefaultStageHandlingSettings, | ||
getStageHandlingFunction: getStageHandlingFunction, | ||
configureStageHandlingAndDependencies: configureStageHandlingAndDependencies, | ||
configureStageHandlingIfNotConfigured: configureStageHandlingIfNotConfigured, | ||
// Stage resolution | ||
@@ -79,2 +78,4 @@ resolveStage: resolveStage, | ||
const Objects = require('core-functions/objects'); | ||
const streamEvents = require('./stream-events'); | ||
@@ -180,5 +181,5 @@ | ||
*/ | ||
function configureStageHandling(context, settings, otherSettings, otherOptions, forceConfiguration) { | ||
function configureStageHandlingWithSettings(context, settings, otherSettings, otherOptions, forceConfiguration) { | ||
// Configure all dependencies if not configured | ||
configureDependenciesIfNotConfigured(context, otherSettings, otherOptions, configureStageHandling.name); | ||
configureDependencies(context, otherSettings, otherOptions, false); | ||
@@ -222,3 +223,3 @@ // If forceConfiguration is false check if the given context already has stage handling configured on it | ||
* @param {LoggingOptions|undefined} [otherOptions.loggingOptions] - optional logging options to use to configure logging | ||
* @param {boolean|undefined} forceConfiguration - whether or not to force configuration of the default settings, which | ||
* @param {boolean|undefined} [forceConfiguration] - whether or not to force configuration of the default settings, which | ||
* will override any previously configured stage handling settings on the given context | ||
@@ -229,3 +230,3 @@ * @return {Object} the context object configured with stage handling settings (either existing or defaults or overrides) | ||
const settings = getDefaultStageHandlingSettings(options); | ||
return configureStageHandling(context, settings, otherSettings, otherOptions, forceConfiguration); | ||
return configureStageHandlingWithSettings(context, settings, otherSettings, otherOptions, forceConfiguration); | ||
} | ||
@@ -274,3 +275,3 @@ | ||
/** | ||
* Loads the default stage handling options from the local config.json file and fills in any missing options with the | ||
* Loads the default stage handling options from the local stages-options.json file and fills in any missing options with the | ||
* static default options. | ||
@@ -280,4 +281,4 @@ * @returns {StageHandlingOptions} the default stage handling options | ||
function loadDefaultStageHandlingOptions() { | ||
const config = require('./config.json'); | ||
const defaultOptions = config ? config.stageHandlingOptions : undefined; | ||
const options = require('./stages-options.json'); | ||
const defaultOptions = options ? options.stageHandlingOptions : undefined; | ||
return { | ||
@@ -293,20 +294,2 @@ envStageName: select(defaultOptions, 'envStageName', 'STAGE'), | ||
/** | ||
* Configures the given context with the stage handling dependencies (currently only logging) using the given other | ||
* settings and given other options. | ||
* | ||
* @param {Object} context - the context onto which to configure the given stage handling dependencies | ||
* @param {Object|undefined} [otherSettings] - optional other configuration settings to use | ||
* @param {LoggingSettings|undefined} [otherSettings.loggingSettings] - optional logging settings to use to configure logging | ||
* @param {Object|undefined} [otherOptions] - optional other configuration options to use if no corresponding other settings are provided | ||
* @param {LoggingOptions|undefined} [otherOptions.loggingOptions] - optional logging options to use to configure logging | ||
* @param {string|undefined} [caller] - optional arbitrary text to identify the caller of this function | ||
* @returns {Object} the context object configured with stage handling dependencies | ||
*/ | ||
function configureDependenciesIfNotConfigured(context, otherSettings, otherOptions, caller) { | ||
// Configure logging if not configured yet | ||
logging.configureLoggingIfNotConfigured(context, otherSettings ? otherSettings.loggingSettings : undefined, | ||
otherOptions ? otherOptions.loggingOptions : undefined, undefined, caller); | ||
} | ||
/** | ||
* Returns the value of the named stage handling setting (if any) on the given context. | ||
@@ -335,44 +318,2 @@ * @param context - the context from which to fetch the named setting's value | ||
/** | ||
* If no stage handling settings have been configured yet, then configures the given context with the default settings. | ||
* @param {Object} context - the context to configure with default logging and stage handling | ||
* @param {string|undefined} [caller] - optional arbitrary text to identify the caller of this function | ||
* @returns {Object} the given context | ||
*/ | ||
function configureDefaultStageHandlingIfNotConfigured(context, caller) { | ||
return configureStageHandlingIfNotConfigured(context, undefined, undefined, undefined, undefined, caller); | ||
} | ||
/** | ||
* If no stage handling settings have been configured yet, then configure the given context with the given stage | ||
* handling settings (if any) otherwise with the default stage handling settings partially overridden by the given stage | ||
* handling options (if any). | ||
* | ||
* @param {Object} context - the context to configure | ||
* @param {StageHandlingSettings|undefined} [settings] - optional stage handling settings to use to configure stage handling | ||
* @param {StageHandlingOptions|undefined} [options] - optional stage handling options to use to override default options | ||
* @param {Object|undefined} [otherSettings] - optional other configuration settings to use | ||
* @param {LoggingSettings|undefined} [otherSettings.loggingSettings] - optional logging settings to use to configure logging | ||
* @param {Object|undefined} [otherOptions] - optional other configuration options to use if corresponding settings are not provided | ||
* @param {LoggingOptions|undefined} [otherOptions.loggingOptions] - optional logging options to use to configure logging | ||
* @param {string|undefined} [caller] - optional arbitrary text to identify the caller of this function | ||
* @returns {Object} the given context | ||
*/ | ||
function configureStageHandlingIfNotConfigured(context, settings, options, otherSettings, otherOptions, caller) { | ||
// Configure all dependencies if not configured | ||
configureDependenciesIfNotConfigured(context, otherSettings, otherOptions, configureStageHandlingIfNotConfigured.name); | ||
// Configure stage handling if not already configured | ||
if (!isStageHandlingConfigured(context)) { | ||
if (settings && typeof settings === 'object') { | ||
context.warn(`Stage handling was not configured${caller ? ` before calling ${caller}` : ''} - using stage handling settings (${stringify(settings)})`); | ||
configureStageHandling(context, settings, otherSettings, otherOptions, true); | ||
} else { | ||
context.warn(`Stage handling was not configured${caller ? ` before calling ${caller}` : ''} - using default stage handling configuration with options (${stringify(options)})`); | ||
configureDefaultStageHandling(context, options, otherSettings, otherOptions, true); | ||
} | ||
} | ||
return context; | ||
} | ||
/** | ||
* Configures the given context with the given stage handling settings (if any) otherwise with the default stage | ||
@@ -393,5 +334,5 @@ * handling settings partially overridden by the given stage handling options (if any), but only if stage handling is | ||
*/ | ||
function configureStageHandlingAndDependencies(context, settings, options, otherSettings, otherOptions, forceConfiguration) { | ||
// First configure all stage handling dependencies | ||
configureDependencies(context, otherSettings, otherOptions, forceConfiguration); | ||
function configureStageHandling(context, settings, options, otherSettings, otherOptions, forceConfiguration) { | ||
// // First configure all stage handling dependencies | ||
// configureDependencies(context, otherSettings, otherOptions, false); | ||
@@ -403,6 +344,10 @@ // Check if stage handling was already configured | ||
const settingsAvailable = settings && typeof settings === 'object'; | ||
const stageHandlingSettings = settingsAvailable ? settings : getDefaultStageHandlingSettings(options); | ||
const optionsAvailable = options && typeof options === 'object'; | ||
const stageHandlingSettings = settingsAvailable ? | ||
optionsAvailable ? Objects.merge(options, settings, false, false) : settings : | ||
getDefaultStageHandlingSettings(options); | ||
// Configure stage handling with the given or derived stage handling settings | ||
configureStageHandling(context, stageHandlingSettings, otherSettings, otherOptions, forceConfiguration); | ||
configureStageHandlingWithSettings(context, stageHandlingSettings, otherSettings, otherOptions, forceConfiguration); | ||
@@ -431,3 +376,3 @@ // Log a warning if no settings and no options were provided and the default settings were applied | ||
// Configure logging if not configured yet | ||
logging.configureLoggingWithSettingsOrOptions(context, otherSettings ? otherSettings.loggingSettings : undefined, | ||
logging.configureLogging(context, otherSettings ? otherSettings.loggingSettings : undefined, | ||
otherOptions ? otherOptions.loggingOptions : undefined, undefined, forceConfiguration); | ||
@@ -503,3 +448,3 @@ } | ||
// Ensure at least default configuration is in place at this point | ||
configureDefaultStageHandlingIfNotConfigured(context, resolveStage.name); | ||
configureDefaultStageHandling(context, undefined, undefined, require('./stages-options.json'), false); | ||
@@ -568,3 +513,3 @@ // Resolve extractInCase | ||
if (extractStageFromStreamName && event && event.Records) { | ||
const stages = streamEvents.getEventSourceStreamNames(event) | ||
const stages = streamEvents.getKinesisEventSourceStreamNames(event) | ||
.map(streamName => isNotBlank(streamName) ? extractStageFromStreamName(trim(streamName), context) : ''); | ||
@@ -641,4 +586,3 @@ | ||
function toStageQualifiedStreamName(unqualifiedStreamName, stage, context) { | ||
return _toStageQualifiedName(unqualifiedStreamName, stage, INJECT_STAGE_INTO_STREAM_NAME_SETTING, | ||
toStageQualifiedStreamName.name, context); | ||
return _toStageQualifiedName(unqualifiedStreamName, stage, INJECT_STAGE_INTO_STREAM_NAME_SETTING, context); | ||
} | ||
@@ -661,4 +605,3 @@ | ||
function extractStageFromQualifiedStreamName(qualifiedStreamName, context) { | ||
return _extractStageFromQualifiedName(qualifiedStreamName, EXTRACT_STAGE_FROM_STREAM_NAME_SETTING, | ||
extractStageFromQualifiedStreamName.name, context); | ||
return _extractStageFromQualifiedName(qualifiedStreamName, EXTRACT_STAGE_FROM_STREAM_NAME_SETTING, context); | ||
} | ||
@@ -685,4 +628,3 @@ | ||
function toStageSuffixedStreamName(unsuffixedStreamName, stage, context) { | ||
return _toStageSuffixedName(unsuffixedStreamName, stage, STREAM_NAME_STAGE_SEPARATOR_SETTING, | ||
toStageSuffixedStreamName.name, context); | ||
return _toStageSuffixedName(unsuffixedStreamName, stage, STREAM_NAME_STAGE_SEPARATOR_SETTING, context); | ||
} | ||
@@ -704,4 +646,3 @@ | ||
function extractStageFromSuffixedStreamName(stageSuffixedStreamName, context) { | ||
return _extractStageFromSuffixedName(stageSuffixedStreamName, STREAM_NAME_STAGE_SEPARATOR_SETTING, | ||
extractStageFromSuffixedStreamName.name, context); | ||
return _extractStageFromSuffixedName(stageSuffixedStreamName, STREAM_NAME_STAGE_SEPARATOR_SETTING, context); | ||
} | ||
@@ -730,4 +671,3 @@ | ||
function toStageQualifiedResourceName(unqualifiedResourceName, stage, context) { | ||
return _toStageQualifiedName(unqualifiedResourceName, stage, INJECT_STAGE_INTO_RESOURCE_NAME_SETTING, | ||
toStageQualifiedResourceName.name, context); | ||
return _toStageQualifiedName(unqualifiedResourceName, stage, INJECT_STAGE_INTO_RESOURCE_NAME_SETTING, context); | ||
} | ||
@@ -750,4 +690,3 @@ | ||
function extractStageFromQualifiedResourceName(qualifiedResourceName, context) { | ||
return _extractStageFromQualifiedName(qualifiedResourceName, EXTRACT_STAGE_FROM_RESOURCE_NAME_SETTING, | ||
extractStageFromQualifiedResourceName.name, context); | ||
return _extractStageFromQualifiedName(qualifiedResourceName, EXTRACT_STAGE_FROM_RESOURCE_NAME_SETTING, context); | ||
} | ||
@@ -773,4 +712,3 @@ | ||
function toStageSuffixedResourceName(unsuffixedResourceName, stage, context) { | ||
return _toStageSuffixedName(unsuffixedResourceName, stage, RESOURCE_NAME_STAGE_SEPARATOR_SETTING, | ||
toStageSuffixedResourceName.name, context); | ||
return _toStageSuffixedName(unsuffixedResourceName, stage, RESOURCE_NAME_STAGE_SEPARATOR_SETTING, context); | ||
} | ||
@@ -791,4 +729,3 @@ | ||
function extractStageFromSuffixedResourceName(stageSuffixedResourceName, context) { | ||
return _extractStageFromSuffixedName(stageSuffixedResourceName, RESOURCE_NAME_STAGE_SEPARATOR_SETTING, | ||
extractStageFromSuffixedResourceName.name, context) | ||
return _extractStageFromSuffixedName(stageSuffixedResourceName, RESOURCE_NAME_STAGE_SEPARATOR_SETTING, context) | ||
} | ||
@@ -800,5 +737,5 @@ | ||
function _toStageQualifiedName(unqualifiedName, stage, injectStageIntoNameSettingName, caller, context) { | ||
function _toStageQualifiedName(unqualifiedName, stage, injectStageIntoNameSettingName, context) { | ||
if (isNotBlank(unqualifiedName)) { | ||
configureDefaultStageHandlingIfNotConfigured(context, caller); | ||
configureDefaultStageHandling(context); | ||
@@ -813,5 +750,5 @@ // Resolve injectStageIntoName function to use | ||
function _extractStageFromQualifiedName(qualifiedName, extractStageFromNameSettingName, caller, context) { | ||
function _extractStageFromQualifiedName(qualifiedName, extractStageFromNameSettingName, context) { | ||
if (isNotBlank(qualifiedName)) { | ||
configureDefaultStageHandlingIfNotConfigured(context, caller); | ||
configureDefaultStageHandling(context); | ||
@@ -830,5 +767,5 @@ // Resolve extractStageFromName function to use | ||
function _toStageSuffixedName(unsuffixedName, stage, separatorSettingName, caller, context) { | ||
function _toStageSuffixedName(unsuffixedName, stage, separatorSettingName, context) { | ||
if (isNotBlank(unsuffixedName)) { | ||
configureDefaultStageHandlingIfNotConfigured(context, caller); | ||
configureDefaultStageHandling(context); | ||
@@ -846,5 +783,5 @@ // Resolve separator | ||
function _extractStageFromSuffixedName(stageSuffixedName, separatorSettingName, caller, context) { | ||
function _extractStageFromSuffixedName(stageSuffixedName, separatorSettingName, context) { | ||
if (isNotBlank(stageSuffixedName)) { | ||
configureDefaultStageHandlingIfNotConfigured(context, caller); | ||
configureDefaultStageHandling(context); | ||
@@ -851,0 +788,0 @@ // Resolve separator |
@@ -16,7 +16,13 @@ 'use strict'; | ||
getEventSourceARNs: getEventSourceARNs, | ||
/** Extracts and returns the stream names from the given stream event's records' eventSourceARNs */ | ||
getEventSourceStreamNames: getEventSourceStreamNames, | ||
/** Extracts and returns the stream name from the given stream event record's eventSourceARN */ | ||
getEventSourceStreamName: getEventSourceStreamName, | ||
/** Extracts and returns the stream names from the given Kinesis stream event's records' eventSourceARNs */ | ||
getKinesisEventSourceStreamNames: getKinesisEventSourceStreamNames, | ||
/** Extracts and returns the stream name from the given Kinesis stream event record's eventSourceARN */ | ||
getKinesisEventSourceStreamName: getKinesisEventSourceStreamName, | ||
/** Extracts and returns the table name from the given DynamoDB stream event record's eventSourceARN */ | ||
getDynamoDBEventSourceTableName: getDynamoDBEventSourceTableName, | ||
/** Extracts and returns the table name from the given DynamoDB stream event record's eventSourceARN */ | ||
getDynamoDBEventSourceTableNameAndStreamTimestamp: getDynamoDBEventSourceTableNameAndStreamTimestamp, | ||
/** Validates the given stream event record and raises an error if the record is invalid or not a Kinesis or DynamoDB stream event record */ | ||
@@ -43,3 +49,3 @@ validateStreamEventRecord: validateStreamEventRecord, | ||
/** | ||
* Extracts and returns the stream names from the given stream event's records' eventSourceARNs (if any); otherwise | ||
* Extracts and returns the stream names from the given Kinesis stream event's records' eventSourceARNs (if any); otherwise | ||
* returns an empty array. | ||
@@ -49,13 +55,13 @@ * @param event - a Kinesis or DynamoDB stream event | ||
*/ | ||
function getEventSourceStreamNames(event) { | ||
return event && event.Records ? event.Records.map(getEventSourceStreamName) : []; | ||
function getKinesisEventSourceStreamNames(event) { | ||
return event && event.Records ? event.Records.map(getKinesisEventSourceStreamName) : []; | ||
} | ||
/** | ||
* Extracts and returns the stream name from the given stream event record's eventSourceARN (if any); otherwise returns | ||
* Extracts and returns the stream name from the given Kinesis stream event record's eventSourceARN (if any); otherwise returns | ||
* an empty string. | ||
* @param record - a Kinesis or DynamoDB stream event record | ||
* @param record - a Kinesis stream event record | ||
* @returns {string} the stream name (if any) or an empty string | ||
*/ | ||
function getEventSourceStreamName(record) { | ||
function getKinesisEventSourceStreamName(record) { | ||
return record && isNotBlank(record.eventSourceARN) ? arns.getArnResources(record.eventSourceARN).resource : ''; | ||
@@ -65,2 +71,31 @@ } | ||
/** | ||
* Extracts and returns an arrays containing the table name followed by the stream timestamp/suffix from the given | ||
* DynamoDB stream event record's eventSourceARN (if any); otherwise returns an array of 2 empty strings. | ||
* | ||
* Example of a DynamoDB stream event source ARN: | ||
* arn:aws:dynamodb:us-east-1:111111111111:table/test/stream/2020-10-10T08:18:22.385 | ||
* where 'test' is the name of the table and '2020-10-10T08:18:22.385' is the stream timestamp/suffix | ||
* | ||
* @param record - a DynamoDB stream event record | ||
* @returns {[string, string]} an array containing the table name (if any or empty) followed by an empty string followed | ||
* by the stream timestamp/suffix (if any or empty) | ||
*/ | ||
function getDynamoDBEventSourceTableNameAndStreamTimestamp(record) { | ||
if (record && isNotBlank(record.eventSourceARN)) { | ||
const resources = arns.getArnResources(record.eventSourceARN); | ||
return [resources.resource, resources.subResource]; | ||
} | ||
return ['', '']; | ||
} | ||
/** | ||
* Extracts and returns the table name from the given DynamoDB stream event record's eventSourceARN (if any); otherwise | ||
* returns an empty string. | ||
* @param record - a DynamoDB stream event record | ||
* @returns {string} the table name (if any) or an empty string (if none) | ||
*/ | ||
function getDynamoDBEventSourceTableName(record) { | ||
return record && isNotBlank(record.eventSourceARN) ? arns.getArnResources(record.eventSourceARN).resource : ''; | ||
} | ||
/** | ||
* Validates the given stream event record and raises an error if the record fails to meet any of the following criteria: | ||
@@ -67,0 +102,0 @@ * 1. It must be defined; |
@@ -103,9 +103,10 @@ 'use strict'; | ||
const arn2 = "arn:partition:service:region:account-id:resourcetype/resource"; | ||
const arn3 = "arn:partition:service:region:account-id:resourcetype:resource"; | ||
const arn4 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version"; | ||
const arn5 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1"; | ||
const arn6 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1:other2"; | ||
const arn7 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1:other2:other3"; | ||
const arn3 = "arn:partition:service:region:account-id:resourcetype/resource/subResourceType/subResource"; | ||
const arn4 = "arn:partition:service:region:account-id:resourcetype:resource"; | ||
const arn5 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version"; | ||
const arn6 = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1"; | ||
const arn6a = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1:other2"; | ||
const arn6b = "arn:partition:service:region:account-id:resourcetype:resource:alias_or_version:other1:other2:other3"; | ||
const expected0 = {resourceType: '', resource: '', aliasOrVersion: '', others: []}; | ||
const expected0 = {resourceType: '', resource: '', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(undefined), expected0, `undefined must give [${JSON.stringify(expected0)}]`); | ||
@@ -122,24 +123,31 @@ t.deepEqual(getArnResources(null), expected0, `null must give [${JSON.stringify(expected0)}]`); | ||
const expected1 = {resourceType: '', resource: 'resource', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn1), expected1, `'${shorter(arn1)}' must give [${JSON.stringify(expected1)}]`); | ||
const expected1 = {resourceType: '', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn1), expected1, `CASE 1: '${shorter(arn1)}' must give [${JSON.stringify(expected1)}]`); | ||
const expected2 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn2), expected2, `'${shorter(arn2)}' must give [${JSON.stringify(expected2)}]`); | ||
const expected2 = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn2), expected2, `CASE 2: '${shorter(arn3)}' must give [${JSON.stringify(expected2)}]`); | ||
const expected3 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn3), expected3, `'${shorter(arn3)}' must give [${JSON.stringify(expected3)}]`); | ||
const expected3 = {resourceType: 'resourcetype', resource: 'resource', subResourceType: 'subResourceType', subResource: 'subResource', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn3), expected3, `CASE 3: '${shorter(arn3)}' must give [${JSON.stringify(expected3)}]`); | ||
const expected4 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: 'alias_or_version', others: []}; | ||
t.deepEqual(getArnResources(arn4), expected4, `'${shorter(arn4)}' must give [${JSON.stringify(expected4)}]`); | ||
const arn3b = "arn:partition:service:region:account-id:table/MyTableName/stream/2020-10-10T08:18:22.385"; | ||
const expected3b = {resourceType: 'table', resource: 'MyTableName', subResourceType: 'stream', subResource: '2020-10-10T08:18:22.385', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn3b), expected3b, `CASE 3b: '${shorter(arn3)}' must give [${JSON.stringify(expected3b)}]`); | ||
const expected5 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: 'alias_or_version', others: ['other1']}; | ||
t.deepEqual(getArnResources(arn5), expected5, `'${shorter(arn5)}' must give [${JSON.stringify(expected5)}]`); | ||
const expected4 = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: '', others: []}; | ||
t.deepEqual(getArnResources(arn4), expected4, `CASE 4: '${shorter(arn4)}' must give [${JSON.stringify(expected4)}]`); | ||
const expected6 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: 'alias_or_version', others: ['other1','other2']}; | ||
t.deepEqual(getArnResources(arn6), expected6, `'${shorter(arn6)}' must give [${JSON.stringify(expected6)}]`); | ||
const expected5 = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: 'alias_or_version', others: []}; | ||
t.deepEqual(getArnResources(arn5), expected5, `CASE 5: '${shorter(arn5)}' must give [${JSON.stringify(expected5)}]`); | ||
const expected7 = {resourceType: 'resourcetype', resource: 'resource', aliasOrVersion: 'alias_or_version', others: ['other1','other2','other3']}; | ||
t.deepEqual(getArnResources(arn7), expected7, `'${shorter(arn7)}' must give [${JSON.stringify(expected7)}]`); | ||
const expected6 = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: 'alias_or_version', others: ['other1']}; | ||
t.deepEqual(getArnResources(arn6), expected6, `CASE 6: '${shorter(arn6)}' must give [${JSON.stringify(expected6)}]`); | ||
const expected6a = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: 'alias_or_version', others: ['other1','other2']}; | ||
t.deepEqual(getArnResources(arn6a), expected6a, `CASE 6a: '${shorter(arn6a)}' must give [${JSON.stringify(expected6a)}]`); | ||
const expected6b = {resourceType: 'resourcetype', resource: 'resource', subResourceType: '', subResource: '', aliasOrVersion: 'alias_or_version', others: ['other1','other2','other3']}; | ||
t.deepEqual(getArnResources(arn6b), expected6b, `CASE 6b: '${shorter(arn6b)}' must give [${JSON.stringify(expected6b)}]`); | ||
t.end(); | ||
}); |
@@ -39,3 +39,3 @@ 'use strict'; | ||
const context = {}; | ||
logging.configureLogging(context, logging.TRACE); | ||
logging.configureLoggingWithSettings(context, logging.TRACE); | ||
@@ -158,3 +158,3 @@ // Set current region | ||
const context = {}; | ||
logging.configureLogging(context, logging.DEBUG); | ||
logging.configureLoggingWithSettings(context, logging.DEBUG); | ||
@@ -161,0 +161,0 @@ process.env.AWS_REGION = 'us-west-1'; |
@@ -39,3 +39,3 @@ 'use strict'; | ||
const context = {}; | ||
logging.configureLogging(context, logging.TRACE); | ||
logging.configureLoggingWithSettings(context, logging.TRACE); | ||
@@ -158,3 +158,3 @@ // Set current region | ||
const context = {}; | ||
logging.configureLogging(context, logging.DEBUG); | ||
logging.configureLoggingWithSettings(context, logging.DEBUG); | ||
@@ -161,0 +161,0 @@ process.env.AWS_REGION = 'us-west-1'; |
{ | ||
"name": "aws-core-utils-tests", | ||
"description": "Unit tests for aws-core-utils modules", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"author": "Byron du Preez", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
@@ -9,2 +9,3 @@ 'use strict'; | ||
const uuid = require('node-uuid'); | ||
const base64 = require('core-functions/base64'); | ||
@@ -17,2 +18,5 @@ const sampleAwsAccountId = "XXXXXXXXXXXX"; | ||
let nextSequenceNumber = 1; | ||
const sampleMessage = { | ||
@@ -40,4 +44,4 @@ key1: 'value1', | ||
sampleStreamName: sampleStreamName, | ||
sampleEventSourceArn: sampleEventSourceArn, | ||
sampleEventSourceArnFromPrefixSuffix: sampleEventSourceArnFromPrefixSuffix, | ||
sampleKinesisEventSourceArn: sampleKinesisEventSourceArn, | ||
sampleKinesisEventSourceArnFromPrefixSuffix: sampleKinesisEventSourceArnFromPrefixSuffix, | ||
sampleBase64Data: sampleBase64Data, | ||
@@ -52,2 +56,6 @@ sampleKinesisRecord: sampleKinesisRecord, | ||
// For DynamoDB stream events | ||
sampleTableName: sampleTableName, | ||
sampleDynamoDBEventSourceArn: sampleDynamoDBEventSourceArn, | ||
sampleDynamoDBEventSourceArnFromPrefixSuffix: sampleDynamoDBEventSourceArnFromPrefixSuffix, | ||
awsDynamoDBUpdateSampleEvent: awsDynamoDBUpdateSampleEvent | ||
@@ -75,2 +83,8 @@ }; | ||
function sampleTableName(tableNamePrefix, tableNameSuffix) { | ||
const prefix = isNotBlank(tableNamePrefix) ? tableNamePrefix : 'TestDynamoDBTable'; | ||
const suffix = isNotBlank(tableNameSuffix) ? tableNameSuffix : ''; | ||
return `${prefix}${suffix}`; | ||
} | ||
function sampleInvokedFunctionArn(invokedFunctionArnRegion, functionName, functionAlias) { | ||
@@ -83,3 +97,3 @@ const region = isNotBlank(invokedFunctionArnRegion) ? invokedFunctionArnRegion : 'IF_ARN_REGION'; | ||
function sampleEventSourceArn(eventSourceArnRegion, streamName) { | ||
function sampleKinesisEventSourceArn(eventSourceArnRegion, streamName) { | ||
const region = isNotBlank(eventSourceArnRegion) ? eventSourceArnRegion : 'EF_ARN_REGION'; | ||
@@ -90,9 +104,25 @@ const streamName1 = isNotBlank(streamName) ? streamName : sampleStreamName(); | ||
function sampleEventSourceArnFromPrefixSuffix(eventSourceArnRegion, streamNamePrefix, streamNameSuffix) { | ||
function sampleDynamoDBEventSourceArn(eventSourceArnRegion, tableName, timestamp) { | ||
const region = isNotBlank(eventSourceArnRegion) ? eventSourceArnRegion : 'EF_ARN_REGION'; | ||
const tableName1 = isNotBlank(tableName) ? tableName : sampleTableName(); | ||
const timestamp0 = isNotBlank(timestamp) ? timestamp : new Date().toISOString(); | ||
const timestamp1 = timestamp0.endsWith('Z') ? timestamp0.substring(0, timestamp0.length - 1) : timestamp0; | ||
//arn:aws:dynamodb:us-east-1:111111111111:table/test/stream/2020-10-10T08:18:22.385 | ||
return `arn:aws:dynamodb:${region}:${sampleAwsAccountId}:table/${tableName1}/stream/${timestamp1}`; | ||
} | ||
function sampleKinesisEventSourceArnFromPrefixSuffix(eventSourceArnRegion, streamNamePrefix, streamNameSuffix) { | ||
const streamName = sampleStreamName(streamNamePrefix, streamNameSuffix); | ||
return sampleEventSourceArn(eventSourceArnRegion, streamName); | ||
return sampleKinesisEventSourceArn(eventSourceArnRegion, streamName); | ||
} | ||
function sampleAwsContext(functionName, functionVersion, invokedFunctionArn) { | ||
function sampleDynamoDBEventSourceArnFromPrefixSuffix(eventSourceArnRegion, tableNamePrefix, tableNameSuffix, timestamp) { | ||
const tableName = sampleTableName(tableNamePrefix, tableNameSuffix); | ||
return sampleDynamoDBEventSourceArn(eventSourceArnRegion, tableName, timestamp); | ||
} | ||
function sampleAwsContext(functionName, functionVersion, invokedFunctionArn, maxTimeInMillis) { | ||
const uuid1 = uuid.v4(); | ||
const startTime = Date.now(); | ||
const maximumTimeInMillis = maxTimeInMillis ? maxTimeInMillis : 1000; | ||
return { | ||
@@ -107,3 +137,6 @@ callbackWaitsForEmptyEventLoop: true, | ||
awsRequestId: uuid1, | ||
invokedFunctionArn: invokedFunctionArn | ||
invokedFunctionArn: invokedFunctionArn, | ||
getRemainingTimeInMillis() { | ||
return maximumTimeInMillis - (Date.now() - startTime); | ||
} | ||
}; | ||
@@ -122,4 +155,5 @@ } | ||
const kinesisPartitionKey = isNotBlank(partitionKey) ? partitionKey : uuid.v4(); | ||
const kinesisData = data !== undefined ? data : "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4="; | ||
const sequenceNumber = sampleNumberString(56); | ||
const kinesisData = data !== undefined ? | ||
typeof data === 'object' ? base64.toBase64(data) : data : "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4="; | ||
const sequenceNumber = nextSequenceNumber++; //sampleNumberString(56); | ||
const awsRegion = eventAwsRegion ? eventAwsRegion : 'EVENT_AWS_REGION'; | ||
@@ -133,3 +167,3 @@ const event = { | ||
kinesisSchemaVersion: "1.0", | ||
sequenceNumber: sequenceNumber | ||
sequenceNumber: `${sequenceNumber}` | ||
}, | ||
@@ -136,0 +170,0 @@ invokeIdentityArn: sampleIdentityArn, |
@@ -15,6 +15,6 @@ 'use strict'; | ||
const isStageHandlingConfigured = stages.isStageHandlingConfigured; | ||
const configureStageHandling = stages.configureStageHandling; | ||
const configureStageHandlingWithSettings = stages.configureStageHandlingWithSettings; | ||
const configureDefaultStageHandling = stages.configureDefaultStageHandling; | ||
const getDefaultStageHandlingSettings = stages.getDefaultStageHandlingSettings; | ||
const configureStageHandlingAndDependencies = stages.configureStageHandlingAndDependencies; | ||
const configureStageHandling = stages.configureStageHandling; | ||
const getStageHandlingSetting = stages.getStageHandlingSetting; | ||
@@ -64,3 +64,3 @@ // Stage resolution | ||
//const sampleStreamName = samples.sampleStreamName; | ||
const sampleEventSourceArn = samples.sampleEventSourceArn; | ||
const sampleKinesisEventSourceArn = samples.sampleKinesisEventSourceArn; | ||
// const sampleEventSourceArnFromPrefixSuffix = samples.sampleEventSourceArnFromPrefixSuffix; | ||
@@ -87,3 +87,3 @@ // const sampleBase64Data = samples.sampleBase64Data; | ||
// Create a Kinesis event | ||
const eventSourceArn = sampleEventSourceArn('eventSourceArnRegion', streamName); | ||
const eventSourceArn = sampleKinesisEventSourceArn('eventSourceArnRegion', streamName); | ||
const event = sampleKinesisEventWithSampleRecord(undefined, undefined, eventSourceArn, 'eventAwsRegion'); | ||
@@ -100,3 +100,3 @@ if (isNotBlank(eventStage)) { | ||
function checkConfigureStageHandling(t, context, envStageName, customToStage, | ||
function checkConfigureStageHandlingWithSettings(t, context, envStageName, customToStage, | ||
convertAliasToStage, injectStageIntoStreamName, extractStageFromStreamName, | ||
@@ -147,3 +147,3 @@ streamNameStageSeparator, injectStageIntoResourceName, extractStageFromResourceName, | ||
}; | ||
configureStageHandling(context, settings, undefined, undefined, forceConfiguration); | ||
configureStageHandlingWithSettings(context, settings, undefined, undefined, forceConfiguration); | ||
@@ -322,3 +322,3 @@ const after = context.stageHandling; | ||
configureStageHandlingAndDependencies(context, settings, options, otherSettings, otherOptions, forceConfiguration); | ||
configureStageHandling(context, settings, options, otherSettings, otherOptions, forceConfiguration); | ||
@@ -392,6 +392,6 @@ const after = context.stageHandling; | ||
// ===================================================================================================================== | ||
// Tests for configureStageHandling and isStageHandlingConfigured | ||
// Tests for configureStageHandlingWithSettings and isStageHandlingConfigured | ||
// ===================================================================================================================== | ||
test('configureStageHandling with all undefined', t => { | ||
test('configureStageHandlingWithSettings with all undefined', t => { | ||
const context = {}; | ||
@@ -401,9 +401,9 @@ t.notOk(isStageHandlingConfigured(context), `stage handling settings must not be configured yet`); | ||
// Configure it | ||
checkConfigureStageHandling(t, context, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, false); | ||
checkConfigureStageHandlingWithSettings(t, context, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, false); | ||
// Must NOT be able to reconfigure it with force false | ||
checkConfigureStageHandling(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName', 'extractStageFromResourceName', 'resourceNameStageSeparator', 'injectInCase', 'extractInCase', 'defaultStage', false); | ||
checkConfigureStageHandlingWithSettings(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName', 'extractStageFromResourceName', 'resourceNameStageSeparator', 'injectInCase', 'extractInCase', 'defaultStage', false); | ||
// Must be able to reconfigure it with force true | ||
checkConfigureStageHandling(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName, extractStageFromResourceName, resourceNameStageSeparator, injectInCase', 'extractInCase', 'defaultStage', true); | ||
checkConfigureStageHandlingWithSettings(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName, extractStageFromResourceName, resourceNameStageSeparator, injectInCase', 'extractInCase', 'defaultStage', true); | ||
@@ -425,3 +425,3 @@ t.end(); | ||
// Overwrite it with arbitrary values to be able to check if defaults are NOT re-instated in next step | ||
checkConfigureStageHandling(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName, extractStageFromResourceName, resourceNameStageSeparator, injectInCase', 'extractInCase', 'defaultStage', true); | ||
checkConfigureStageHandlingWithSettings(t, context, 'envStage', 'customToStage', 'convertAliasToStage', 'injectStageIntoStreamName', 'extractStageFromStreamName', 'streamNameStageSeparator', 'injectStageIntoResourceName, extractStageFromResourceName, resourceNameStageSeparator, injectInCase', 'extractInCase', 'defaultStage', true); | ||
@@ -438,6 +438,6 @@ // Must NOT be able to reconfigure it with force false | ||
// ===================================================================================================================== | ||
// Tests for configureStageHandlingAndDependencies with settings | ||
// Tests for configureStageHandling with settings | ||
// ===================================================================================================================== | ||
test('configureStageHandlingAndDependencies with settings', t => { | ||
test('configureStageHandling with settings', t => { | ||
const context = {}; | ||
@@ -480,6 +480,6 @@ t.notOk(isStageHandlingConfigured(context), `stage handling settings must not be configured yet`); | ||
// ===================================================================================================================== | ||
// Tests for configureStageHandlingAndDependencies with options | ||
// Tests for configureStageHandling with options | ||
// ===================================================================================================================== | ||
test('configureStageHandlingAndDependencies with settings', t => { | ||
test('configureStageHandling with settings', t => { | ||
const context = {}; | ||
@@ -514,6 +514,6 @@ t.notOk(isStageHandlingConfigured(context), `stage handling settings must not be configured yet`); | ||
// ===================================================================================================================== | ||
// Tests for configureStageHandlingAndDependencies with settings AND options | ||
// Tests for configureStageHandling with settings AND options | ||
// ===================================================================================================================== | ||
test('configureStageHandlingAndDependencies with settings AND options', t => { | ||
test('configureStageHandling with settings AND options', t => { | ||
const context = {}; | ||
@@ -520,0 +520,0 @@ t.notOk(isStageHandlingConfigured(context), `stage handling settings must not be configured yet`); |
@@ -13,5 +13,9 @@ 'use strict'; | ||
const getEventSourceARNs = streamEvents.getEventSourceARNs; | ||
const getEventSourceStreamNames = streamEvents.getEventSourceStreamNames; | ||
const getEventSourceStreamName = streamEvents.getEventSourceStreamName; | ||
const getKinesisEventSourceStreamNames = streamEvents.getKinesisEventSourceStreamNames; | ||
const getKinesisEventSourceStreamName = streamEvents.getKinesisEventSourceStreamName; | ||
//const getDynamoDBEventSourceTableName = streamEvents.getDynamoDBEventSourceTableName; | ||
//const getDynamoDBEventSourceTableNameAndStreamTimestamp = streamEvents.getDynamoDBEventSourceTableNameAndStreamTimestamp; | ||
const validateStreamEventRecord = streamEvents.validateStreamEventRecord; | ||
@@ -36,3 +40,3 @@ const validateKinesisStreamEventRecord = streamEvents.validateKinesisStreamEventRecord; | ||
const eventSourceArns = streamNames.map(streamName => | ||
isNotBlank(streamName) ? samples.sampleEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName)); | ||
isNotBlank(streamName) ? samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName)); | ||
const records = eventSourceArns.map(eventSourceArn => | ||
@@ -72,9 +76,9 @@ samples.sampleKinesisRecord(undefined, undefined, eventSourceArn, 'eventAwsRegion')); | ||
// ===================================================================================================================== | ||
// getEventSourceStreamNames | ||
// getKinesisEventSourceStreamNames | ||
// ===================================================================================================================== | ||
test('getEventSourceStreamNames', t => { | ||
test('getKinesisEventSourceStreamNames', t => { | ||
function check(streamNames) { | ||
const eventSourceArns = streamNames.map(streamName => | ||
isNotBlank(streamName) ? samples.sampleEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName)); | ||
isNotBlank(streamName) ? samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName)); | ||
const records = eventSourceArns.map(eventSourceArn => | ||
@@ -85,3 +89,3 @@ samples.sampleKinesisRecord(undefined, undefined, eventSourceArn, 'eventAwsRegion')); | ||
// get the event source ARNs | ||
const actual = getEventSourceStreamNames(event); | ||
const actual = getKinesisEventSourceStreamNames(event); | ||
@@ -117,13 +121,13 @@ const expected = streamNames.map(trimOrEmpty); | ||
// ===================================================================================================================== | ||
// getEventSourceStreamName | ||
// getKinesisEventSourceStreamName | ||
// ===================================================================================================================== | ||
test('getEventSourceStreamName', t => { | ||
test('getKinesisEventSourceStreamName', t => { | ||
function check(streamName) { | ||
const eventSourceArn = isNotBlank(streamName) ? | ||
samples.sampleEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName); | ||
samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim(streamName)) : trim(streamName); | ||
const record = samples.sampleKinesisRecord(undefined, undefined, eventSourceArn, 'eventAwsRegion'); | ||
// get the event source ARNs | ||
const actual = getEventSourceStreamName(record); | ||
const actual = getKinesisEventSourceStreamName(record); | ||
@@ -194,3 +198,3 @@ const expected = trimOrEmpty(streamName); | ||
// valid Kinesis records | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
check(sampleRecord, true); | ||
@@ -271,3 +275,3 @@ | ||
// valid Kinesis records | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
check(sampleRecord, true); | ||
@@ -355,3 +359,3 @@ | ||
// invalid - since Kinesis records | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
const sampleRecord = samples.sampleKinesisRecord(undefined, undefined, samples.sampleKinesisEventSourceArn('eventSourceArnRegion', trim("streamName")), 'eventAwsRegion'); | ||
check(sampleRecord, false); | ||
@@ -358,0 +362,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296428
4286
428
+ Addedlogging-utils@3.0.18(transitive)
- Removedlogging-utils@2.0.4(transitive)
Updatedcore-functions@^2.0.5
Updatedlogging-utils@^3.0.0