diff --git a/src/commands/import/import.js b/src/commands/import/import.js index 0d3f984..c151b6a 100644 --- a/src/commands/import/import.js +++ b/src/commands/import/import.js @@ -7,6 +7,7 @@ const baseFile = require("../../shared/baseFile.json"); const templateAnatomy = require("../../shared/templateAnatomy.json"); const lambdaHandlerParser = require("../../shared/lambdaHandlerParser"); const fs = require("fs"); +const path = require("path"); const _ = require("lodash"); const runtimes = require("../../shared/runtimes.json"); const templateType = "SAM"; // to allow for more template frameworks @@ -28,7 +29,33 @@ async function run(cmd) { const patterns = await githubUtil.getPatterns(cmd.sourceFilter); + const files = fs.readdirSync(path.join(__dirname, "/simple-resources")); + + patterns.unshift(new Separator("Community patterns")); + for (const file of files.filter((p) => p.endsWith(".yaml"))) { + patterns.unshift({ + name: file.replace(".yaml", ""), + value: { + basic: true, + name: file.replace(".yaml", "") + } + }) + } + patterns.unshift(new Separator("Simple resources")); + + console.log(JSON.stringify(patterns, null, 2)); + const pattern = await inputUtil.autocomplete("Select pattern", patterns); + + if (pattern.basic) { + const snippet = fs.readFileSync( + path.join(__dirname, `/simple-resources/${pattern.name}.yaml`) + ); + const snippetJson = { Resources: parser.parse("import", snippet) }; + mergeWithExistingResource(ownTemplate, [], snippetJson); + return; + } + let templateString; for (const fileName of pattern.setting.fileNames) { try { @@ -159,7 +186,7 @@ async function handleStepFunctionsActions(template, block, name, pattern, aslFor template[block.section][name].Properties.DefinitionUri = definitionUri; } } - } + } } async function importASL( diff --git a/src/commands/local/lib/connect.js b/src/commands/local/lib/connect.js index 08bb8dd..dd35e54 100644 --- a/src/commands/local/lib/connect.js +++ b/src/commands/local/lib/connect.js @@ -69,7 +69,7 @@ if (!fs.existsSync(".lambda-debug") || !certData) { const createKeysAndCertificate = async () => { const homeDir = os.homedir(); - const certPath = path.join(homeDir, '.lambda-debug', `certificate-${accountId}.json`); + const certPath = path.join(homeDir, '.lambda-debug', `certificate-${accountId}-${targetConfig.region}.json`); let response; if (fs.existsSync(certPath)) { response = JSON.parse(fs.readFileSync(certPath)); @@ -87,7 +87,7 @@ if (!fs.existsSync(".lambda-debug") || !certData) { certData = await createKeysAndCertificate(); const getIotEndpoint = async () => { - const cachePath = path.join(os.homedir(), ".lambda-debug", `endpoint-${accountId}.txt`); + const cachePath = path.join(os.homedir(), ".lambda-debug", `endpoint-${accountId}-${targetConfig.region}.txt`); if (fs.existsSync(cachePath)) { return fs.readFileSync(cachePath).toString(); q } @@ -134,6 +134,7 @@ if (!fs.existsSync(".lambda-debug") || !certData) { } }; const attachPolicy = async () => { + console.log("Attaching policy", certData); const attachPolicyCommand = new AttachPolicyCommand({ policyName: policyName, target: certData.certificateArn diff --git a/src/commands/powertools/index.js b/src/commands/powertools/index.js index afffee4..b735cdb 100644 --- a/src/commands/powertools/index.js +++ b/src/commands/powertools/index.js @@ -1,6 +1,5 @@ const program = require("commander"); const powertools = require("./powertools"); -const runtimeFinder = require('../../shared/runtime-env-finder'); program .command("powertools") .alias("pt")