-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipes): add pipes base implementation
- Loading branch information
1 parent
ecbbea4
commit b16b69c
Showing
11 changed files
with
657 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { IRole } from 'aws-cdk-lib/aws-iam'; | ||
import { CfnPipe } from 'aws-cdk-lib/aws-pipes'; | ||
|
||
/** | ||
* Enrichment step to enhance the data from the source before sending it to the target. | ||
*/ | ||
export interface IPipeEnrichment { | ||
/** | ||
* The ARN of the enrichment resource. | ||
* | ||
* Length Constraints: Minimum length of 0. Maximum length of 1600. | ||
*/ | ||
readonly enrichmentArn: string; | ||
|
||
/** | ||
* The parameters required to set up enrichment on your pipe. | ||
*/ | ||
readonly enrichmentParameters: CfnPipe.PipeEnrichmentParametersProperty; | ||
|
||
/** | ||
* Grant the pipes role to invoke the enrichment. | ||
*/ | ||
grantInvoke(grantee: IRole): void; | ||
} | ||
|
||
/** | ||
* Enrichment step to enhance the data from the source before sending it to the target. | ||
*/ | ||
export abstract class PipeEnrichment implements IPipeEnrichment { | ||
public readonly enrichmentArn: string; | ||
public readonly enrichmentParameters: CfnPipe.PipeEnrichmentParametersProperty; | ||
|
||
constructor( | ||
enrichmentArn: string, | ||
props: CfnPipe.PipeEnrichmentParametersProperty, | ||
) { | ||
this.enrichmentParameters = props; | ||
// TODO - validate ARN is a valid enrichment ARN based on regex from cfn | ||
this.enrichmentArn = enrichmentArn; | ||
} | ||
/** | ||
* Grant the pipes role to invoke the enrichment. | ||
*/ | ||
abstract grantInvoke(grantee: IRole): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export * from './pipe'; | ||
export * from './enrichment'; | ||
export * from './inputTransformation'; | ||
export * from './source'; | ||
export * from './sourceFilter'; | ||
export * from './target'; | ||
export * from './targetParameter'; |
55 changes: 55 additions & 0 deletions
55
packages/@aws-cdk/aws-pipes-alpha/lib/inputTransformation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
enum reservedVariables { | ||
PIPES_ARN = '<aws.pipes.pipe-arn>', | ||
PIPES_NAME = '<aws.pipes.pipe-name>', | ||
PIPES_TARGET_ARN = '<aws.pipes.target-arn>', | ||
PIPE_EVENT_INGESTION_TIME = '<aws.pipes.event.ingestion-time>', | ||
PIPE_EVENT = '<aws.pipes.event>', | ||
PIPE_EVENT_JSON = '<aws.pipes.event.json>', | ||
} | ||
|
||
type StaticString = string; | ||
// type JsonPath = `<$.${string}>`; | ||
type KeyValue = Record<string, string | reservedVariables>; | ||
type StaticJsonFlat = Record<string, StaticString | KeyValue>; | ||
type InputTransformJson = Record<string, StaticString | KeyValue | StaticJsonFlat>; | ||
|
||
type PipeInputTransformationValue = StaticString | InputTransformJson; | ||
|
||
/** | ||
* Transform or replace the input event payload | ||
*/ | ||
export interface IInputTransformation { | ||
/** | ||
* Valid JSON text passed to the target. | ||
*/ | ||
inputTemplate: string; | ||
} | ||
|
||
/** | ||
* Transform or replace the input event payload | ||
*/ | ||
export class PipeInputTransformation implements IInputTransformation { | ||
/** | ||
* Builds an input transformation from a JSON object. | ||
* @param inputTemplate | ||
* @returns | ||
*/ | ||
static fromJson(inputTemplate: Record<string, any>): PipeInputTransformation { | ||
return new PipeInputTransformation(inputTemplate); | ||
} | ||
|
||
inputTemplate: string; | ||
|
||
constructor(inputTemplate: PipeInputTransformationValue) { | ||
this.inputTemplate = this.unquoteKeyPlaceholders(inputTemplate); | ||
} | ||
|
||
private unquoteKeyPlaceholders(obj: any) { | ||
const jsonString = JSON.stringify(obj); | ||
|
||
const result = jsonString.replace(/"(<(?:\$\.|aws\.pipes)[^"]*?)"/g, '$1'); // Retain the "<>" and remove the outer quotes for the values that start with either "<$." or "<aws.pipes" | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.