├── .github └── example.gif ├── LICENSE ├── README.md ├── csv.tpl ├── doc ├── tags └── vim-trivy.txt └── plugin └── vim-trivy.vim /.github/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aquasecurity/vim-trivy/3b97bfcc885691b75b5124bfedabc9f81bf7c5c4/.github/example.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Aqua Security 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-trivy 2 | 3 | ## What is it? 4 | 5 | Vim plugin for Trivy to install and run Trivy. 6 | 7 | ## Install 8 | 9 | 1. add the plugin to our list of plugins 10 | 11 | ``` 12 | Plug 'aquasecurity/vim-trivy' 13 | ``` 14 | 15 | 2. restart vim and run `:PlugInstall` to install 16 | 17 | 18 | ## Usage 19 | 20 | If you don't have `Trivy` already install then you can run `:TrivyInstall` to get the latest version. 21 | 22 | Run `:Trivy` to get a list of the current Trivy issues in your current directory. The issues will be added to the QuickFix list. 23 | 24 | 25 | ## Example usage 26 | 27 | ![Example](.github/example.gif) 28 | 29 | -------------------------------------------------------------------------------- /csv.tpl: -------------------------------------------------------------------------------- 1 | {{ range . }} 2 | {{ $target := .Target }} 3 | {{- if and (eq (len .Vulnerabilities) 0) (eq (len .Misconfigurations) 0) }}{{- else }} 4 | {{- range .Vulnerabilities }}{{ $target }},1,[{{ .Severity }}] {{ .VulnerabilityID }} - {{ .Title }} 5 | {{ end }} 6 | {{- range .Misconfigurations }}{{ $target }},{{ if not .CauseMetadata }}1{{ else if .CauseMetadata.StartLine }}{{ .CauseMetadata.StartLine }}{{ else }}1{{ end }},[{{ .Severity }}] {{ .ID }} - {{ .Title}} 7 | {{ end }} 8 | {{ end -}}{{- end }} -------------------------------------------------------------------------------- /doc/tags: -------------------------------------------------------------------------------- 1 | :trivy vim-trivy.txt /*:trivy* 2 | :trivyInstall vim-trivy.txt /*:trivyInstall* 3 | :trivyUpdate vim-trivy.txt /*:trivyUpdate* 4 | vim-trivy vim-trivy.txt /*vim-trivy* 5 | vim-trivy-commands vim-trivy.txt /*vim-trivy-commands* 6 | vim-trivy-contents vim-trivy.txt /*vim-trivy-contents* 7 | vim-trivy.txt vim-trivy.txt /*vim-trivy.txt* 8 | -------------------------------------------------------------------------------- /doc/vim-trivy.txt: -------------------------------------------------------------------------------- 1 | *vim-trivy.txt* 2 | *vim-trivy* 3 | 4 | ============================================================================== 5 | CONTENTS *vim-trivy-contents* 6 | 1. Commands.............................................|vim-trivy-commands| 7 | 8 | ============================================================================== 9 | COMMANDS *vim-trivy-commands* 10 | 11 | :trivy *:trivy* 12 | Run trivy against the current directory and populate the QuickFix list 13 | 14 | :trivyInstall *:trivyInstall* 15 | Install the latest version of trivy to %GOPATH/bin/trivy 16 | 17 | :trivyUpdate *:trivyUpdate* 18 | Updates trivy to the latest version, requires trivy to be on the path 19 | 20 | 21 | vim:tw=78:ts=8:ft=help:norl: 22 | -------------------------------------------------------------------------------- /plugin/vim-trivy.vim: -------------------------------------------------------------------------------- 1 | "" 2 | " @usage {} 3 | " Run Trivy against the current directory and populate the QuickFix list 4 | command! Trivy call s:Trivy() 5 | 6 | "" 7 | " @usage {} 8 | " Install the latest version of Trivy to %GOPATH/bin/Trivy 9 | command! TrivyInstall call s:TrivyInstall() 10 | 11 | 12 | " Trivy runs Trivy and prints adds the results to the quick fix buffer 13 | function! s:Trivy() abort 14 | try 15 | " capture the current error format 16 | let errorformat = &g:errorformat 17 | 18 | let s:template = '"@' . expand(':p:h:h') . '/vim-trivy/csv.tpl"' 19 | let s:command = 'trivy fs -q --security-checks vuln,config --exit-code 0 -f template --template ' . s:template . ' . | sort -u | sed -r "/^\s*$/d"' 20 | 21 | " set the error format for use with Trivy 22 | let &g:errorformat = '%f\,%l\,%m' 23 | " get the latest Trivy comments and open the quick fix window with them 24 | cgetexpr system(s:command) | cw 25 | call setqflist([], 'a', {'title' : ':Trivy'}) 26 | copen 27 | finally 28 | " restore the errorformat value 29 | let &g:errorformat = errorformat 30 | endtry 31 | endfunction 32 | 33 | " TrivyInstall runs the go install command to get the latest version of Trivy 34 | function! s:TrivyInstall() abort 35 | try 36 | echom "Downloading the latest version of Trivy" 37 | let installResult = system('curl https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | bash') 38 | if v:shell_error != 0 39 | echom installResult 40 | else 41 | echom "Trivy downloaded successfully" 42 | endif 43 | endtry 44 | endfunction 45 | 46 | --------------------------------------------------------------------------------