Skip to content

Commit 5363f77

Browse files
CCM-10927 Fix line endings
1 parent 05f4139 commit 5363f77

File tree

3 files changed

+97
-98
lines changed

3 files changed

+97
-98
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
locals {
2-
aws_lambda_functions_dir_path = "../../../../lambdas"
3-
4-
openapi_spec = templatefile("${path.module}/resources/spec.tmpl.json", {
5-
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
6-
AWS_REGION = var.region
7-
# AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
8-
HELLO_WORLD_LAMBDA_ARN = module.hello_world.function_arn
9-
})
10-
}
1+
locals {
2+
aws_lambda_functions_dir_path = "../../../../lambdas"
3+
4+
openapi_spec = templatefile("${path.module}/resources/spec.tmpl.json", {
5+
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
6+
AWS_REGION = var.region
7+
# AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
8+
HELLO_WORLD_LAMBDA_ARN = module.hello_world.function_arn
9+
})
10+
}

lambdas/authorizer/src/index.ts

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
// A simple request-based authorizer example to demonstrate how to use request
2-
// parameters to allow or deny a request. In this example, a request is
3-
// authorized if the client-supplied HeaderAuth1 header and stage variable of StageVar1
4-
// both match specified values of 'headerValue1' and 'stageValue1', respectively.
5-
//
6-
// Example curl request (replace <api-url> and <stage> as appropriate):
7-
//
8-
// curl -H "HeaderAuth1: headerValue1" \
9-
// "<api-url>/<stage>/your-resource"
10-
//
11-
12-
// See https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html for the original JS documentation
13-
14-
import { APIGatewayRequestAuthorizerEvent, Context, Callback, APIGatewayAuthorizerResult } from 'aws-lambda';
15-
16-
export const handler = (
17-
event: APIGatewayRequestAuthorizerEvent,
18-
context: Context,
19-
callback: Callback<APIGatewayAuthorizerResult>
20-
): void => {
21-
console.log('Received event:', JSON.stringify(event, null, 2));
22-
23-
// Retrieve request parameters from the Lambda function input:
24-
const headers = event.headers || {};
25-
const pathParameters = event.pathParameters || {};
26-
const stageVariables = event.stageVariables || {};
27-
28-
// Parse the input for the parameter values
29-
const tmp = event.methodArn.split(':');
30-
const apiGatewayArnTmp = tmp[5].split('/');
31-
const awsAccountId = tmp[4];
32-
const region = tmp[3];
33-
const restApiId = apiGatewayArnTmp[0];
34-
const stage = apiGatewayArnTmp[1];
35-
const method = apiGatewayArnTmp[2];
36-
let resource = '/'; // root resource
37-
if (apiGatewayArnTmp[3]) {
38-
resource += apiGatewayArnTmp[3];
39-
}
40-
41-
// Perform authorization to return the Allow policy for correct parameters and
42-
// the 'Unauthorized' error, otherwise.
43-
if (
44-
headers['HeaderAuth1'] === 'headerValue1' &&
45-
stageVariables['StageVar1'] === 'stageValue1'
46-
) {
47-
callback(null, generateAllow('me', event.methodArn));
48-
} else {
49-
callback(null, generateDeny('me', event.methodArn));
50-
}
51-
};
52-
53-
// Helper function to generate an IAM policy
54-
function generatePolicy(
55-
principalId: string,
56-
effect: 'Allow' | 'Deny',
57-
resource: string
58-
): APIGatewayAuthorizerResult {
59-
// Required output:
60-
const authResponse: APIGatewayAuthorizerResult = {
61-
principalId,
62-
policyDocument: {
63-
Version: '2012-10-17',
64-
Statement: [
65-
{
66-
Action: 'execute-api:Invoke',
67-
Effect: effect,
68-
Resource: resource,
69-
},
70-
],
71-
},
72-
context: {
73-
stringKey: 'stringval',
74-
numberKey: 123,
75-
booleanKey: true,
76-
},
77-
};
78-
return authResponse;
79-
}
80-
81-
function generateAllow(principalId: string, resource: string): APIGatewayAuthorizerResult {
82-
return generatePolicy(principalId, 'Allow', resource);
83-
}
84-
85-
function generateDeny(principalId: string, resource: string): APIGatewayAuthorizerResult {
86-
return generatePolicy(principalId, 'Deny', resource);
87-
}
1+
// A simple request-based authorizer example to demonstrate how to use request
2+
// parameters to allow or deny a request. In this example, a request is
3+
// authorized if the client-supplied HeaderAuth1 header and stage variable of StageVar1
4+
// both match specified values of 'headerValue1' and 'stageValue1', respectively.
5+
//
6+
// Example curl request (replace <api-url> and <stage> as appropriate):
7+
//
8+
// curl -H "HeaderAuth1: headerValue1" \
9+
// "<api-url>/<stage>/your-resource"
10+
//
11+
12+
// See https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html for the original JS documentation
13+
14+
import { APIGatewayRequestAuthorizerEvent, Context, Callback, APIGatewayAuthorizerResult } from 'aws-lambda';
15+
16+
export const handler = (
17+
event: APIGatewayRequestAuthorizerEvent,
18+
context: Context,
19+
callback: Callback<APIGatewayAuthorizerResult>
20+
): void => {
21+
console.log('Received event:', JSON.stringify(event, null, 2));
22+
23+
// Retrieve request parameters from the Lambda function input:
24+
const headers = event.headers || {};
25+
const pathParameters = event.pathParameters || {};
26+
const stageVariables = event.stageVariables || {};
27+
28+
// Parse the input for the parameter values
29+
const tmp = event.methodArn.split(':');
30+
const apiGatewayArnTmp = tmp[5].split('/');
31+
const awsAccountId = tmp[4];
32+
const region = tmp[3];
33+
const restApiId = apiGatewayArnTmp[0];
34+
const stage = apiGatewayArnTmp[1];
35+
const method = apiGatewayArnTmp[2];
36+
let resource = '/'; // root resource
37+
if (apiGatewayArnTmp[3]) {
38+
resource += apiGatewayArnTmp[3];
39+
}
40+
41+
// Perform authorization to return the Allow policy for correct parameters and
42+
// the 'Unauthorized' error, otherwise.
43+
if (
44+
headers['HeaderAuth1'] === 'headerValue1' &&
45+
stageVariables['StageVar1'] === 'stageValue1'
46+
) {
47+
callback(null, generateAllow('me', event.methodArn));
48+
} else {
49+
callback(null, generateDeny('me', event.methodArn));
50+
}
51+
};
52+
53+
// Helper function to generate an IAM policy
54+
function generatePolicy(
55+
principalId: string,
56+
effect: 'Allow' | 'Deny',
57+
resource: string
58+
): APIGatewayAuthorizerResult {
59+
// Required output:
60+
const authResponse: APIGatewayAuthorizerResult = {
61+
principalId,
62+
policyDocument: {
63+
Version: '2012-10-17',
64+
Statement: [
65+
{
66+
Action: 'execute-api:Invoke',
67+
Effect: effect,
68+
Resource: resource,
69+
},
70+
],
71+
},
72+
context: {
73+
stringKey: 'stringval',
74+
numberKey: 123,
75+
booleanKey: true,
76+
},
77+
};
78+
return authResponse;
79+
}
80+
81+
function generateAllow(principalId: string, resource: string): APIGatewayAuthorizerResult {
82+
return generatePolicy(principalId, 'Allow', resource);
83+
}
84+
85+
function generateDeny(principalId: string, resource: string): APIGatewayAuthorizerResult {
86+
return generatePolicy(principalId, 'Deny', resource);
87+
}

scripts/githooks/check-file-format.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ function run-editorconfig-natively() {
8989
# dry_run_opt=[dry run option]
9090
# filter=[git command to filter the files to check]
9191
function run-editorconfig-in-docker() {
92-
echo "RUNNING EDITOR CHECK IN DOCKER"
9392
# shellcheck disable=SC1091
9493
source ./scripts/docker/docker.lib.sh
9594

0 commit comments

Comments
 (0)