├── using-vim-tfsec.gif ├── README.md ├── doc └── vim-tfsec.txt ├── LICENSE └── plugin └── vim-tfsec.vim /using-vim-tfsec.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aquasecurity/vim-tfsec/HEAD/using-vim-tfsec.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-tfsec 2 | 3 | ## What is it? 4 | 5 | Vim plugin for tfsec to install and run tfsec. 6 | 7 | ## Install 8 | 9 | 1. add the plugin to our list of plugins 10 | 11 | ``` 12 | Plug 'aquasecurity/vim-tfsec' 13 | ``` 14 | 15 | 2. restart vim and run `:PlugInstall` to install 16 | 17 | 18 | ## Usage 19 | 20 | If you don't have `tfsec` already install then you can run `:TfsecInstall` to get the latest version. 21 | 22 | If you already hav it, you can run `TfsecUpdate` to get the latest version. 23 | 24 | Run `:Tfsec` to get a list of the current tfsec issues in your current directory. The issues will be added to the QuickFix list. 25 | 26 | 27 | ## Example usage 28 | 29 | ![Usage](using-vim-tfsec.gif) 30 | -------------------------------------------------------------------------------- /doc/vim-tfsec.txt: -------------------------------------------------------------------------------- 1 | *vim-tfsec.txt* 2 | *vim-tfsec* 3 | 4 | ============================================================================== 5 | CONTENTS *vim-tfsec-contents* 6 | 1. Commands.............................................|vim-tfsec-commands| 7 | 8 | ============================================================================== 9 | COMMANDS *vim-tfsec-commands* 10 | 11 | :Tfsec *:Tfsec* 12 | Run tfsec against the current directory and populate the QuickFix list 13 | 14 | :TfsecInstall *:TfsecInstall* 15 | Install the latest version of tfsec to %GOPATH/bin/tfsec 16 | 17 | :TfsecUpdate *:TfsecUpdate* 18 | Updates tfsec to the latest version, requires tfsec to be on the path 19 | 20 | 21 | vim:tw=78:ts=8:ft=help:norl: 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 tfsec 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /plugin/vim-tfsec.vim: -------------------------------------------------------------------------------- 1 | "" 2 | " @usage {} 3 | " Run tfsec against the current directory and populate the QuickFix list 4 | command! Tfsec call s:tfsec() 5 | 6 | "" 7 | " @usage {} 8 | " Install the latest version of tfsec to %GOPATH/bin/tfsec 9 | command! TfsecInstall call s:tfsecInstall() 10 | 11 | "" 12 | " @usage {} 13 | " Updates tfsec to the latest version, requires tfsec to be on the path 14 | command! TfsecUpdate call s:tfsecUpdate() 15 | 16 | 17 | " tfsec runs tfsec and prints adds the results to the quick fix buffer 18 | function! s:tfsec() abort 19 | try 20 | " capture the current error format 21 | let errorformat = &g:errorformat 22 | 23 | " set the error format for use with tfsec 24 | let &g:errorformat = '%f\,%l\,%m' 25 | 26 | " get the latest tfsec comments and open the quick fix window with them 27 | cgetexpr system('tfsec --format csv --force-all-dirs --exclude-downloaded-modules 2>/dev/null | grep -v ''file,start_line,'' | awk -F, ''{print $1","$2",["$5"] " $6}'' | sort ') | cw 28 | call setqflist([], 'a', {'title' : ':Tfsec'}) 29 | finally 30 | " restore the errorformat value 31 | let &g:errorformat = errorformat 32 | endtry 33 | endfunction 34 | 35 | " tfsecInstall runs the go install command to get the latest version of tfsec 36 | function! s:tfsecInstall() abort 37 | try 38 | echom "Downloading the latest version of tfsec" 39 | let installResult = system('go install github.com/aquasecurity/tfsec/cmd/tfsec@latest') 40 | if v:shell_error != 0 41 | echom installResult 42 | else 43 | echom "tfsec downloaded successfully" 44 | endif 45 | endtry 46 | endfunction 47 | 48 | " tfsecUpdate will update existing tfsec 49 | function! s:tfsecUpdate() abort 50 | try 51 | echom "Updating to the latest version of tfsec" 52 | echom system('tfsec --update') 53 | endtry 54 | endfunction 55 | --------------------------------------------------------------------------------