@aws/nx-plugin 0.119.0 → 0.121.0
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.
- package/package.json +1 -1
- package/src/mcp-server/generator-info.d.ts +2 -6
- package/src/mcp-server/generator-info.js +19 -40
- package/src/mcp-server/generator-info.js.map +1 -1
- package/src/preset/generator.js +1 -0
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/generator.js +4 -1
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/schema.json +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +197 -12
- package/src/py/fast-api/generator.js +9 -0
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/schema.d.ts +1 -1
- package/src/py/fast-api/schema.json +2 -2
- package/src/py/mcp-server/generator.js +3 -0
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/mcp-server/schema.json +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +195 -11
- package/src/smithy/ts/api/generator.js +18 -0
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/smithy/ts/api/schema.d.ts +1 -1
- package/src/smithy/ts/api/schema.json +2 -2
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +258 -25
- package/src/trpc/backend/generator.js +19 -0
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +1 -1
- package/src/trpc/backend/schema.json +2 -2
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +28 -18
- package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +9 -6
- package/src/trpc/react/generator.js +2 -6
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/agent/generator.js +4 -1
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/schema.json +1 -1
- package/src/ts/mcp-server/generator.js +3 -0
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/mcp-server/schema.json +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +3 -1
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +38 -6
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +39 -3
- package/src/utils/api-constructs/files/cdk/authorizer/http/authorizer.ts.template +34 -0
- package/src/utils/api-constructs/files/cdk/authorizer/rest/authorizer.ts.template +52 -0
- package/src/utils/api-constructs/files/py-authorizer/http/authorizer.py.template +25 -0
- package/src/utils/api-constructs/files/py-authorizer/rest/authorizer.py.template +39 -0
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +112 -5
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +114 -6
- package/src/utils/commands.d.ts +1 -1
- package/src/utils/commands.js +3 -2
- package/src/utils/commands.js.map +1 -1
- package/src/utils/connection/open-api/react.d.ts +1 -1
|
@@ -747,7 +747,7 @@ export class TestApi<
|
|
|
747
747
|
"
|
|
748
748
|
`;
|
|
749
749
|
|
|
750
|
-
exports[`trpc backend generator > should generate with
|
|
750
|
+
exports[`trpc backend generator > should generate with custom auth for a REST API > apps/test-api/src/client/index.ts 1`] = `
|
|
751
751
|
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
752
752
|
import { AppRouter } from '../router.js';
|
|
753
753
|
|
|
@@ -766,12 +766,12 @@ export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
|
766
766
|
"
|
|
767
767
|
`;
|
|
768
768
|
|
|
769
|
-
exports[`trpc backend generator > should generate with
|
|
769
|
+
exports[`trpc backend generator > should generate with custom auth for a REST API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
770
770
|
"export * from './test-api.js';
|
|
771
771
|
"
|
|
772
772
|
`;
|
|
773
773
|
|
|
774
|
-
exports[`trpc backend generator > should generate with
|
|
774
|
+
exports[`trpc backend generator > should generate with custom auth for a REST API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
775
775
|
"import { Construct } from 'constructs';
|
|
776
776
|
import * as url from 'url';
|
|
777
777
|
import { Distribution } from 'aws-cdk-lib/aws-cloudfront';
|
|
@@ -787,6 +787,7 @@ import {
|
|
|
787
787
|
AuthorizationType,
|
|
788
788
|
LambdaIntegration,
|
|
789
789
|
ResponseTransferMode,
|
|
790
|
+
TokenAuthorizer,
|
|
790
791
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
791
792
|
import { Aspects, Duration } from 'aws-cdk-lib';
|
|
792
793
|
import {
|
|
@@ -885,17 +886,39 @@ export class TestApi<
|
|
|
885
886
|
id: string,
|
|
886
887
|
props: TestApiProps<TIntegrations>,
|
|
887
888
|
) {
|
|
889
|
+
const authorizerFunction = new Function(
|
|
890
|
+
scope,
|
|
891
|
+
'TestApiAuthorizerFunction',
|
|
892
|
+
{
|
|
893
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
894
|
+
handler: 'index.handler',
|
|
895
|
+
code: Code.fromAsset(
|
|
896
|
+
url.fileURLToPath(
|
|
897
|
+
new URL(
|
|
898
|
+
'../../../../../../dist/apps/test-api/bundle/authorizer',
|
|
899
|
+
import.meta.url,
|
|
900
|
+
),
|
|
901
|
+
),
|
|
902
|
+
),
|
|
903
|
+
timeout: Duration.seconds(10),
|
|
904
|
+
tracing: Tracing.ACTIVE,
|
|
905
|
+
},
|
|
906
|
+
);
|
|
907
|
+
|
|
888
908
|
super(scope, id, {
|
|
889
909
|
apiName: 'TestApi',
|
|
890
910
|
defaultMethodOptions: {
|
|
891
|
-
authorizationType: AuthorizationType.
|
|
911
|
+
authorizationType: AuthorizationType.CUSTOM,
|
|
912
|
+
authorizer: new TokenAuthorizer(scope, 'TestApiTokenAuthorizer', {
|
|
913
|
+
handler: authorizerFunction,
|
|
914
|
+
}),
|
|
892
915
|
},
|
|
893
916
|
deployOptions: {
|
|
894
917
|
tracingEnabled: true,
|
|
895
918
|
},
|
|
896
919
|
policy: new PolicyDocument({
|
|
897
920
|
statements: [
|
|
898
|
-
// Allow all callers to invoke the API in the resource policy
|
|
921
|
+
// Allow all callers to invoke the API in the resource policy, since auth is handled by the Lambda Authorizer
|
|
899
922
|
new PolicyStatement({
|
|
900
923
|
effect: Effect.ALLOW,
|
|
901
924
|
principals: [new AnyPrincipal()],
|
|
@@ -950,7 +973,7 @@ export class TestApi<
|
|
|
950
973
|
"
|
|
951
974
|
`;
|
|
952
975
|
|
|
953
|
-
exports[`trpc backend generator > should generate with
|
|
976
|
+
exports[`trpc backend generator > should generate with custom auth for an HTTP API > apps/test-api/src/client/index.ts 1`] = `
|
|
954
977
|
"import { createTRPCClient, httpLink, HTTPLinkOptions } from '@trpc/client';
|
|
955
978
|
import { AppRouter } from '../router.js';
|
|
956
979
|
|
|
@@ -969,12 +992,12 @@ export const createTestApiClient = (config: TestApiClientConfig) => {
|
|
|
969
992
|
"
|
|
970
993
|
`;
|
|
971
994
|
|
|
972
|
-
exports[`trpc backend generator > should generate with
|
|
995
|
+
exports[`trpc backend generator > should generate with custom auth for an HTTP API > packages/common/constructs/src/app/apis/index.ts 1`] = `
|
|
973
996
|
"export * from './test-api.js';
|
|
974
997
|
"
|
|
975
998
|
`;
|
|
976
999
|
|
|
977
|
-
exports[`trpc backend generator > should generate with
|
|
1000
|
+
exports[`trpc backend generator > should generate with custom auth for an HTTP API > packages/common/constructs/src/app/apis/test-api.ts 1`] = `
|
|
978
1001
|
"import { Construct } from 'constructs';
|
|
979
1002
|
import * as url from 'url';
|
|
980
1003
|
import { Distribution } from 'aws-cdk-lib/aws-cloudfront';
|
|
@@ -987,11 +1010,11 @@ import {
|
|
|
987
1010
|
} from 'aws-cdk-lib/aws-lambda';
|
|
988
1011
|
import { Duration } from 'aws-cdk-lib';
|
|
989
1012
|
import { RuntimeConfig } from '../../core/runtime-config.js';
|
|
1013
|
+
import { CorsHttpMethod, CfnApi } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
990
1014
|
import {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
} from 'aws-cdk-lib/aws-apigatewayv2';
|
|
1015
|
+
HttpLambdaAuthorizer,
|
|
1016
|
+
HttpLambdaResponseType,
|
|
1017
|
+
} from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
995
1018
|
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
996
1019
|
import {
|
|
997
1020
|
ApiIntegrations,
|
|
@@ -1076,6 +1099,25 @@ export class TestApi<
|
|
|
1076
1099
|
id: string,
|
|
1077
1100
|
props: TestApiProps<TIntegrations>,
|
|
1078
1101
|
) {
|
|
1102
|
+
const authorizerFunction = new Function(
|
|
1103
|
+
scope,
|
|
1104
|
+
'TestApiAuthorizerFunction',
|
|
1105
|
+
{
|
|
1106
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
1107
|
+
handler: 'index.handler',
|
|
1108
|
+
code: Code.fromAsset(
|
|
1109
|
+
url.fileURLToPath(
|
|
1110
|
+
new URL(
|
|
1111
|
+
'../../../../../../dist/apps/test-api/bundle/authorizer',
|
|
1112
|
+
import.meta.url,
|
|
1113
|
+
),
|
|
1114
|
+
),
|
|
1115
|
+
),
|
|
1116
|
+
timeout: Duration.seconds(10),
|
|
1117
|
+
tracing: Tracing.ACTIVE,
|
|
1118
|
+
},
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1079
1121
|
super(scope, id, {
|
|
1080
1122
|
apiName: 'TestApi',
|
|
1081
1123
|
corsPreflight: {
|
|
@@ -1089,7 +1131,13 @@ export class TestApi<
|
|
|
1089
1131
|
'x-amz-security-token',
|
|
1090
1132
|
],
|
|
1091
1133
|
},
|
|
1092
|
-
defaultAuthorizer: new
|
|
1134
|
+
defaultAuthorizer: new HttpLambdaAuthorizer(
|
|
1135
|
+
'TestApiLambdaAuthorizer',
|
|
1136
|
+
authorizerFunction,
|
|
1137
|
+
{
|
|
1138
|
+
responseTypes: [HttpLambdaResponseType.SIMPLE],
|
|
1139
|
+
},
|
|
1140
|
+
),
|
|
1093
1141
|
operations: routerToOperations(appRouter),
|
|
1094
1142
|
...props,
|
|
1095
1143
|
});
|
|
@@ -3572,7 +3620,7 @@ output "api_log_group_arn" {
|
|
|
3572
3620
|
}
|
|
3573
3621
|
`;
|
|
3574
3622
|
|
|
3575
|
-
exports[`trpc backend generator > terraform iacProvider > should generate terraform files for HTTP API with
|
|
3623
|
+
exports[`trpc backend generator > terraform iacProvider > should generate terraform files for HTTP API with Custom auth and snapshot them > terraform-http-custom-files 1`] = `
|
|
3576
3624
|
{
|
|
3577
3625
|
"http-api.tf": "# Core HTTP API Gateway module
|
|
3578
3626
|
# This module creates the API Gateway HTTP API, stage, and logging resources
|
|
@@ -4038,6 +4086,100 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
|
|
|
4038
4086
|
}
|
|
4039
4087
|
|
|
4040
4088
|
|
|
4089
|
+
# Custom Lambda Authorizer
|
|
4090
|
+
resource "aws_lambda_function" "authorizer_lambda" {
|
|
4091
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
4092
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for authorizer
|
|
4093
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
4094
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
4095
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
4096
|
+
s3_bucket = aws_s3_object.authorizer_zip.bucket
|
|
4097
|
+
s3_key = aws_s3_object.authorizer_zip.key
|
|
4098
|
+
s3_object_version = aws_s3_object.authorizer_zip.version_id
|
|
4099
|
+
function_name = "TestApiAuthorizer-\${random_string.suffix.result}"
|
|
4100
|
+
role = aws_iam_role.authorizer_execution_role.arn
|
|
4101
|
+
handler = "index.handler"
|
|
4102
|
+
runtime = "nodejs22.x"
|
|
4103
|
+
timeout = 10
|
|
4104
|
+
memory_size = 128
|
|
4105
|
+
|
|
4106
|
+
source_code_hash = data.archive_file.authorizer_zip.output_base64sha256
|
|
4107
|
+
|
|
4108
|
+
tracing_config {
|
|
4109
|
+
mode = "Active"
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4112
|
+
tags = var.tags
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4115
|
+
resource "aws_iam_role" "authorizer_execution_role" {
|
|
4116
|
+
name = "TestApiAuthorizer-role-\${random_string.suffix.result}"
|
|
4117
|
+
|
|
4118
|
+
assume_role_policy = jsonencode({
|
|
4119
|
+
Version = "2012-10-17"
|
|
4120
|
+
Statement = [
|
|
4121
|
+
{
|
|
4122
|
+
Action = "sts:AssumeRole"
|
|
4123
|
+
Effect = "Allow"
|
|
4124
|
+
Principal = {
|
|
4125
|
+
Service = "lambda.amazonaws.com"
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
]
|
|
4129
|
+
})
|
|
4130
|
+
|
|
4131
|
+
tags = var.tags
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
resource "aws_iam_role_policy_attachment" "authorizer_basic_execution" {
|
|
4135
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
|
4136
|
+
role = aws_iam_role.authorizer_execution_role.name
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
resource "aws_iam_role_policy_attachment" "authorizer_xray_execution" {
|
|
4140
|
+
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
|
|
4141
|
+
role = aws_iam_role.authorizer_execution_role.name
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
resource "aws_cloudwatch_log_group" "authorizer_logs" {
|
|
4145
|
+
#checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
|
|
4146
|
+
#checkov:skip=CKV_AWS_338:Log retention set to forever
|
|
4147
|
+
#checkov:skip=CKV_AWS_66:Log retention set to forever
|
|
4148
|
+
name = "/aws/lambda/TestApiAuthorizer-\${random_string.suffix.result}"
|
|
4149
|
+
tags = var.tags
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
data "archive_file" "authorizer_zip" {
|
|
4153
|
+
type = "zip"
|
|
4154
|
+
source_dir = "\${path.module}/../../../../../../../dist/apps/test-api/bundle/authorizer"
|
|
4155
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/authorizer.zip"
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
resource "aws_s3_object" "authorizer_zip" {
|
|
4159
|
+
bucket = var.asset_bucket_name
|
|
4160
|
+
key = "apis/test-api/authorizer-\${data.archive_file.authorizer_zip.output_sha256}.zip"
|
|
4161
|
+
source = data.archive_file.authorizer_zip.output_path
|
|
4162
|
+
source_hash = data.archive_file.authorizer_zip.output_base64sha256
|
|
4163
|
+
etag = data.archive_file.authorizer_zip.output_md5
|
|
4164
|
+
}
|
|
4165
|
+
|
|
4166
|
+
resource "aws_apigatewayv2_authorizer" "custom_authorizer" {
|
|
4167
|
+
api_id = module.http_api.api_id
|
|
4168
|
+
authorizer_type = "REQUEST"
|
|
4169
|
+
authorizer_uri = aws_lambda_function.authorizer_lambda.invoke_arn
|
|
4170
|
+
authorizer_payload_format_version = "2.0"
|
|
4171
|
+
authorizer_result_ttl_in_seconds = 0
|
|
4172
|
+
enable_simple_responses = true
|
|
4173
|
+
name = "TestApiAuthorizer-\${random_string.suffix.result}"
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
resource "aws_lambda_permission" "authorizer_invoke" {
|
|
4177
|
+
statement_id = "AllowAPIGatewayInvokeAuthorizer"
|
|
4178
|
+
action = "lambda:InvokeFunction"
|
|
4179
|
+
function_name = aws_lambda_function.authorizer_lambda.function_name
|
|
4180
|
+
principal = "apigateway.amazonaws.com"
|
|
4181
|
+
source_arn = "\${module.http_api.api_execution_arn}/authorizers/\${aws_apigatewayv2_authorizer.custom_authorizer.id}"
|
|
4182
|
+
}
|
|
4041
4183
|
|
|
4042
4184
|
# Lambda integration for HTTP API
|
|
4043
4185
|
resource "aws_apigatewayv2_integration" "lambda_integration" {
|
|
@@ -4061,9 +4203,10 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
4061
4203
|
route_key = "\${each.key} /{proxy+}"
|
|
4062
4204
|
target = "integrations/\${aws_apigatewayv2_integration.lambda_integration.id}"
|
|
4063
4205
|
|
|
4064
|
-
authorization_type = "
|
|
4206
|
+
authorization_type = "CUSTOM"
|
|
4207
|
+
authorizer_id = aws_apigatewayv2_authorizer.custom_authorizer.id
|
|
4065
4208
|
|
|
4066
|
-
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
4209
|
+
depends_on = [aws_apigatewayv2_integration.lambda_integration, aws_apigatewayv2_authorizer.custom_authorizer]
|
|
4067
4210
|
}
|
|
4068
4211
|
|
|
4069
4212
|
# Add API url to runtime config
|
|
@@ -4202,7 +4345,7 @@ output "api_log_group_arn" {
|
|
|
4202
4345
|
}
|
|
4203
4346
|
`;
|
|
4204
4347
|
|
|
4205
|
-
exports[`trpc backend generator > terraform iacProvider > should generate terraform files for HTTP API with
|
|
4348
|
+
exports[`trpc backend generator > terraform iacProvider > should generate terraform files for HTTP API with IAM auth and snapshot them > terraform-http-iam-files 1`] = `
|
|
4206
4349
|
{
|
|
4207
4350
|
"http-api.tf": "# Core HTTP API Gateway module
|
|
4208
4351
|
# This module creates the API Gateway HTTP API, stage, and logging resources
|
|
@@ -4691,9 +4834,7 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
4691
4834
|
route_key = "\${each.key} /{proxy+}"
|
|
4692
4835
|
target = "integrations/\${aws_apigatewayv2_integration.lambda_integration.id}"
|
|
4693
4836
|
|
|
4694
|
-
|
|
4695
|
-
# need a public API without authentication
|
|
4696
|
-
authorization_type = "NONE"
|
|
4837
|
+
authorization_type = "AWS_IAM"
|
|
4697
4838
|
|
|
4698
4839
|
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
4699
4840
|
}
|
|
@@ -6896,6 +7037,98 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
|
|
|
6896
7037
|
}
|
|
6897
7038
|
|
|
6898
7039
|
|
|
7040
|
+
# Custom Lambda Authorizer
|
|
7041
|
+
resource "aws_lambda_function" "authorizer_lambda" {
|
|
7042
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
7043
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for authorizer
|
|
7044
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
7045
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
7046
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
7047
|
+
s3_bucket = aws_s3_object.authorizer_zip.bucket
|
|
7048
|
+
s3_key = aws_s3_object.authorizer_zip.key
|
|
7049
|
+
s3_object_version = aws_s3_object.authorizer_zip.version_id
|
|
7050
|
+
function_name = "TestApiAuthorizer-\${random_string.suffix.result}"
|
|
7051
|
+
role = aws_iam_role.authorizer_execution_role.arn
|
|
7052
|
+
handler = "index.handler"
|
|
7053
|
+
runtime = "nodejs22.x"
|
|
7054
|
+
timeout = 10
|
|
7055
|
+
memory_size = 128
|
|
7056
|
+
|
|
7057
|
+
source_code_hash = data.archive_file.authorizer_zip.output_base64sha256
|
|
7058
|
+
|
|
7059
|
+
tracing_config {
|
|
7060
|
+
mode = "Active"
|
|
7061
|
+
}
|
|
7062
|
+
|
|
7063
|
+
tags = var.tags
|
|
7064
|
+
}
|
|
7065
|
+
|
|
7066
|
+
resource "aws_iam_role" "authorizer_execution_role" {
|
|
7067
|
+
name = "TestApiAuthorizer-role-\${random_string.suffix.result}"
|
|
7068
|
+
|
|
7069
|
+
assume_role_policy = jsonencode({
|
|
7070
|
+
Version = "2012-10-17"
|
|
7071
|
+
Statement = [
|
|
7072
|
+
{
|
|
7073
|
+
Action = "sts:AssumeRole"
|
|
7074
|
+
Effect = "Allow"
|
|
7075
|
+
Principal = {
|
|
7076
|
+
Service = "lambda.amazonaws.com"
|
|
7077
|
+
}
|
|
7078
|
+
}
|
|
7079
|
+
]
|
|
7080
|
+
})
|
|
7081
|
+
|
|
7082
|
+
tags = var.tags
|
|
7083
|
+
}
|
|
7084
|
+
|
|
7085
|
+
resource "aws_iam_role_policy_attachment" "authorizer_basic_execution" {
|
|
7086
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
|
7087
|
+
role = aws_iam_role.authorizer_execution_role.name
|
|
7088
|
+
}
|
|
7089
|
+
|
|
7090
|
+
resource "aws_iam_role_policy_attachment" "authorizer_xray_execution" {
|
|
7091
|
+
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
|
|
7092
|
+
role = aws_iam_role.authorizer_execution_role.name
|
|
7093
|
+
}
|
|
7094
|
+
|
|
7095
|
+
resource "aws_cloudwatch_log_group" "authorizer_logs" {
|
|
7096
|
+
#checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
|
|
7097
|
+
#checkov:skip=CKV_AWS_338:Log retention set to forever
|
|
7098
|
+
#checkov:skip=CKV_AWS_66:Log retention set to forever
|
|
7099
|
+
name = "/aws/lambda/TestApiAuthorizer-\${random_string.suffix.result}"
|
|
7100
|
+
tags = var.tags
|
|
7101
|
+
}
|
|
7102
|
+
|
|
7103
|
+
data "archive_file" "authorizer_zip" {
|
|
7104
|
+
type = "zip"
|
|
7105
|
+
source_dir = "\${path.module}/../../../../../../../dist/apps/test-api/bundle/authorizer"
|
|
7106
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/authorizer.zip"
|
|
7107
|
+
}
|
|
7108
|
+
|
|
7109
|
+
resource "aws_s3_object" "authorizer_zip" {
|
|
7110
|
+
bucket = var.asset_bucket_name
|
|
7111
|
+
key = "apis/test-api/authorizer-\${data.archive_file.authorizer_zip.output_sha256}.zip"
|
|
7112
|
+
source = data.archive_file.authorizer_zip.output_path
|
|
7113
|
+
source_hash = data.archive_file.authorizer_zip.output_base64sha256
|
|
7114
|
+
etag = data.archive_file.authorizer_zip.output_md5
|
|
7115
|
+
}
|
|
7116
|
+
|
|
7117
|
+
resource "aws_api_gateway_authorizer" "custom_authorizer" {
|
|
7118
|
+
name = "TestApiAuthorizer-\${random_string.suffix.result}"
|
|
7119
|
+
rest_api_id = module.rest_api.api_id
|
|
7120
|
+
type = "TOKEN"
|
|
7121
|
+
authorizer_uri = aws_lambda_function.authorizer_lambda.invoke_arn
|
|
7122
|
+
identity_source = "method.request.header.Authorization"
|
|
7123
|
+
}
|
|
7124
|
+
|
|
7125
|
+
resource "aws_lambda_permission" "authorizer_invoke" {
|
|
7126
|
+
statement_id = "AllowAPIGatewayInvokeAuthorizer"
|
|
7127
|
+
action = "lambda:InvokeFunction"
|
|
7128
|
+
function_name = aws_lambda_function.authorizer_lambda.function_name
|
|
7129
|
+
principal = "apigateway.amazonaws.com"
|
|
7130
|
+
source_arn = "\${module.rest_api.api_execution_arn}/authorizers/\${aws_api_gateway_authorizer.custom_authorizer.id}"
|
|
7131
|
+
}
|
|
6899
7132
|
|
|
6900
7133
|
# Create proxy resource (captures all paths)
|
|
6901
7134
|
resource "aws_api_gateway_resource" "proxy_resource" {
|
|
@@ -6925,15 +7158,14 @@ resource "aws_api_gateway_method" "proxy_method" {
|
|
|
6925
7158
|
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
6926
7159
|
http_method = "ANY"
|
|
6927
7160
|
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
authorization = "NONE"
|
|
7161
|
+
authorization = "CUSTOM"
|
|
7162
|
+
authorizer_id = aws_api_gateway_authorizer.custom_authorizer.id
|
|
6931
7163
|
|
|
6932
7164
|
request_parameters = {
|
|
6933
7165
|
"method.request.path.proxy" = true
|
|
6934
7166
|
}
|
|
6935
7167
|
|
|
6936
|
-
depends_on = []
|
|
7168
|
+
depends_on = [aws_api_gateway_authorizer.custom_authorizer]
|
|
6937
7169
|
}
|
|
6938
7170
|
|
|
6939
7171
|
# OPTIONS method for CORS preflight
|
|
@@ -7011,6 +7243,7 @@ resource "aws_api_gateway_deployment" "api_deployment" {
|
|
|
7011
7243
|
aws_api_gateway_integration.options_integration,
|
|
7012
7244
|
aws_api_gateway_method_response.options_response,
|
|
7013
7245
|
aws_api_gateway_integration_response.options_integration_response,
|
|
7246
|
+
aws_api_gateway_authorizer.custom_authorizer,
|
|
7014
7247
|
]
|
|
7015
7248
|
}
|
|
7016
7249
|
|
|
@@ -7039,7 +7272,7 @@ resource "aws_api_gateway_rest_api_policy" "api_policy" {
|
|
|
7039
7272
|
Version = "2012-10-17"
|
|
7040
7273
|
Statement = [
|
|
7041
7274
|
{
|
|
7042
|
-
# Allow all callers to invoke the API in the resource policy
|
|
7275
|
+
# Allow all callers to invoke the API in the resource policy, since auth is handled by the Lambda Authorizer
|
|
7043
7276
|
Effect = "Allow"
|
|
7044
7277
|
Principal = "*"
|
|
7045
7278
|
Action = "execute-api:Invoke"
|
|
@@ -69,6 +69,9 @@ async function tsTrpcApiGenerator(tree, options) {
|
|
|
69
69
|
projectAlias: enhancedOptions.backendProjectAlias,
|
|
70
70
|
bundleOutputDir: (0, devkit_1.joinPathFragments)('dist', backendRoot, 'bundle'),
|
|
71
71
|
integrationPattern: getIntegrationPattern(options),
|
|
72
|
+
...(options.auth === 'Custom' && {
|
|
73
|
+
authorizerBundleOutputDir: (0, devkit_1.joinPathFragments)('dist', backendRoot, 'bundle', 'authorizer'),
|
|
74
|
+
}),
|
|
72
75
|
},
|
|
73
76
|
auth: options.auth,
|
|
74
77
|
iacProvider,
|
|
@@ -102,6 +105,13 @@ async function tsTrpcApiGenerator(tree, options) {
|
|
|
102
105
|
targetFilePath: 'src/handler.ts',
|
|
103
106
|
external: [/@aws-sdk\/.*/], // lambda runtime provides aws sdk
|
|
104
107
|
});
|
|
108
|
+
if (options.auth === 'Custom') {
|
|
109
|
+
await (0, bundle_1.addTypeScriptBundleTarget)(tree, projectConfig, {
|
|
110
|
+
targetFilePath: 'src/authorizer.ts',
|
|
111
|
+
bundleOutputDir: 'authorizer',
|
|
112
|
+
external: [/@aws-sdk\/.*/],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
105
115
|
(0, nx_1.addDependencyToTargetIfNotPresent)(projectConfig, 'build', 'bundle');
|
|
106
116
|
projectConfig.targets = (0, object_1.sortObjectKeys)(projectConfig.targets);
|
|
107
117
|
(0, devkit_1.updateProjectConfiguration)(tree, projectConfig.name, projectConfig);
|
|
@@ -109,6 +119,12 @@ async function tsTrpcApiGenerator(tree, options) {
|
|
|
109
119
|
overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite,
|
|
110
120
|
});
|
|
111
121
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'src', 'lib'));
|
|
122
|
+
if (options.auth === 'Custom') {
|
|
123
|
+
const authorizerType = options.computeType === 'ServerlessApiGatewayHttpApi' ? 'http' : 'rest';
|
|
124
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '..', '..', 'utils', 'api-constructs', 'files', 'cdk', 'authorizer', authorizerType), (0, devkit_1.joinPathFragments)(backendRoot, 'src'), {}, {
|
|
125
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
112
128
|
// Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)
|
|
113
129
|
if (options.computeType !== 'ServerlessApiGatewayRestApi') {
|
|
114
130
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'src', 'schema', 'z-async-iterable.ts'));
|
|
@@ -125,6 +141,9 @@ async function tsTrpcApiGenerator(tree, options) {
|
|
|
125
141
|
'@trpc/client',
|
|
126
142
|
'aws4fetch',
|
|
127
143
|
'@aws-sdk/credential-providers',
|
|
144
|
+
...(options.auth === 'Custom'
|
|
145
|
+
? ['@middy/core', '@aws-lambda-powertools/parser']
|
|
146
|
+
: []),
|
|
128
147
|
]), (0, versions_1.withVersions)(['@types/aws-lambda', 'tsx', 'cors', '@types/cors']));
|
|
129
148
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'package.json'));
|
|
130
149
|
(0, nx_1.addGeneratorMetadata)(tree, backendName, exports.TRPC_BACKEND_GENERATOR_INFO);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;AA6CA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;;AA6CA,gDA6LC;;AA1OD;;;GAGG;AACH,uCAQoB;AAEpB,qEAA0E;AAC1E,+EAAwD;AACxD,qDAAwE;AACxE,mDAAoD;AACpD,6CAA2D;AAC3D,+CAA0D;AAC1D,yDAA2E;AAC3E,+CAAoD;AACpD,uCAMwB;AACxB,iDAAsE;AACtE,8EAA+E;AAC/E,2CAA8C;AAC9C,yCAAqD;AACrD,sDAAsE;AAEzD,QAAA,2BAA2B,GACtC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B,MAAM,mCAAmC,GAAG,IAAI,GAAG,CAAC;IAClD,uCAAuC;IACvC,qCAAqC;IACrC,uCAAuC;IACvC,qCAAqC;CACtC,CAAC,CAAC;AAEI,KAAK,UAAU,kBAAkB,CACtC,IAAU,EACV,OAAiC;IAEjC,uDAAuD,CAAC,OAAO,CAAC,CAAC;IAEjE,MAAM,WAAW,GAAG,MAAM,IAAA,wBAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAExE,MAAM,IAAA,6CAAyB,EAAC,IAAI,EAAE;QACpC,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;IAC7C,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H,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAC5B,OAAiC,EACV,EAAE;IACzB,OAAO,OAAO,CAAC,kBAAkB,IAAI,UAAU,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,OAAiC,EAAU,EAAE;IAC3E,IAAI,OAAO,CAAC,WAAW,KAAK,6BAA6B,EAAE,CAAC;QAC1D,OAAO,sBAAsB,CAAC;IAChC,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAO,yCAAyC,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,yCAAyC,CAAC;IACnD,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAEF,kBAAe,kBAAkB,CAAC"}
|
|
@@ -10,7 +10,7 @@ export interface TsTrpcApiGeneratorSchema {
|
|
|
10
10
|
name: string;
|
|
11
11
|
computeType: 'ServerlessApiGatewayRestApi' | 'ServerlessApiGatewayHttpApi';
|
|
12
12
|
integrationPattern?: 'isolated' | 'shared';
|
|
13
|
-
auth: 'IAM' | 'Cognito' | '
|
|
13
|
+
auth: 'IAM' | 'Cognito' | 'Custom';
|
|
14
14
|
directory?: TsProjectGeneratorSchema['directory'];
|
|
15
15
|
subDirectory?: TsProjectGeneratorSchema['subDirectory'];
|
|
16
16
|
iacProvider: IacProviderOption;
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"auth": {
|
|
47
47
|
"type": "string",
|
|
48
|
-
"description": "The method used to authenticate with your API. Choose between IAM (default), Cognito or
|
|
48
|
+
"description": "The method used to authenticate with your API. Choose between IAM (default), Cognito or Custom.",
|
|
49
49
|
"default": "IAM",
|
|
50
|
-
"enum": ["IAM", "Cognito", "
|
|
50
|
+
"enum": ["IAM", "Cognito", "Custom"],
|
|
51
51
|
"x-prompt": "How would you like users to authenticate with your API?",
|
|
52
52
|
"x-priority": "important"
|
|
53
53
|
},
|
|
@@ -77,7 +77,7 @@ export default TestApiClientProvider;
|
|
|
77
77
|
"
|
|
78
78
|
`;
|
|
79
79
|
|
|
80
|
-
exports[`trpc react generator > REST API (ServerlessApiGatewayRestApi) > should generate REST API client provider with splitLink for
|
|
80
|
+
exports[`trpc react generator > REST API (ServerlessApiGatewayRestApi) > should generate REST API client provider with splitLink for Custom auth > TestApiClientProvider-REST-Custom.tsx 1`] = `
|
|
81
81
|
"import { AppRouter } from 'backend';
|
|
82
82
|
import { useQueryClient } from '@tanstack/react-query';
|
|
83
83
|
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
|
|
@@ -91,7 +91,6 @@ import {
|
|
|
91
91
|
splitLink,
|
|
92
92
|
} from '@trpc/client';
|
|
93
93
|
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
94
|
-
import { useSigV4 } from '../hooks/useSigV4';
|
|
95
94
|
|
|
96
95
|
export interface TestApiTRPCContextValue {
|
|
97
96
|
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
@@ -106,7 +105,6 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
106
105
|
const queryClient = useQueryClient();
|
|
107
106
|
const runtimeConfig = useRuntimeConfig();
|
|
108
107
|
const apiUrl = runtimeConfig.apis.TestApi;
|
|
109
|
-
const sigv4Client = useSigV4();
|
|
110
108
|
|
|
111
109
|
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
112
110
|
const client = createTRPCClient<AppRouter>({
|
|
@@ -117,22 +115,14 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
117
115
|
url: apiUrl,
|
|
118
116
|
EventSource: EventSourcePolyfill,
|
|
119
117
|
eventSourceOptions: async ({ op }) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(op.input !== undefined
|
|
123
|
-
? \`?input=\${encodeURIComponent(JSON.stringify(op.input))}\`
|
|
124
|
-
: '');
|
|
125
|
-
const signed = await sigv4Client.sign(url, { method: 'GET' });
|
|
126
|
-
const headers: Record<string, string> = {};
|
|
127
|
-
signed.headers.forEach((v, k) => {
|
|
128
|
-
headers[k] = v;
|
|
129
|
-
});
|
|
130
|
-
return { headers };
|
|
118
|
+
// TODO: Add headers required by your custom authorizer
|
|
119
|
+
return { headers: {} };
|
|
131
120
|
},
|
|
132
121
|
}),
|
|
133
122
|
false: httpLink({
|
|
134
123
|
url: apiUrl,
|
|
135
|
-
|
|
124
|
+
// TODO: Add headers required by your custom authorizer
|
|
125
|
+
headers: {},
|
|
136
126
|
}),
|
|
137
127
|
}),
|
|
138
128
|
],
|
|
@@ -144,7 +134,7 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
144
134
|
});
|
|
145
135
|
|
|
146
136
|
return { optionsProxy, client };
|
|
147
|
-
}, [apiUrl, queryClient
|
|
137
|
+
}, [apiUrl, queryClient]);
|
|
148
138
|
|
|
149
139
|
return (
|
|
150
140
|
<TestApiTRPCContext.Provider value={container}>
|
|
@@ -157,7 +147,7 @@ export default TestApiClientProvider;
|
|
|
157
147
|
"
|
|
158
148
|
`;
|
|
159
149
|
|
|
160
|
-
exports[`trpc react generator > REST API (ServerlessApiGatewayRestApi) > should generate REST API client provider with splitLink for
|
|
150
|
+
exports[`trpc react generator > REST API (ServerlessApiGatewayRestApi) > should generate REST API client provider with splitLink for IAM auth > TestApiClientProvider-REST-IAM.tsx 1`] = `
|
|
161
151
|
"import { AppRouter } from 'backend';
|
|
162
152
|
import { useQueryClient } from '@tanstack/react-query';
|
|
163
153
|
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';
|
|
@@ -170,6 +160,8 @@ import {
|
|
|
170
160
|
httpSubscriptionLink,
|
|
171
161
|
splitLink,
|
|
172
162
|
} from '@trpc/client';
|
|
163
|
+
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
164
|
+
import { useSigV4 } from '../hooks/useSigV4';
|
|
173
165
|
|
|
174
166
|
export interface TestApiTRPCContextValue {
|
|
175
167
|
optionsProxy: ReturnType<typeof createTRPCOptionsProxy<AppRouter>>;
|
|
@@ -184,6 +176,7 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
184
176
|
const queryClient = useQueryClient();
|
|
185
177
|
const runtimeConfig = useRuntimeConfig();
|
|
186
178
|
const apiUrl = runtimeConfig.apis.TestApi;
|
|
179
|
+
const sigv4Client = useSigV4();
|
|
187
180
|
|
|
188
181
|
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
189
182
|
const client = createTRPCClient<AppRouter>({
|
|
@@ -192,9 +185,24 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
192
185
|
condition: (op) => op.type === 'subscription',
|
|
193
186
|
true: httpSubscriptionLink({
|
|
194
187
|
url: apiUrl,
|
|
188
|
+
EventSource: EventSourcePolyfill,
|
|
189
|
+
eventSourceOptions: async ({ op }) => {
|
|
190
|
+
const url =
|
|
191
|
+
\`\${apiUrl.replace(/\\/$/, '')}/\${op.path}\` +
|
|
192
|
+
(op.input !== undefined
|
|
193
|
+
? \`?input=\${encodeURIComponent(JSON.stringify(op.input))}\`
|
|
194
|
+
: '');
|
|
195
|
+
const signed = await sigv4Client.sign(url, { method: 'GET' });
|
|
196
|
+
const headers: Record<string, string> = {};
|
|
197
|
+
signed.headers.forEach((v, k) => {
|
|
198
|
+
headers[k] = v;
|
|
199
|
+
});
|
|
200
|
+
return { headers };
|
|
201
|
+
},
|
|
195
202
|
}),
|
|
196
203
|
false: httpLink({
|
|
197
204
|
url: apiUrl,
|
|
205
|
+
fetch: sigv4Client.fetch,
|
|
198
206
|
}),
|
|
199
207
|
}),
|
|
200
208
|
],
|
|
@@ -206,7 +214,7 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
206
214
|
});
|
|
207
215
|
|
|
208
216
|
return { optionsProxy, client };
|
|
209
|
-
}, [apiUrl, queryClient]);
|
|
217
|
+
}, [apiUrl, queryClient, sigv4Client]);
|
|
210
218
|
|
|
211
219
|
return (
|
|
212
220
|
<TestApiTRPCContext.Provider value={container}>
|
|
@@ -249,6 +257,8 @@ export const TestApiClientProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
|
249
257
|
const container = useMemo<TestApiTRPCContextValue>(() => {
|
|
250
258
|
const linkOptions: HTTPLinkOptions<any> = {
|
|
251
259
|
url: apiUrl,
|
|
260
|
+
// TODO: Add headers required by your custom authorizer
|
|
261
|
+
headers: {},
|
|
252
262
|
};
|
|
253
263
|
|
|
254
264
|
const client = createTRPCClient<AppRouter>({
|