From 099dd0e518eddfc57d25f6737dd053ae43ee1ef2 Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Tue, 31 Jan 2023 08:17:38 +0000 Subject: [PATCH] chore: remove aws from config (#40) Signed-off-by: Owen Rumney --- README.md | 15 +-- pkg/config/config.go | 11 --- pkg/controllers/filesystem/key_bindings.go | 2 +- pkg/widgets/context.go | 7 -- pkg/widgets/services.go | 109 --------------------- pkg/widgets/widget.go | 1 - 6 files changed, 2 insertions(+), 143 deletions(-) delete mode 100644 pkg/widgets/services.go diff --git a/README.md b/README.md index 6b374eb..3b1a5db 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,6 @@ lazydocker, lazynpm, lazygit) - [Scan all images on your system](#scanning-all-local-images) - [Scan a single image](#scanning-a-specific-image) - [Scan a remote image](#scanning-a-remote-image) -- AWS Scanning - - [Scan your cloud account](#scanning-an-aws-account) - File System Scanning - [Scan a filesystem for vulnerabilities and misconfigurations](#scanning-a-filesystem) @@ -58,9 +56,6 @@ Alternatively, you can get the latest releases from [GitHub](https://github.com/ A config file can be added to `~/.config/lazytrivy/config.yml` to set default options. ```yaml -aws: - accountno: "464897523927" - region: us-east-1 vulnerability: ignoreunfixed: false filesystem: @@ -91,7 +86,6 @@ Usage: lazytrivy [command] Available Commands: - aws Launch lazytrivy in aws scanning mode filesystem Launch lazytrivy in filesystem scanning mode help Help about any command image Launch lazytrivy in image scanning mode @@ -122,7 +116,7 @@ The default docker host is `unix:///var/run/docker.sock`. If you are running Doc ### Starting in a specific mode -You can start `lazytrivy` in a specific mode using `aws`, `images` or `filesystem`: +You can start `lazytrivy` in a specific mode using `images` or `filesystem`: For example, to scan a specific filesystem folder, you could run: @@ -172,13 +166,6 @@ To scan an image that is not already locally on the machine, you can use the `r` ![Scanning a remote image](./.github/images/scan_remote_image.gif) -### Scanning an AWS Account - -To scan an AWS account, you can use the `w` key to switch to AWS mode, from there you can use the `s` key to scan, it will detect any valid credentials it can. - -![Scanning an AWS account](./.github/images/scan_aws_account.gif) - -By pressing `r` you can switch region in results you already have. ### Scanning a filesystem diff --git a/pkg/config/config.go b/pkg/config/config.go index 95fdab2..dd135ed 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,7 +9,6 @@ import ( ) type Config struct { - AWS AWSConfig Vulnerability VulnerabilityConfig Filesystem FileSystemConfig CacheDirectory string `json:"-"` @@ -18,12 +17,6 @@ type Config struct { DockerEndpoint string } -type AWSConfig struct { - AccountNo string - Region string - CacheDirectory string -} - type VulnerabilityConfig struct { IgnoreUnfixed bool } @@ -47,14 +40,10 @@ func createDefaultConfig() error { homeDir = os.TempDir() } trivyCacheDir := filepath.Join(homeDir, ".cache", "trivy") - awsCacheDir := filepath.Join(trivyCacheDir, "cloud", "aws") defaultConfig = &Config{ CacheDirectory: trivyCacheDir, Debug: false, - AWS: AWSConfig{ - CacheDirectory: awsCacheDir, - }, Vulnerability: VulnerabilityConfig{ IgnoreUnfixed: false, }, diff --git a/pkg/controllers/filesystem/key_bindings.go b/pkg/controllers/filesystem/key_bindings.go index c96e12a..1e27a16 100644 --- a/pkg/controllers/filesystem/key_bindings.go +++ b/pkg/controllers/filesystem/key_bindings.go @@ -9,7 +9,7 @@ import ( ) func (c *Controller) configureKeyBindings() error { - logger.Debugf("Configuring global AWS Controller keyboard shortcuts") + logger.Debugf("Configuring global Filesystem Controller keyboard shortcuts") if err := c.ConfigureGlobalKeyBindings(); err != nil { return fmt.Errorf("error configuring global keybindings: %w", err) } diff --git a/pkg/widgets/context.go b/pkg/widgets/context.go index 8844492..300effd 100644 --- a/pkg/widgets/context.go +++ b/pkg/widgets/context.go @@ -18,13 +18,6 @@ type vulnerabilityContext interface { ScanImage(ctx context.Context) } -type awsContext interface { - baseContext - ScanService(ctx context.Context) - UpdateAccount(account string) error - UpdateRegion(region string) error -} - type fsContext interface { baseContext ShowTarget(ctx context.Context) diff --git a/pkg/widgets/services.go b/pkg/widgets/services.go deleted file mode 100644 index fec6d1e..0000000 --- a/pkg/widgets/services.go +++ /dev/null @@ -1,109 +0,0 @@ -package widgets - -import ( - "context" - "errors" - "fmt" - "strings" - - "github.com/awesome-gocui/gocui" -) - -type ServicesWidget struct { - ListWidget - name string - x, y int - w, h int - body string - - ctx awsContext - v *gocui.View -} - -func NewServicesWidget(name string, g awsContext) *ServicesWidget { - w := 28 - - widget := &ServicesWidget{ - ListWidget: ListWidget{ - ctx: g, - selectionChangeFunc: g.SetSelected, - }, - name: name, - x: 0, - y: 0, - w: w, - h: 1, - ctx: g, - } - - return widget -} - -func (w *ServicesWidget) ConfigureKeys(*gocui.Gui) error { - if err := w.ctx.SetKeyBinding(w.name, gocui.KeyArrowUp, gocui.ModNone, w.previousItem); err != nil { - return fmt.Errorf("failed to set the previous image %w", err) - } - - if err := w.ctx.SetKeyBinding(w.name, gocui.KeyArrowDown, gocui.ModNone, w.nextItem); err != nil { - return fmt.Errorf("failed to set the next image %w", err) - } - - if err := w.ctx.SetKeyBinding(w.name, gocui.KeyEnter, gocui.ModNone, func(gui *gocui.Gui, view *gocui.View) error { - w.ctx.ScanService(context.Background()) - return nil - }); err != nil { - return fmt.Errorf("error setting keybinding for scanning image: %w", err) - } - - return nil -} - -func (w *ServicesWidget) Layout(g *gocui.Gui) error { - v, err := g.SetView(w.name, w.x, w.y, w.w, w.h, 0) - if err != nil { - if !errors.Is(err, gocui.ErrUnknownView) { - return fmt.Errorf("%w", err) - } - _, _ = fmt.Fprint(v, w.body) - _ = v.SetCursor(0, 0) - } - v.Title = " Services " - v.Highlight = true - v.SelBgColor = gocui.ColorGreen | gocui.AttrDim - v.SelFgColor = gocui.ColorBlack | gocui.AttrBold - if g.CurrentView() == v { - v.FrameColor = gocui.ColorGreen - } else { - v.FrameColor = gocui.ColorDefault - } - - w.v = v - return nil -} - -func (w *ServicesWidget) RefreshServices(services []string, serviceWidth int) error { - serviceList := make([]string, len(services)) - for i, service := range services { - serviceList[i] = fmt.Sprintf(" % -*s", serviceWidth+1, service) - } - - w.body = strings.Join(serviceList, "\n") - w.v.Clear() - w.bottomMost = len(serviceList) - _, _ = fmt.Fprintf(w.v, w.body) - _ = w.v.SetCursor(0, 0) - return nil -} - -func (w *ServicesWidget) SelectedService() string { - _, y := w.v.Cursor() - if service, err := w.v.Line(y); err == nil { - return strings.TrimSpace(service) - } - return "" -} - -func (w *ServicesWidget) RefreshView() { - w.v.Clear() - _, _ = fmt.Fprintf(w.v, w.body) -} diff --git a/pkg/widgets/widget.go b/pkg/widgets/widget.go index 0df2abb..126beb1 100644 --- a/pkg/widgets/widget.go +++ b/pkg/widgets/widget.go @@ -29,6 +29,5 @@ type Tab string const ( VulnerabilitiesTab Tab = "Vulnerabilities" - AWSTab Tab = "AWS" FileSystemTab Tab = "FileSystem" )