Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove sdk v2 handler and associated tests #29868

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f880fe0
remove sdk v2 handler and tests
colifran Apr 17, 2024
c84ea57
custom resource snaps
colifran Apr 17, 2024
e811716
open search snaps
colifran Apr 17, 2024
390b1e4
Merge branch 'main' into colifran/remove-v2-handler
colifran Apr 17, 2024
bcce8c7
events targets snaps
colifran Apr 17, 2024
6cd51f3
logs destinations snaps
colifran Apr 17, 2024
e0b77c8
route53 snaos
colifran Apr 17, 2024
a3a6772
synthetics snaps
colifran Apr 17, 2024
84073d9
global accelerator snaps
colifran Apr 17, 2024
2280ff7
elastic search snaps
colifran Apr 17, 2024
6d017b8
s3 snaps
colifran Apr 17, 2024
fbeb93c
elastic load balancing v2 snaps
colifran Apr 18, 2024
4de2618
elastic load balancing v2 actions snaps
colifran Apr 18, 2024
bba68da
Merge branch 'main' into colifran/remove-v2-handler
colifran Apr 18, 2024
f331116
Merge branch 'main' into colifran/remove-v2-handler
colifran Apr 23, 2024
cc4f14d
remove extra eslint-disable no-console
colifran Apr 23, 2024
f33da94
give functions return types
colifran Apr 23, 2024
d700235
refactor
colifran Apr 23, 2024
8f10f53
refactor
colifran Apr 24, 2024
0db3f3b
Merge branch 'main' into colifran/remove-v2-handler
colifran Apr 24, 2024
84164a6
custom resource snaps
colifran Apr 24, 2024
580cc60
open search snaps
colifran Apr 24, 2024
e9fe02c
docstring
colifran Apr 24, 2024
3e1d7f3
update docstring
colifran Apr 24, 2024
015e535
update docstring
colifran Apr 24, 2024
17ca527
merge conflicts
colifran Apr 26, 2024
d937159
synthetics snaps
colifran Apr 26, 2024
c3f5987
s3 snaps
colifran Apr 26, 2024
2294a2c
route53 snaps
colifran Apr 26, 2024
d1dfe89
logs destinations snaps
colifran Apr 26, 2024
3ad6c89
global accelerator snaps
colifran Apr 26, 2024
80f9c5b
events targets snaps
colifran Apr 26, 2024
6ad51a5
elastic search snaps
colifran Apr 26, 2024
d4217f2
efs snaps
colifran Apr 26, 2024
5d3cc92
elastic load balancing v2 snaps
colifran Apr 26, 2024
7474b09
fix import
colifran Apr 26, 2024
7d2766d
cognito
colifran Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
Signed-off-by: Francis <colifran@amazon.com>
  • Loading branch information
colifran committed Apr 24, 2024
commit 8f10f532beea3cac5721fc7b113166709256ae01
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApiCall } from '@aws-cdk/aws-custom-resource-sdk-adapter';
import type * as AWSLambda from 'aws-lambda';
import type { AwsSdkCall } from './construct-types';
import { loadAwsSdk } from './load-sdk';
import { decodeCall, decodeSpecialValues, filterKeys, startsWithOneOf, respond, getCredentials } from './utils';
import { decodeCall, decodeSpecialValues, respond, getCredentials, formatData } from './utils';

/* eslint-disable @typescript-eslint/no-require-imports, import/no-extraneous-dependencies */
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent, context: AWSLambda.Context): Promise<void> {
Expand Down Expand Up @@ -65,18 +65,7 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
flatData.region = await apiCall.client.config.region().catch(() => undefined); // For test purposes: check if region was correctly passed.
Object.assign(flatData, response);

let outputPaths: string[] | undefined;
if (call.outputPath) {
outputPaths = [call.outputPath];
} else if (call.outputPaths) {
outputPaths = call.outputPaths;
}

if (outputPaths) {
data = filterKeys(flatData, startsWithOneOf(outputPaths));
} else {
data = flatData;
}
data = formatData(call, flatData);
} catch (e: any) {
// empirecal evidence show e.name is not always set
const exceptionName = e.name ?? e.constructor.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ export function decodeSpecialValues(object: object, physicalResourceId: string):
}
}

/**
* Filters the keys of an object.
*/
export function filterKeys(object: object, pred: (key: string) => boolean): {} {
return Object.entries(object)
.reduce(
(acc, [k, v]) => pred(k)
? { ...acc, [k]: v }
: acc,
{},
);
}

/**
* Parses a stringified JSON API call.
*/
Expand All @@ -54,17 +41,6 @@ export function decodeCall(call: string | undefined): any {
return JSON.parse(call);
}

export function startsWithOneOf(searchStrings: string[]): (string: string) => boolean {
return function(string: string): boolean {
for (const searchString of searchStrings) {
if (string.startsWith(searchString)) {
return true;
}
}
return false;
};
}

/**
* Responds to the CloudFormation Custom Resource.
*/
Expand Down Expand Up @@ -140,3 +116,49 @@ export async function getCredentials(call: AwsSdkCall, physicalResourceId: strin
}
return credentials;
}

/**
* Formats API response data based on outputPath or outputPaths configured in the SDK call.
*/
export function formatData(call: AwsSdkCall, flatData: { [key: string]: string }): { [key: string]: string } {
let outputPaths: string[] | undefined;
if (call.outputPath) {
outputPaths = [call.outputPath];
} else if (call.outputPaths) {
outputPaths = call.outputPaths;
}

if (outputPaths) {
return filterKeys(flatData, startsWithOneOf(outputPaths));
}

return flatData;
}

/**
* Returns a predicate function that returns true if a target string starts with any of the specified
* search strings.
*/
function startsWithOneOf(searchStrings: string[]): (string: string) => boolean {
return function(string: string): boolean {
for (const searchString of searchStrings) {
if (string.startsWith(searchString)) {
return true;
}
}
return false;
};
}

/**
* Filters the keys of an object.
*/
function filterKeys(object: object, pred: (key: string) => boolean): {} {
return Object.entries(object)
.reduce(
(acc, [k, v]) => pred(k)
? { ...acc, [k]: v }
: acc,
{},
);
}
Loading