-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tommypraeger/master
interactions category
- Loading branch information
Showing
24 changed files
with
2,114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"no-param-reassign": "off", | ||
"no-return-await" : "off", | ||
"no-continue": "off", | ||
"no-await-in-loop": "off", | ||
"no-use-before-define": "off", | ||
"no-console": "off", | ||
"global-require": "off", | ||
"import/no-dynamic-require": "off", | ||
"consistent-return": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Amplify CLI Analytics Plugin | ||
|
||
## Commands Summary | ||
|
||
The current set of commands supported by the Amplify Interactions Category Plugin | ||
|
||
| Command | Description | | ||
| --- | --- | | ||
| amplify interactions add | Takes you through a CLI flow to add an interactions resource to your backend | | ||
| amplify interactions update | Takes you through steps in the CLI to update an interactions resource. | | ||
| amplify interactions push | Provisions only interactions cloud resources with the latest local developments | | ||
| amplify interactions remove | Removes interactions resource from your local backend which would be removed from the cloud on the next push command | |
31 changes: 31 additions & 0 deletions
31
packages/amplify-category-interactions/commands/interactions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const featureName = 'interactions'; | ||
|
||
module.exports = { | ||
name: featureName, | ||
run: async (context) => { | ||
const header = `amplify ${featureName} <subcommand>`; | ||
|
||
const commands = [ | ||
{ | ||
name: 'add', | ||
description: `Takes you through a CLI flow to add an ${featureName} resource to your local backend`, | ||
}, | ||
{ | ||
name: 'update', | ||
description: `Takes you through a CLI flow to update an ${featureName} resource`, | ||
}, | ||
{ | ||
name: 'push', | ||
description: `Provisions only ${featureName} cloud resources with the latest local developments`, | ||
}, | ||
{ | ||
name: 'remove', | ||
description: `Removes ${featureName} resource from your local backend which would be removed from the cloud on the next push command`, | ||
}, | ||
]; | ||
|
||
context.amplify.showHelp(header, commands); | ||
|
||
context.print.info(''); | ||
}, | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/amplify-category-interactions/commands/interactions/add.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const fs = require('fs'); | ||
|
||
const subcommand = 'add'; | ||
const category = 'interactions'; | ||
const servicesMetadata = JSON.parse(fs.readFileSync(`${__dirname}/../../provider-utils/supported-services.json`)); | ||
|
||
let options; | ||
|
||
module.exports = { | ||
name: subcommand, | ||
run: async (context) => { | ||
const { amplify } = context; | ||
|
||
return amplify.serviceSelectionPrompt(context, category, servicesMetadata) | ||
.then((result) => { | ||
options = { | ||
service: result.service, | ||
providerPlugin: result.providerName, | ||
build: true, | ||
}; | ||
const providerController = require(`../../provider-utils/${result.providerName}/index`); | ||
if (!providerController) { | ||
context.print.error('Provider not configured for this category'); | ||
return; | ||
} | ||
return providerController.addResource(context, category, result.service); | ||
}) | ||
.then(resourceName => amplify.updateamplifyMetaAfterResourceAdd( | ||
category, | ||
resourceName, | ||
options, | ||
)) | ||
.then(() => context.print.success('Successfully added resource')) | ||
.catch((err) => { | ||
context.print.info(err.stack); | ||
context.print.error('There was an error adding the interactions resource'); | ||
}); | ||
}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/amplify-category-interactions/commands/interactions/push.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const subcommand = 'push'; | ||
const category = 'interactions'; | ||
|
||
module.exports = { | ||
name: subcommand, | ||
run: async (context) => { | ||
const { amplify, parameters } = context; | ||
const resourceName = parameters.first; | ||
|
||
return amplify.pushResources(context, category, resourceName) | ||
.catch((err) => { | ||
context.print.info(err.stack); | ||
context.print.error('There was an error pushing the interactions resource'); | ||
}); | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
packages/amplify-category-interactions/commands/interactions/remove.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const subcommand = 'remove'; | ||
const category = 'interactions'; | ||
|
||
module.exports = { | ||
name: subcommand, | ||
run: async (context) => { | ||
const { amplify, parameters } = context; | ||
const resourceName = parameters.first; | ||
|
||
return amplify.removeResource(context, category, resourceName) | ||
.then(() => context.print.success('Successfully removed resource')) | ||
.catch((err) => { | ||
context.print.info(err.stack); | ||
context.print.error('There was an error removing the interactions resource'); | ||
}); | ||
}, | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/amplify-category-interactions/commands/interactions/update.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs'); | ||
|
||
const subcommand = 'update'; | ||
const category = 'interactions'; | ||
const servicesMetadata = JSON.parse(fs.readFileSync(`${__dirname}/../../provider-utils/supported-services.json`)); | ||
|
||
|
||
module.exports = { | ||
name: subcommand, | ||
alias: ['configure'], | ||
run: async (context) => { | ||
const { amplify } = context; | ||
|
||
return amplify.serviceSelectionPrompt(context, category, servicesMetadata) | ||
.then((result) => { | ||
const providerController = require(`../../provider-utils/${result.providerName}/index`); | ||
if (!providerController) { | ||
context.print.error('Provider not configured for this category'); | ||
return; | ||
} | ||
return providerController.updateResource(context, category, result.service); | ||
}) | ||
.then(() => context.print.success('Successfully updated resource')) | ||
.catch((err) => { | ||
context.print.info(err.stack); | ||
context.print.error('There was an error updating the interactions resource'); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "amplify-category-interactions", | ||
"version": "0.1.0", | ||
"description": "amplify-cli interactions plugin", | ||
"dependencies": { | ||
"eslint": "^4.19.1", | ||
"fs-extra": "^7.0.0", | ||
"inquirer": "^3.2.1", | ||
"uuid": "^3.3.2" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint-fix": "eslint . --fix" | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.12.0" | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...der-utils/awscloudformation/cloudformation-templates/lex-cloudformation-template.json.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Lex chatbot creation from Amplify CLI", | ||
"Parameters": { | ||
}, | ||
"Metadata": { | ||
"AWS::CloudFormation::Interface": { | ||
"ParameterGroups": [ | ||
{ | ||
"Label": { | ||
"default": "Creating lex chatbot" | ||
}, | ||
"Parameters": [ | ||
"inputs" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"Resources": { | ||
"LambdaFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"FunctionName": "<%= props.functionName %>", | ||
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }, | ||
"Runtime": "nodejs6.10", | ||
"Timeout": "300" | ||
} | ||
}, | ||
|
||
"LambdaExecutionRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"RoleName": "<%= props.roleName %>", | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com" | ||
] | ||
}, | ||
"Action": [ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
] | ||
}, | ||
"Policies": [ | ||
{ | ||
"PolicyName": "<%= props.cloudWatchPolicyName %>", | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": "arn:aws:logs:*:*:*" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"PolicyName": "<%= props.lexPolicyName %>", | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"lex:*" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"LambdaFunctionOutputs<%= props.shortId %>": { | ||
"Type": "Custom::LambdaCallout", | ||
"Properties": { | ||
"ServiceToken": { | ||
"Fn::GetAtt": [ | ||
"LambdaFunction", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"Region": { | ||
"Value": { | ||
"Ref": "AWS::Region" | ||
} | ||
}, | ||
"FunctionArn": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"LambdaFunction", | ||
"Arn" | ||
] | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ify-category-interactions/provider-utils/awscloudformation/default-values/lex-defaults.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const uuid = require('uuid'); | ||
|
||
const getAllDefaults = (project) => { | ||
const name = project.projectConfig.projectName.toLowerCase().replace('-', '_'); | ||
const [shortId] = uuid().split('-'); | ||
const region = project.amplifyMeta.providers.awscloudformation.Region; | ||
const defaults = { | ||
resourceName: `lex${shortId}`, | ||
botName: `${name}_bot`, | ||
sessionTimeout: 5, | ||
lexPolicyName: `lexPolicy${shortId}`, | ||
authPolicyName: `lex_amplify_${shortId}`, | ||
unauthPolicyName: `lex_amplify_${shortId}`, | ||
roleName: `lexLambdaRole${shortId}`, | ||
functionName: `${name}_cfnlambda_${shortId}`, | ||
cloudWatchPolicyName: `cloudWatchPolicy${shortId}`, | ||
region, | ||
}; | ||
return defaults; | ||
}; | ||
|
||
module.exports = { | ||
getAllDefaults, | ||
}; |
53 changes: 53 additions & 0 deletions
53
...egory-interactions/provider-utils/awscloudformation/function-template-dir/cfn-response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Copyright 2015 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. | ||
This file is licensed to you under the AWS Customer Agreement (the "License"). | ||
You may not use this file except in compliance with the License. | ||
A copy of the License is located at http://aws.amazon.com/agreement/ . | ||
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. | ||
See the License for the specific language governing permissions and limitations under the License. */ | ||
|
||
exports.SUCCESS = 'SUCCESS'; | ||
exports.FAILED = 'FAILED'; | ||
|
||
exports.send = function (event, context, responseStatus, responseData, physicalResourceId, noEcho) { | ||
const responseBody = JSON.stringify({ | ||
Status: responseStatus, | ||
Reason: `See the details in CloudWatch Log Stream: ${context.logStreamName}`, | ||
PhysicalResourceId: physicalResourceId || context.logStreamName, | ||
StackId: event.StackId, | ||
RequestId: event.RequestId, | ||
LogicalResourceId: event.LogicalResourceId, | ||
NoEcho: noEcho || false, | ||
Data: responseData, | ||
}); | ||
|
||
console.log('Response body:\n', responseBody); | ||
|
||
const https = require('https'); | ||
const url = require('url'); | ||
|
||
const parsedUrl = url.parse(event.ResponseURL); | ||
const options = { | ||
hostname: parsedUrl.hostname, | ||
port: 443, | ||
path: parsedUrl.path, | ||
method: 'PUT', | ||
headers: { | ||
'content-type': '', | ||
'content-length': responseBody.length, | ||
}, | ||
}; | ||
|
||
const request = https.request(options, (response) => { | ||
console.log(`Status code: ${response.statusCode}`); | ||
console.log(`Status message: ${response.statusMessage}`); | ||
context.done(); | ||
}); | ||
|
||
request.on('error', (error) => { | ||
console.log(`send(..) failed executing https.request(..): ${error}`); | ||
context.done(); | ||
}); | ||
|
||
request.write(responseBody); | ||
request.end(); | ||
}; |
Oops, something went wrong.