@@ -6,7 +6,6 @@ import * as sqs from '@aws-cdk/aws-sqs';
66import * as dynamodb from '@aws-cdk/aws-dynamodb' ;
77import * as sfn from '@aws-cdk/aws-stepfunctions' ;
88import * as tasks from '@aws-cdk/aws-stepfunctions-tasks' ;
9- import * as apigateway from '@aws-cdk/aws-apigateway' ;
109import {
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- }
0 commit comments