Skip to content

Commit d73a5bf

Browse files
authored
Merge pull request #38 from cookpad/nb/fix-keygen
Removed unused API Gateway and apiHandler lambda
2 parents a42e1d0 + a8834d0 commit d73a5bf

12 files changed

Lines changed: 62 additions & 811 deletions

File tree

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ FUNCTIONS= \
1212
$(CODE_DIR)/build/submitReport/bootstrap \
1313
$(CODE_DIR)/build/publishReport/bootstrap \
1414
$(CODE_DIR)/build/submitFinding/bootstrap \
15-
$(CODE_DIR)/build/apiHandler/bootstrap \
1615
$(CODE_DIR)/build/feedbackAttribute/bootstrap
1716

1817
GO_OPT=-ldflags="-s -w" -trimpath
@@ -39,9 +38,6 @@ $(CODE_DIR)/build/submitReport/bootstrap: $(CODE_DIR)/lambda/submitReport/*.go $
3938
$(CODE_DIR)/build/submitFinding/bootstrap: $(CODE_DIR)/lambda/submitFinding/*.go $(COMMON)
4039
mkdir -p $(dir $@)
4140
env GOARCH=amd64 GOOS=linux go build $(GO_OPT) -o $@ ./lambda/submitFinding
42-
$(CODE_DIR)/build/apiHandler/bootstrap: $(CODE_DIR)/lambda/apiHandler/*.go $(COMMON)
43-
mkdir -p $(dir $@)
44-
env GOARCH=amd64 GOOS=linux go build $(GO_OPT) -o $@ ./lambda/apiHandler
4541
$(CODE_DIR)/build/feedbackAttribute/bootstrap: $(CODE_DIR)/lambda/feedbackAttribute/*.go $(COMMON)
4642
mkdir -p $(dir $@)
4743
env GOARCH=amd64 GOOS=linux go build $(GO_OPT) -o $@ ./lambda/feedbackAttribute

cdk/deepalert-stack.ts

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as sqs from '@aws-cdk/aws-sqs';
66
import * as dynamodb from '@aws-cdk/aws-dynamodb';
77
import * as sfn from '@aws-cdk/aws-stepfunctions';
88
import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
9-
import * as apigateway from '@aws-cdk/aws-apigateway';
109
import {
1110
SqsEventSource,
1211
DynamoEventSource,
@@ -24,8 +23,6 @@ export interface Property extends cdk.StackProps {
2423
inspectDelay?: cdk.Duration;
2524
reviewDelay?: cdk.Duration;
2625

27-
enableAPI?: boolean;
28-
apiKeyPath?: string;
2926
sentryDsn?: string;
3027
sentryEnv?: string;
3128
logLevel?: string;
@@ -52,7 +49,6 @@ export class DeepAlertStack extends cdk.Stack {
5249
dummyReviewer: lambda.Function;
5350
submitReport: lambda.Function;
5451
publishReport: lambda.Function;
55-
apiHandler: lambda.Function;
5652

5753
// StepFunctions
5854
readonly inspectionMachine: sfn.StateMachine;
@@ -163,7 +159,7 @@ export class DeepAlertStack extends cdk.Stack {
163159
config.setToStack(f);
164160
};
165161

166-
// receptAlert and apiHandler is configured later because they requires StepFunctions
162+
// receptAlert is configured later because it requires StepFunctions
167163
// in environment variables.
168164
const lambdaConfigs: LambdaConfig[] = [
169165
{
@@ -235,51 +231,6 @@ export class DeepAlertStack extends cdk.Stack {
235231
setToStack: (f: lambda.Function) => { this.receptAlert = f; },
236232
})
237233

238-
if (props.enableAPI) {
239-
buildLambdaFunction({
240-
funcName: 'apiHandler',
241-
environment: envVarsWithSF,
242-
setToStack: (f: lambda.Function) => { this.apiHandler = f; },
243-
})
244-
245-
const api = new apigateway.LambdaRestApi(this, 'deepalertAPI', {
246-
handler: this.apiHandler,
247-
proxy: false,
248-
cloudWatchRole: false,
249-
endpointTypes: [apigateway.EndpointType.REGIONAL],
250-
policy: new iam.PolicyDocument({
251-
statements: [
252-
new iam.PolicyStatement({
253-
actions: ['execute-api:Invoke'],
254-
resources: ['execute-api:/*/*'],
255-
effect: iam.Effect.ALLOW,
256-
principals: [new iam.AnyPrincipal()],
257-
}),
258-
],
259-
}),
260-
});
261-
const key = api.addApiKey('APIKey', {
262-
value: getAPIKey(props.apiKeyPath),
263-
})
264-
const plan = api.addUsagePlan('UsagePlan', {})
265-
plan.addApiKey(key)
266-
plan.addApiStage({
267-
stage: api.deploymentStage,
268-
})
269-
270-
const apiOpt = { apiKeyRequired: true };
271-
const v1 = api.root.addResource('api').addResource('v1',);
272-
const alertAPI = v1.addResource('alert');
273-
alertAPI.addMethod('POST', undefined, apiOpt);
274-
alertAPI.addResource('{alert_id}').addResource('report').addMethod('GET', undefined, apiOpt);
275-
276-
const reportAPI = v1.addResource('report');
277-
const reportAPIwithID = reportAPI.addResource('{report_id}');
278-
reportAPIwithID.addMethod('GET', undefined, apiOpt);
279-
reportAPIwithID.addResource('alert').addMethod('GET', undefined, apiOpt);
280-
reportAPIwithID.addResource('attribute').addMethod('GET', undefined, apiOpt);
281-
reportAPIwithID.addResource('section').addMethod('GET', undefined, apiOpt);
282-
}
283234

284235
if (lambdaRole === undefined) {
285236
this.inspectionMachine.grantStartExecution(this.receptAlert);
@@ -296,11 +247,6 @@ export class DeepAlertStack extends cdk.Stack {
296247
this.cacheTable.grantReadWriteData(this.submitReport);
297248
this.cacheTable.grantReadWriteData(this.publishReport);
298249

299-
if (props.enableAPI) {
300-
this.inspectionMachine.grantStartExecution(this.apiHandler);
301-
this.reviewMachine.grantStartExecution(this.apiHandler);
302-
this.cacheTable.grantReadWriteData(this.apiHandler);
303-
}
304250
}
305251
}
306252
}
@@ -375,23 +321,3 @@ function buildReviewMachine(
375321
role: sfnRole,
376322
});
377323
}
378-
379-
function getAPIKey(apiKeyPath?: string): string {
380-
if (apiKeyPath === undefined) {
381-
apiKeyPath = path.join(process.cwd(), 'apikey.json');
382-
}
383-
384-
if (fs.existsSync(apiKeyPath)) {
385-
console.log('Read API key from: ', apiKeyPath);
386-
const buf = fs.readFileSync(apiKeyPath)
387-
const keyData = JSON.parse(buf.toString());
388-
return keyData['X-API-KEY'];
389-
} else {
390-
const literals = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
391-
const length = 32;
392-
const apiKey = Array.from(Array(length)).map(()=>literals[Math.floor(Math.random()*literals.length)]).join('');
393-
fs.writeFileSync(apiKeyPath, JSON.stringify({'X-API-KEY': apiKey}))
394-
console.log('Generated and wrote API key to: ', apiKeyPath);
395-
return apiKey;
396-
}
397-
}

go.mod

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,47 @@ toolchain go1.26.1
66

77
require (
88
github.com/Netflix/go-env v0.1.2
9+
github.com/aws/aws-cdk-go/awscdk v1.204.0-devpreview
10+
github.com/aws/aws-cdk-go/awscdk/v2 v2.250.0
911
github.com/aws/aws-lambda-go v1.53.0
1012
github.com/aws/aws-sdk-go v1.55.8
11-
github.com/awslabs/aws-lambda-go-api-proxy v0.16.2
12-
github.com/gin-gonic/gin v1.12.0
13+
github.com/aws/constructs-go/constructs/v10 v10.6.0
14+
github.com/aws/constructs-go/constructs/v3 v3.4.344
15+
github.com/aws/jsii-runtime-go v1.128.0
1316
github.com/google/uuid v1.6.0
1417
github.com/guregu/dynamo v1.23.0
1518
github.com/m-mizutani/golambda v1.1.3
1619
github.com/stretchr/testify v1.11.1
1720
)
1821

1922
require (
20-
github.com/bytedance/gopkg v0.1.3 // indirect
21-
github.com/bytedance/sonic v1.15.0 // indirect
22-
github.com/bytedance/sonic/loader v0.5.0 // indirect
23+
github.com/Masterminds/semver/v3 v3.4.0 // indirect
24+
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.273 // indirect
25+
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.1.1 // indirect
26+
github.com/cdklabs/cloud-assembly-schema-go/awscdkcloudassemblyschema/v53 v53.0.0 // indirect
2327
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
24-
github.com/cloudwego/base64x v0.1.6 // indirect
2528
github.com/davecgh/go-spew v1.1.1 // indirect
26-
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
29+
github.com/fatih/color v1.19.0 // indirect
2730
github.com/getsentry/sentry-go v0.43.0 // indirect
28-
github.com/gin-contrib/sse v1.1.0 // indirect
29-
github.com/go-playground/locales v0.14.1 // indirect
30-
github.com/go-playground/universal-translator v0.18.1 // indirect
31-
github.com/go-playground/validator/v10 v10.30.1 // indirect
32-
github.com/goccy/go-json v0.10.6 // indirect
33-
github.com/goccy/go-yaml v1.19.2 // indirect
31+
github.com/google/go-cmp v0.7.0 // indirect
3432
github.com/jmespath/go-jmespath v0.4.0 // indirect
35-
github.com/json-iterator/go v1.1.12 // indirect
36-
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
37-
github.com/leodido/go-urn v1.4.0 // indirect
33+
github.com/kr/pretty v0.3.1 // indirect
3834
github.com/m-mizutani/goerr v1.0.0 // indirect
3935
github.com/mattn/go-colorable v0.1.14 // indirect
4036
github.com/mattn/go-isatty v0.0.20 // indirect
41-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
42-
github.com/modern-go/reflect2 v1.0.2 // indirect
43-
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
4437
github.com/pmezard/go-difflib v1.0.0 // indirect
45-
github.com/quic-go/qpack v0.6.0 // indirect
46-
github.com/quic-go/quic-go v0.59.0 // indirect
38+
github.com/rogpeppe/go-internal v1.10.0 // indirect
4739
github.com/rs/zerolog v1.34.0 // indirect
48-
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
49-
github.com/ugorji/go/codec v1.3.1 // indirect
50-
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
51-
golang.org/x/arch v0.25.0 // indirect
52-
golang.org/x/crypto v0.49.0 // indirect
53-
golang.org/x/net v0.52.0 // indirect
40+
github.com/yuin/goldmark v1.7.16 // indirect
41+
golang.org/x/lint v0.0.0-20241112194109-818c5a804067 // indirect
42+
golang.org/x/mod v0.34.0 // indirect
5443
golang.org/x/sync v0.20.0 // indirect
5544
golang.org/x/sys v0.42.0 // indirect
45+
golang.org/x/telemetry v0.0.0-20260311193753-579e4da9a98c // indirect
5646
golang.org/x/text v0.35.0 // indirect
57-
google.golang.org/protobuf v1.36.11 // indirect
47+
golang.org/x/tools v0.43.0 // indirect
48+
golang.org/x/tools/cmd/godoc v0.1.0-deprecated // indirect
49+
golang.org/x/tools/godoc v0.1.0-deprecated // indirect
5850
gopkg.in/yaml.v2 v2.4.0 // indirect
5951
gopkg.in/yaml.v3 v3.0.1 // indirect
6052
)

0 commit comments

Comments
 (0)