From 6d440af1a91dcc3d6a437de65a5ffad82e68ee39 Mon Sep 17 00:00:00 2001 From: simar7 <1254783+simar7@users.noreply.github.com> Date: Sat, 4 Nov 2023 16:12:10 -0600 Subject: [PATCH] chore(docs): Update docs (#42) * chore(docs): Update docs * add readme * remove id gen from trivy-iac --- ARCHITECTURE.md | 19 ++++++++++++++++++ Makefile | 5 ----- README.md | 10 +++++++++- cmd/id/main.go | 52 ------------------------------------------------- 4 files changed, 28 insertions(+), 58 deletions(-) create mode 100644 ARCHITECTURE.md delete mode 100644 cmd/id/main.go diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 00000000..c8cb6ca1 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,19 @@ +# Architecture + +This document aims to answer the question *Where is the code that does X?* + +## Project Layout + +The directory structure is broken down as follows: + +- `avd_docs/` - The source for the [AVD documentation](https://aquasecurity.github.io/avd/). +- `cmd/` - These CLI tools are primarily used during development for end-to-end testing without needing to pull the library into trivy/tfsec etc. +- `internal/adapters` - Adapters take input - such as a Terraform file or an AWS account - and _adapt_ it to a common format that can be used by the rules engine. +- `pkg/detection` - Used for sniffing file types from both file name and content. This is done so that we can determine the type of file we're dealing with and then pass it to the correct parser. +- `pkg/extrafs` - Wraps `os.DirFS` to provide a filesystem that can also resolve symlinks. +- `pkg/formatters` - Used to format scan results in specific formats, such as JSON, CheckStyle, CSV, SARIF, etc. +- `pkg/rego` - A package for evaluating Rego rules against given inputs. +- `pkg/rules` - This package exposes internal rules, and imports them accordingly (see _rules.go_). +- `pkg/scanners` - Scanners for various inputs. For example, the `terraform` scanner will scan a Terraform directory and return a list of resources. +- `pkg/types` - Useful types. Our types wrap a simple data type (e.g. `bool`) and add various metadata to it, such as file name and line number where it was defined. +- `test` - Integration tests and other high-level tests that require a full build of the project. diff --git a/Makefile b/Makefile index c7614914..9d2ea5a6 100755 --- a/Makefile +++ b/Makefile @@ -23,8 +23,3 @@ docs: .PHONY: docs-test docs-test: go test -v ./cmd/avd_generator/... - -.PHONY: id -id: - @go run ./cmd/id - diff --git a/README.md b/README.md index 8196a8b1..202c4efc 100755 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# Trivy IAC \ No newline at end of file +# trivy-iac + +_trivy-iac_ is the Infrastructure-as-code scanning logic for Trivy + +Please see [ARCHITECTURE.md](ARCHITECTURE.md) for more information. + +_trivy-aws_ is an [Aqua Security](https://aquasec.com) open source project. +Learn about our open source work and portfolio [here](https://www.aquasec.com/products/open-source-projects/). +Join the community, and talk to us about any matter in [GitHub Discussion](https://github.com/aquasecurity/trivy/discussions). diff --git a/cmd/id/main.go b/cmd/id/main.go deleted file mode 100644 index e8e5da2e..00000000 --- a/cmd/id/main.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "fmt" - "os" - "sort" - "strconv" - "strings" - - "github.com/aquasecurity/defsec/pkg/framework" - - _ "github.com/aquasecurity/trivy-iac/pkg/rego" - "github.com/aquasecurity/trivy-iac/pkg/rules" -) - -func main() { - - // organise existing rules by provider - keyMap := make(map[string][]string) - for _, rule := range rules.GetRegistered(framework.ALL) { - id := rule.GetRule().AVDID - if id == "" { - continue - } - parts := strings.Split(id, "-") - if len(parts) != 3 { - continue - } - keyMap[parts[1]] = append(keyMap[parts[1]], parts[2]) - } - - fmt.Print("\nThe following IDs are free - choose the one for the service you are targeting.\n\n") - - var freeIDs []string - for key := range keyMap { - sort.Strings(keyMap[key]) - all := keyMap[key] - max := all[len(all)-1] - i, err := strconv.Atoi(max) - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "Error, invalid AVD ID: AVD-%s-%s\n", key, max) - } - free := fmt.Sprintf("AVD-%s-%04d", key, i+1) - freeIDs = append(freeIDs, fmt.Sprintf("%16s: %s", key, free)) - } - - sort.Slice(freeIDs, func(i, j int) bool { - return strings.TrimSpace(freeIDs[i]) < strings.TrimSpace(freeIDs[j]) - }) - fmt.Println(strings.Join(freeIDs, "\n")) - -}