-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ddb overrides and flow refactor
* feat: ddb overrides * feat: add migration logic * fix: remove older files post migration * fix: address PR comments * fix: remove inquirer and use amplify prompts instead Co-authored-by: Ghosh <kaustavg@3c22fb229ff6.ant.amazon.com>
- Loading branch information
1 parent
1b2cd07
commit 89b4f0a
Showing
33 changed files
with
2,072 additions
and
1,003 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
17 changes: 17 additions & 0 deletions
17
packages/amplify-category-storage/resources/genInputSchema.ts
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 @@ | ||
import { TypeDef, CLIInputSchemaGenerator } from 'amplify-cli-core'; | ||
|
||
//ResourceProvider TypeDefs | ||
const DDBStorageTypeDef: TypeDef = { | ||
typeName: 'DynamoDBCLIInputs', | ||
service: 'DynamoDB', | ||
}; | ||
const S3StorageTypeDef: TypeDef = { | ||
typeName: 'S3UserInputs', | ||
service: 'S3', | ||
}; | ||
|
||
// Defines the type names and the paths to the TS files that define them | ||
const storageCategoryTypeDefs: TypeDef[] = [DDBStorageTypeDef]; | ||
|
||
const schemaGenerator = new CLIInputSchemaGenerator(storageCategoryTypeDefs); | ||
schemaGenerator.generateJSONSchemas(); //convert CLI input data into json schemas. |
7 changes: 7 additions & 0 deletions
7
packages/amplify-category-storage/resources/overrides-resource/DynamoDB/override.ts
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,7 @@ | ||
/* Add Amplify Helper dependencies */ | ||
|
||
/* TODO: Need to change props to Root-Stack specific props when props are ready */ | ||
export function overrideProps(props: any) { | ||
/* TODO: Add snippet of how to override in comments */ | ||
return props; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/amplify-category-storage/resources/overrides-resource/DynamoDB/package.json
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,18 @@ | ||
{ | ||
"name": "overrides-for-root-stack", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@types/fs-extra": "^9.0.11", | ||
"fs-extra": "^9.1.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.2.4" | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
packages/amplify-category-storage/resources/overrides-resource/DynamoDB/tsconfig.json
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "build" | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...ges/amplify-category-storage/resources/overrides-resource/DynamoDB/tsconfig.resource.json
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "./", | ||
"rootDir": "../" | ||
}, | ||
"include": ["../**/*"] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/amplify-category-storage/resources/overrides-resource/S3/override.ts
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,6 @@ | ||
/* Add Amplify Helper dependencies */ | ||
|
||
/* TODO: Need to change props to Root-Stack specific props when props are ready */ | ||
export function overrideProps(props: any): void { | ||
/* TODO: Add snippet of how to override in comments */ | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/amplify-category-storage/resources/overrides-resource/S3/package.json
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,18 @@ | ||
{ | ||
"name": "overrides-for-root-stack", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@types/fs-extra": "^9.0.11", | ||
"fs-extra": "^9.1.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.2.4" | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
packages/amplify-category-storage/resources/overrides-resource/S3/tsconfig.json
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "build" | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
packages/amplify-category-storage/resources/overrides-resource/S3/tsconfig.resource.json
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "./", | ||
"rootDir": "../" | ||
}, | ||
"include": ["../**/*"] | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/amplify-category-storage/resources/schemas/DynamoDB/DynamoDBCLIInputs.schema.json
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,64 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"resourceName": { | ||
"type": "string" | ||
}, | ||
"tableName": { | ||
"type": "string" | ||
}, | ||
"partitionKey": { | ||
"$ref": "#/definitions/DynamoDBCLIInputsKeyType" | ||
}, | ||
"sortKey": { | ||
"$ref": "#/definitions/DynamoDBCLIInputsKeyType" | ||
}, | ||
"gsi": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/DynamoDBCLIInputsGSIType" | ||
} | ||
}, | ||
"triggerFunctions": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"required": ["partitionKey", "resourceName", "tableName"], | ||
"definitions": { | ||
"DynamoDBCLIInputsKeyType": { | ||
"type": "object", | ||
"properties": { | ||
"fieldName": { | ||
"type": "string" | ||
}, | ||
"fieldType": { | ||
"$ref": "#/definitions/FieldType" | ||
} | ||
}, | ||
"required": ["fieldName", "fieldType"] | ||
}, | ||
"FieldType": { | ||
"enum": ["binary", "boolean", "list", "map", "null", "number", "string"], | ||
"type": "string" | ||
}, | ||
"DynamoDBCLIInputsGSIType": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"partitionKey": { | ||
"$ref": "#/definitions/DynamoDBCLIInputsKeyType" | ||
}, | ||
"sortKey": { | ||
"$ref": "#/definitions/DynamoDBCLIInputsKeyType" | ||
} | ||
}, | ||
"required": ["name", "partitionKey"] | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/amplify-category-storage/resources/schemas/S3/S3UserInputs.schema.json
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,50 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"resourceName": { | ||
"type": "string" | ||
}, | ||
"bucketName": { | ||
"type": "string" | ||
}, | ||
"storageAccess": { | ||
"$ref": "#/definitions/S3AccessType" | ||
}, | ||
"selectedGuestPermissions": { | ||
"type": "array", | ||
"items": { | ||
"enum": ["DELETE_OBJECT", "GET_OBJECT", "LIST_BUCKET", "PUT_OBJECT"], | ||
"type": "string" | ||
} | ||
}, | ||
"selectedAuthenticatedPermissions": { | ||
"type": "array", | ||
"items": { | ||
"enum": ["DELETE_OBJECT", "GET_OBJECT", "LIST_BUCKET", "PUT_OBJECT"], | ||
"type": "string" | ||
} | ||
}, | ||
"isTriggerEnabled": { | ||
"type": "boolean" | ||
}, | ||
"triggerFunctionName": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"bucketName", | ||
"isTriggerEnabled", | ||
"resourceName", | ||
"selectedAuthenticatedPermissions", | ||
"selectedGuestPermissions", | ||
"storageAccess", | ||
"triggerFunctionName" | ||
], | ||
"definitions": { | ||
"S3AccessType": { | ||
"enum": ["auth", "authAndGuest"], | ||
"type": "string" | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/amplify-category-storage/src/commands/storage/override.ts
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,83 @@ | ||
/* | ||
entry code for amplify override root | ||
*/ | ||
|
||
import { generateOverrideSkeleton, $TSContext, FeatureFlags, stateManager, pathManager } from 'amplify-cli-core'; | ||
import { printer } from 'amplify-prompts'; | ||
import * as fs from 'fs-extra'; | ||
import inquirer from 'inquirer'; | ||
import { DynamoDBInputState } from '../../provider-utils/awscloudformation/service-walkthroughs/dynamoDB-input-state'; | ||
import { DDBStackTransform } from '../../provider-utils/awscloudformation/cdk-stack-builder/ddb-stack-transform'; | ||
import * as path from 'path'; | ||
import { categoryName } from '../../constants'; | ||
|
||
export const name = 'override'; | ||
|
||
export const run = async (context: $TSContext) => { | ||
if (FeatureFlags.getBoolean('overrides.project')) { | ||
const { amplify } = context; | ||
const amplifyMeta = stateManager.getMeta(); | ||
|
||
const storageResources: string[] = []; | ||
|
||
Object.keys(amplifyMeta[categoryName]).forEach(resourceName => { | ||
storageResources.push(resourceName); | ||
}); | ||
|
||
if (storageResources.length === 0) { | ||
const errMessage = 'No resources to override. You need to add a resource.'; | ||
printer.error(errMessage); | ||
return; | ||
} | ||
|
||
let selectedResourceName: string = storageResources[0]; | ||
|
||
if (storageResources.length > 1) { | ||
const resourceAnswer = await inquirer.prompt({ | ||
type: 'list', | ||
name: 'resource', | ||
message: 'Which resource would you like to add overrides for?', | ||
choices: storageResources, | ||
}); | ||
selectedResourceName = resourceAnswer.resource; | ||
} | ||
|
||
const destPath = pathManager.getResourceDirectoryPath(undefined, categoryName, selectedResourceName); | ||
fs.ensureDirSync(destPath); | ||
|
||
const srcPath = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'..', | ||
'resources', | ||
'overrides-resource', | ||
amplifyMeta[categoryName][selectedResourceName].service, | ||
); | ||
|
||
// Make sure to migrate first | ||
if (amplifyMeta[categoryName][selectedResourceName].service === 'DynamoDB') { | ||
const resourceInputState = new DynamoDBInputState(selectedResourceName); | ||
if (!resourceInputState.cliInputFileExists()) { | ||
if (await amplify.confirmPrompt('File migration required to continue. Do you want to continue?', true)) { | ||
resourceInputState.migrate(); | ||
const stackGenerator = new DDBStackTransform(selectedResourceName); | ||
stackGenerator.transform(); | ||
} else { | ||
return; | ||
} | ||
} | ||
} else if (amplifyMeta[categoryName][selectedResourceName].service === 'S3') { | ||
// S3 migration logic goes in here | ||
} | ||
|
||
await generateOverrideSkeleton(context, srcPath, destPath); | ||
} else { | ||
printer.info('Storage overrides is currently not turned on. In amplify/cli.json file please include the following:'); | ||
printer.info(`{ | ||
override: { | ||
storage: true | ||
} | ||
}`); | ||
} | ||
}; |
Oops, something went wrong.