Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function selectDatabase(context, inputs, clusterArn, secretArn, AWS) {
// Database Name Question
const DataApi = new AWS.RDSDataService();
const params = new DataApiParams();
params.secretArn = secretArn;
params.resourceArn = clusterArn;
params.sql = 'SHOW databases';
spinner.start('Fetching Aurora Serverless cluster...');
const dataApiResult = await DataApi.executeStatement(params).promise();
// eslint-disable-next-line prefer-destructuring
const records = dataApiResult.records;
const databaseList = [];
for (let i = 0; i < records.length; i += 1) {
const recordValue = records[i][0].stringValue;
// ignore the three meta tables that the cluster creates
if (!['information_schema', 'performance_schema', 'mysql'].includes(recordValue)) {
databaseList.push(recordValue);
teamProviderInfo[currEnv][categories][category][resourceName][rdsDatabaseName] = answers.databaseName;
fs.writeFileSync(teamProviderInfoFilePath, JSON.stringify(teamProviderInfo, null, 4));
const backendConfigFilePath = amplify.pathManager.getBackendConfigFilePath();
const backendConfig = context.amplify.readJsonFile(backendConfigFilePath);
backendConfig[category][resourceName][rdsInit] = true;
fs.writeFileSync(backendConfigFilePath, JSON.stringify(backendConfig, null, 4));
/**
* Load the MySqlRelationalDBReader
*/
// eslint-disable-next-line max-len
const dbReader = new AuroraServerlessMySQLDatabaseReader(
answers.region,
answers.secretStoreArn,
answers.dbClusterArn,
answers.databaseName,
AWS
);
/**
* Instantiate a new Relational Schema Transformer and perform
* the db instrospection to get the GraphQL Schema and Template Context
*/
const relationalSchemaTransformer = new RelationalDBSchemaTransformer(dbReader, answers.databaseName);
return relationalSchemaTransformer.introspectDatabaseSchema();
})
.then(graphqlSchemaContext => {
* Load the MySqlRelationalDBReader
*/
// eslint-disable-next-line max-len
const dbReader = new AuroraServerlessMySQLDatabaseReader(
answers.region,
answers.secretStoreArn,
answers.dbClusterArn,
answers.databaseName,
AWS
);
/**
* Instantiate a new Relational Schema Transformer and perform
* the db instrospection to get the GraphQL Schema and Template Context
*/
const relationalSchemaTransformer = new RelationalDBSchemaTransformer(dbReader, answers.databaseName);
return relationalSchemaTransformer.introspectDatabaseSchema();
})
.then(graphqlSchemaContext => {
fs.ensureFileSync(graphqlSchemaFilePath);
const graphqlSchemaRaw = fs.readFileSync(graphqlSchemaFilePath, 'utf8');
const currGraphQLSchemaDoc = graphql.parse(graphqlSchemaRaw);
const rdsGraphQLSchemaDoc = graphqlSchemaContext.schemaDoc;
const concatGraphQLSchemaDoc = mergeTypes([currGraphQLSchemaDoc, rdsGraphQLSchemaDoc], { all: true });
fs.writeFileSync(graphqlSchemaFilePath, concatGraphQLSchemaDoc, 'utf8');
const resolversDir = `${projectBackendDirPath}/${category}/${resourceName}/resolvers`;
/**
* Instantiate a new Relational Template Generator and create
* the template and relational resolvers
*/
const templateGenerator = new RelationalDBTemplateGenerator(graphqlSchemaContext);
context[rdsResourceName] = resourceName;
context[rdsDatasource] = datasource;
let template = templateGenerator.createTemplate(context);
template = templateGenerator.addRelationalResolvers(template, resolversDir);
const cfn = templateGenerator.printCloudformationTemplate(template);
/**
* Add the generated the CFN to the appropriate nested stacks directory
*/
const stacksDir = `${projectBackendDirPath}/${category}/${resourceName}/stacks`;
const writeToPath = `${stacksDir}/${resourceName}-${databaseName}-rds.json`;
fs.writeFileSync(writeToPath, cfn, 'utf8');
return datasource;
})
.then(datasourceName => {