in source/packages/services/installer/src/commands/modules/infrastructure/apigw.ts [32:179]
public async prompts(answers: Answers): Promise<Answers> {
answers = await inquirer.prompt(
[
// choose location where cloudformation snippets are stored
pathPrompt(
'Some of the modules chosen expose a REST API. Select the path to where the REST API CloudFormation snippets are stored (relative from aws-connected-device-framework repository) :',
'apigw.cloudFormationSnippetsPath',
answers.apigw?.cloudFormationSnippetsPath ??
path.join('source', 'infrastructure', 'cloudformation', 'snippets')
),
// choose the type of rest api auth
{
message: 'What kind of authentication do you want to apply?',
type: 'list',
name: 'apigw.type',
default: answers.apigw?.type || 'None',
choices: [
{ key: 'None', value: 'None' },
{ key: 'Private API Gateway', value: 'Private' },
{ key: 'Cognito', value: 'Cognito' },
{ key: 'LambdaRequest Authorizer', value: 'LambdaRequest' },
{ key: 'LambdaToken Authorizer', value: 'LambdaToken' },
{ key: 'API Key', value: 'ApiKey' },
{ key: 'IAM', value: 'IAM' },
],
pageSize: 10,
loop: false,
askAnswered: true,
validate(answer: string) {
if (answer?.length === 0) {
return 'You must choose an authentication method.';
}
return true;
},
},
// a CloudFormation snippet is required to manage the apigw config...
{
message:
'Enter the name of the CloudFormation snippet that configures the REST APIs:',
type: 'input',
name: 'apigw.cloudFormationTemplate',
default: (answers: Answers) => {
if (answers.apigw?.cloudFormationTemplate !== undefined)
return answers.apigw.cloudFormationTemplate;
let cloudformationTemplate = 'cfn-apiGateway-noAuth.yaml';
switch (answers.apigw?.type) {
case 'ApiKey':
cloudformationTemplate = 'cfn-apiGateway-apiKeyAuth.yaml';
break;
case 'Cognito':
cloudformationTemplate = 'cfn-apiGateway-cognitoAuth.yaml';
break;
case 'IAM':
cloudformationTemplate = 'cfn-apiGateway-iamAuth.yaml';
break;
case 'LambdaRequest':
cloudformationTemplate = 'cfn-apiGateway-lambdaRequestAuth.yaml';
break;
case 'LambdaToken':
cloudformationTemplate = 'cfn-apiGateway-lambdaTokenAuth.yaml';
break;
case 'None':
cloudformationTemplate = 'cfn-apiGateway-noAuth.yaml';
break;
case 'Private':
cloudformationTemplate = 'cfn-apiGateway-privateApi.yaml';
break;
}
return cloudformationTemplate;
},
askAnswered: true,
validate(answer: string) {
if (answer?.length === 0) {
return `You must enter the name of the CloudFormation snippet.`;
}
return true;
},
},
{
message: 'Enter the name of Cognito user pool arn:',
type: 'input',
name: 'apigw.cognitoUserPoolArn',
default: answers.apigw?.cognitoUserPoolArn,
askAnswered: true,
when(answers: Answers) {
return answers.apigw?.type === 'Cognito';
},
validate(answer: string) {
if (answer?.length === 0) {
return `You must enter the name of the Cognito user pool arn.`;
}
return true;
},
},
{
message: 'Enter the Lambda Authorizer Arn:',
type: 'input',
name: 'apigw.lambdaAuthorizerArn',
default: answers.apigw?.lambdaAuthorizerArn,
askAnswered: true,
when(answers: Answers) {
return (
answers.apigw?.type === 'LambdaRequest' ||
answers.apigw?.type === 'LambdaToken'
);
},
validate(answer: ApiAuthenticationType) {
if (answer?.length === 0) {
return `You must enter the name of the Lambda Authorizer arn.`;
}
return true;
},
},
// TODO: Use existing cognito? Or deploy a Cognito user pool specifically for CDF?
{
message: 'Configure Cross-Origin Resource Sharing (CORS)?',
type: 'confirm',
name: 'apigw.corsEnable',
default: answers.apigw?.corsEnable ?? false,
askAnswered: true,
},
{
message: 'Specify domain for CORS origin',
type: 'input',
name: 'apigw.corsOrigin',
default: answers.apigw?.corsOrigin ?? '*',
when(answers: Answers) {
return answers.apigw?.corsEnable ?? false;
},
askAnswered: true,
},
],
answers
);
if ((answers.apigw?.type ?? '') === 'None') {
// TODO potentially remove old ansers
}
includeOptionalModule('vpc', answers.modules, answers.apigw.type === 'Private');
return answers;
}