From 92780a469faf6a7522468dc2f66e4d951f65222e Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Mon, 28 Mar 2022 10:48:43 +0100 Subject: [PATCH] feat: add support for snippets and toolbar button for action command Signed-off-by: Owen Rumney --- CHANGELOG.md | 5 ++++ README.md | 6 +++++ package.json | 21 ++++++++++++--- resources/dark/help.svg | 3 +++ resources/light/help.svg | 10 +++++++ src/snippets/custom_checks.json | 48 +++++++++++++++++++++++++++++++++ src/tfsec_wrapper.ts | 3 ++- 7 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 resources/dark/help.svg create mode 100644 resources/light/help.svg create mode 100644 src/snippets/custom_checks.json diff --git a/CHANGELOG.md b/CHANGELOG.md index b903572..fd2026c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the "tfsec" extension will be documented in this file. +### 1.8.0 +- Add snippets support + - using `tfsec-check-file` in a yaml file to create custom check + - using `tfsec-custom-check` in the existing check file to add a new custom check +- Add icon on toolbar to get the version ### 1.7.5 - Update the severity icons inline with Aqua colours diff --git a/README.md b/README.md index 9663151..741b029 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ Ignore codes will be automatically resolved and the description of the error wil ## Release Notes +### 1.8.0 +- Add snippets support + - using `tfsec-check-file` in a yaml file to create custom check + - using `tfsec-custom-check` in the existing check file to add a new custom check +- Add icon on toolbar to get the version + ### 1.7.5 - Update the severity icons inline with Aqua colours diff --git a/package.json b/package.json index 55aaba6..28f81ea 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "tfsec", "publisher": "tfsec", "description": "tfsec integration for Visual Studio Code", - "version": "1.7.5", + "version": "1.8.0", "engines": { "vscode": "^1.54.0" }, @@ -101,7 +101,11 @@ }, { "command": "tfsec.version", - "title": "tfsec: Get the current version of tfsec" + "title": "tfsec: Get the current version of tfsec", + "icon": { + "light": "resources/light/help.svg", + "dark": "resources/dark/help.svg" + } } ], "viewsContainers": { @@ -156,6 +160,11 @@ "command": "tfsec.updatebinary", "when": "view == tfsec.issueview", "group": "navigation@2" + }, + { + "command": "tfsec.version", + "when": "view == tfsec.issueview", + "group": "navigation@2" } ], "view/item/context": [ @@ -172,7 +181,13 @@ "when": "view == tfsec.issueview && viewItem == TFSEC_SEVERITY" } ] - } + }, + "snippets": [ + { + "language": "yaml", + "path": "./src/snippets/custom_checks.json" + } + ] }, "scripts": { "vscode:prepublish": "npm run esbuild-base -- --minify", diff --git a/resources/dark/help.svg b/resources/dark/help.svg new file mode 100644 index 0000000..a0a00f0 --- /dev/null +++ b/resources/dark/help.svg @@ -0,0 +1,3 @@ + + + diff --git a/resources/light/help.svg b/resources/light/help.svg new file mode 100644 index 0000000..a6977ef --- /dev/null +++ b/resources/light/help.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/snippets/custom_checks.json b/src/snippets/custom_checks.json new file mode 100644 index 0000000..5d3a4ce --- /dev/null +++ b/src/snippets/custom_checks.json @@ -0,0 +1,48 @@ +{ + "custom_checks_yaml": { + "prefix": [ + "tfsec-check-file" + ], + "body": [ + "---", + "checks:", + " - code: ${1}", + " description: ${2}", + " requiredTypes:", + " - ${3:resource}", + " requiredLabels:", + " - ${4}", + " severity: ${5:MEDIUM}", + " matchSpec:", + " name: ${6}", + " action: ${7}", + " value: ${8}", + " errorMessage: ${9}", + " relatedLinks:", + " - ${10}" + ], + "description": "Add the body for custom checks file." + }, + "custom_check": { + "prefix": [ + "tfsec-custom-check" + ], + "body": [ + " - code: ${1}", + " description: ${2}", + " requiredTypes:", + " - ${3:resource}", + " requiredLabels:", + " - ${4}", + " severity: ${5:MEDIUM}", + " matchSpec:", + " name: ${6}", + " action: ${7}", + " value: ${8}", + " errorMessage: ${9}", + " relatedLinks:", + " - ${10}" + ], + "description": "Add the body for an individual custom check." + } +} \ No newline at end of file diff --git a/src/tfsec_wrapper.ts b/src/tfsec_wrapper.ts index e35e2a4..65f5136 100644 --- a/src/tfsec_wrapper.ts +++ b/src/tfsec_wrapper.ts @@ -34,7 +34,7 @@ export class TfsecWrapper { return; } - var files = readdirSync(this.resultsStoragePath).filter(fn => fn.endsWith('_results.json') || fn.endsWith('_results.json.json') ); + var files = readdirSync(this.resultsStoragePath).filter(fn => fn.endsWith('_results.json') || fn.endsWith('_results.json.json')); files.forEach(file => { let deletePath = path.join(this.resultsStoragePath, file); unlinkSync(deletePath); @@ -59,6 +59,7 @@ export class TfsecWrapper { execution.on('exit', function (code) { if (code !== 0) { vscode.window.showErrorMessage("tfsec failed to run"); + outputChannel.show(); return; }; vscode.window.showInformationMessage('tfsec ran successfully, updating results');