Compare commits
39 Commits
Author | SHA1 | Date |
---|---|---|
|
7211eae083 | |
|
dbd7b766ad | |
|
34c5c938dc | |
|
4d3850d414 | |
|
16e13fa73b | |
|
861041797a | |
|
2ed3ca63e3 | |
|
21520e93dd | |
|
0e28f79a57 | |
|
44e8f186f7 | |
|
a92643da41 | |
|
6ba122926d | |
|
0eb0b03a70 | |
|
055c0bdc47 | |
|
312aa3e95b | |
|
27c7bb4167 | |
|
726e444b1f | |
|
063369fd25 | |
|
14917360b6 | |
|
88e199785f | |
|
d07b011783 | |
|
fe7d086b26 | |
|
d12be3359b | |
|
9491b1c6a4 | |
|
b77cbf3f1c | |
|
2c5e74add4 | |
|
3c39e93975 | |
|
1c51d8e6c0 | |
|
505ab3b26f | |
|
cb3b85f49f | |
|
f29a571d78 | |
|
13f43684a3 | |
|
ed188deb01 | |
|
17f9fb3b2a | |
|
f49e888edc | |
|
5c47c08b09 | |
|
fc0a709ca4 | |
|
b271cc4068 | |
|
cf3fd07f23 |
|
@ -0,0 +1,12 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
open-pull-requests-limit: 10
|
||||
groups:
|
||||
actions:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
|
@ -15,17 +15,49 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
||||
with:
|
||||
go-version: 1.21
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
- name: Build
|
||||
run: make build
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
run: make test
|
||||
|
||||
gomodtidy:
|
||||
name: Enforce go.mod tidiness
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb # v3.5.0
|
||||
with:
|
||||
ref: "${{ github.event.pull_request.head.sha }}"
|
||||
repository: ${{github.event.pull_request.head.repo.full_name}}
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
- name: Execute go mod tidy and check the outcome
|
||||
working-directory: ./
|
||||
run: |
|
||||
go mod tidy
|
||||
exit_code=$(git diff --exit-code)
|
||||
exit ${exit_code}
|
||||
|
||||
- name: Print a comment in case of failure
|
||||
run: |
|
||||
echo "The go.mod and/or go.sum files appear not to be correctly tidied.
|
||||
|
||||
Please, rerun go mod tidy to fix the issues."
|
||||
exit 1
|
||||
if: |
|
||||
failure() && github.event.pull_request.head.repo.full_name == github.repository
|
||||
|
|
|
@ -16,7 +16,7 @@ jobs:
|
|||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
|
||||
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb #v3.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
@ -24,22 +24,22 @@ jobs:
|
|||
run: git fetch --prune --force --tags
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a #v3.2.1
|
||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
- uses: sigstore/cosign-installer@c3667d99424e7e6047999fb6246c0da843953c65 #v3.0.1
|
||||
- uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 #v3.9.2
|
||||
|
||||
- uses: anchore/sbom-action/download-syft@448520c4f19577ffce70a8317e619089054687e3 #v0.13.4
|
||||
- uses: anchore/sbom-action/download-syft@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 #v0.20.4
|
||||
|
||||
- uses: docker/login-action@v2
|
||||
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Install GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v5
|
||||
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6
|
||||
with:
|
||||
install-only: true
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ GO ?= go
|
|||
GORELEASER ?= goreleaser
|
||||
output ?= dbg-go
|
||||
TEST_FLAGS ?= -v -race -tags=test_all
|
||||
DRIVERKIT_VERSION=v0.15.3
|
||||
DRIVERKIT_VERSION=v0.21.0
|
||||
LDFLAGS := -X github.com/falcosecurity/driverkit/pkg/driverbuilder/builder.defaultImageTag=${DRIVERKIT_VERSION}
|
||||
|
||||
.PHONY: build
|
||||
|
|
30
cmd/root.go
30
cmd/root.go
|
@ -16,8 +16,8 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"github.com/falcosecurity/falcoctl/pkg/output"
|
||||
"github.com/pterm/pterm"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -29,7 +29,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
logLevel = output.NewLogLevel()
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "dbg-go",
|
||||
Short: "A command line helper tool used by falcosecurity test-infra dbg.",
|
||||
SilenceErrors: true,
|
||||
|
@ -49,7 +50,8 @@ var (
|
|||
return err
|
||||
}
|
||||
}
|
||||
return initLogger(cmd.Name())
|
||||
root.Printer = output.NewPrinter(logLevel.ToPtermLogLevel(), pterm.LogFormatterColorful, os.Stdout)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -78,12 +80,12 @@ func loadDriverVersions() error {
|
|||
func init() {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
root.Printer.Logger.Fatal("failed to get working dir.", pterm.DefaultLogger.Args("err", err))
|
||||
}
|
||||
|
||||
flags := rootCmd.PersistentFlags()
|
||||
flags.Bool("dry-run", false, "enable dry-run mode.")
|
||||
flags.StringP("log-level", "l", slog.LevelInfo.String(), "set log verbosity.")
|
||||
flags.VarP(logLevel, "log-level", "l", "set log verbosity "+logLevel.Allowed())
|
||||
flags.String("repo-root", cwd, "test-infra repository root path.")
|
||||
flags.StringP("architecture", "a", runtime.GOARCH, `architecture to run against. Supported: `+kernelrelease.SupportedArchs.String())
|
||||
flags.StringSlice("driver-version", nil, "driver versions to run against.")
|
||||
|
@ -97,10 +99,10 @@ func init() {
|
|||
Supported: [`+strings.Join(root.SupportedDistroSlice, ",")+"].")
|
||||
|
||||
// Custom completions
|
||||
rootCmd.RegisterFlagCompletionFunc("target-distro", func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
_ = rootCmd.RegisterFlagCompletionFunc("target-distro", func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return root.SupportedDistroSlice, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
rootCmd.RegisterFlagCompletionFunc("architecture", func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
_ = rootCmd.RegisterFlagCompletionFunc("architecture", func(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return kernelrelease.SupportedArchs.Strings(), cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
|
||||
|
@ -109,18 +111,6 @@ Supported: [`+strings.Join(root.SupportedDistroSlice, ",")+"].")
|
|||
rootCmd.AddCommand(s3Cmd)
|
||||
}
|
||||
|
||||
func initLogger(subcmd string) error {
|
||||
var programLevel = new(slog.LevelVar) // Info by default
|
||||
h := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: programLevel})
|
||||
|
||||
// Set as default a logger with "cmd" attribute
|
||||
slog.SetDefault(slog.New(h).With("cmd", subcmd))
|
||||
|
||||
// Set log level
|
||||
logLevel := viper.GetString("log-level")
|
||||
return programLevel.UnmarshalText([]byte(logLevel))
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
|
216
go.mod
216
go.mod
|
@ -1,157 +1,181 @@
|
|||
module github.com/falcosecurity/dbg-go
|
||||
|
||||
go 1.21
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.24.2
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go-v2 v1.21.0
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.37
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.35
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5
|
||||
github.com/falcosecurity/driverkit v0.15.3
|
||||
github.com/aws/aws-sdk-go-v2 v1.32.2
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.43
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.41
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.58.2
|
||||
github.com/falcosecurity/driverkit v0.21.0
|
||||
github.com/falcosecurity/falcoctl v0.10.1-0.20241120140318-131abecc4be9
|
||||
github.com/johannesboyne/gofakes3 v0.0.0-20230506070712-04da935ef877
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/spf13/viper v1.16.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/sync v0.3.0
|
||||
github.com/pterm/pterm v0.12.79
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/viper v1.19.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
golang.org/x/sync v0.11.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
atomicgo.dev/cursor v0.2.0 // indirect
|
||||
atomicgo.dev/keyboard v0.2.9 // indirect
|
||||
atomicgo.dev/schedule v0.1.0 // indirect
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
|
||||
github.com/MakeNowJust/heredoc v1.0.0 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/aws/aws-sdk-go v1.44.256 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.42 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
|
||||
github.com/aws/smithy-go v1.14.2 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/aws/aws-sdk-go v1.55.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 // indirect
|
||||
github.com/aws/smithy-go v1.22.0 // indirect
|
||||
github.com/blang/semver v3.5.1+incompatible // indirect
|
||||
github.com/chai2010/gettext-go v1.0.2 // indirect
|
||||
github.com/containerd/containerd v1.7.5 // indirect
|
||||
github.com/blang/semver/v4 v4.0.0 // indirect
|
||||
github.com/chai2010/gettext-go v1.0.3 // indirect
|
||||
github.com/containerd/console v1.0.4 // indirect
|
||||
github.com/containerd/log v0.1.0 // indirect
|
||||
github.com/creasty/defaults v1.7.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/docker/distribution v2.8.2+incompatible // indirect
|
||||
github.com/docker/docker v24.0.5+incompatible // indirect
|
||||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/distribution/reference v0.6.0 // indirect
|
||||
github.com/docker/docker v27.3.1+incompatible // indirect
|
||||
github.com/docker/go-connections v0.5.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
|
||||
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
|
||||
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
|
||||
github.com/falcosecurity/falcoctl v0.6.0 // indirect
|
||||
github.com/fatih/camelcase v1.0.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/fvbommel/sortorder v1.1.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.20.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||
github.com/go-openapi/swag v0.22.4 // indirect
|
||||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||
github.com/go-errors/errors v1.5.1 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.15.3 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/btree v1.1.2 // indirect
|
||||
github.com/google/gnostic-models v0.6.8 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gookit/color v1.5.4 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.16.7 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
|
||||
github.com/lithammer/fuzzysearch v1.1.8 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||
github.com/moby/patternmatcher v0.6.0 // indirect
|
||||
github.com/moby/spdystream v0.2.0 // indirect
|
||||
github.com/moby/sys/sequential v0.5.0 // indirect
|
||||
github.com/moby/spdystream v0.5.0 // indirect
|
||||
github.com/moby/sys/sequential v0.6.0 // indirect
|
||||
github.com/moby/sys/user v0.3.0 // indirect
|
||||
github.com/moby/sys/userns v0.1.0 // indirect
|
||||
github.com/moby/term v0.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
|
||||
github.com/opencontainers/runc v1.1.9 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
|
||||
github.com/sagikazarmark/locafero v0.6.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/spf13/afero v1.9.5 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
github.com/xlab/treeprint v1.2.0 // indirect
|
||||
go.starlark.net v0.0.0-20230831151029-c9e9adf3fde2 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/oauth2 v0.11.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
|
||||
go.opentelemetry.io/otel v1.29.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.29.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.29.0 // indirect
|
||||
go.starlark.net v0.0.0-20240725214946-42030a7cedce // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/crypto v0.35.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
|
||||
golang.org/x/net v0.36.0 // indirect
|
||||
golang.org/x/oauth2 v0.24.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/term v0.29.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
golang.org/x/tools v0.26.0 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
k8s.io/api v0.28.1 // indirect
|
||||
k8s.io/apimachinery v0.28.1 // indirect
|
||||
k8s.io/cli-runtime v0.28.1 // indirect
|
||||
k8s.io/client-go v0.28.1 // indirect
|
||||
k8s.io/component-base v0.28.1 // indirect
|
||||
k8s.io/klog/v2 v2.100.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20230901164831-6c774f458599 // indirect
|
||||
k8s.io/kubectl v0.28.1 // indirect
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
|
||||
lukechampine.com/uint128 v1.3.0 // indirect
|
||||
modernc.org/cc/v3 v3.41.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.15 // indirect
|
||||
modernc.org/libc v1.24.1 // indirect
|
||||
k8s.io/api v0.31.2 // indirect
|
||||
k8s.io/apimachinery v0.31.2 // indirect
|
||||
k8s.io/cli-runtime v0.30.3 // indirect
|
||||
k8s.io/client-go v0.31.2 // indirect
|
||||
k8s.io/component-base v0.30.3 // indirect
|
||||
k8s.io/klog/v2 v2.130.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20240726031636-6f6746feab9c // indirect
|
||||
k8s.io/kubectl v0.30.3 // indirect
|
||||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240722195230-4a140ff9c08e // indirect
|
||||
modernc.org/libc v1.55.6 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.7.1 // indirect
|
||||
modernc.org/opt v0.1.3 // indirect
|
||||
modernc.org/sqlite v1.25.0 // indirect
|
||||
modernc.org/memory v1.8.0 // indirect
|
||||
modernc.org/sqlite v1.31.1 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
oras.land/oras-go/v2 v2.3.0 // indirect
|
||||
oras.land/oras-go/v2 v2.5.0 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/kustomize/api v0.14.0 // indirect
|
||||
sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
sigs.k8s.io/kustomize/api v0.17.3 // indirect
|
||||
sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
|
5
main.go
5
main.go
|
@ -15,13 +15,12 @@ limitations under the License.
|
|||
package main
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/falcosecurity/dbg-go/cmd"
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := cmd.Execute(); err != nil {
|
||||
slog.With("err", err).Error("error executing dbg-go")
|
||||
root.Printer.Logger.Error("error executing dbg-go", root.Printer.Logger.Args("err", err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package build
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
@ -34,7 +33,7 @@ import (
|
|||
var testClient *s3utils.Client
|
||||
|
||||
func Run(opts Options) error {
|
||||
slog.Info("building drivers")
|
||||
root.Printer.Logger.Info("building drivers")
|
||||
var (
|
||||
client *s3utils.Client
|
||||
err error
|
||||
|
@ -84,7 +83,8 @@ func Run(opts Options) error {
|
|||
func buildConfig(client *s3utils.Client, opts Options,
|
||||
publishCh chan<- publishVal, redirectErrorsF *os.File,
|
||||
driverVersion, configPath string) error {
|
||||
logger := slog.With("config", configPath)
|
||||
|
||||
args := root.Printer.Logger.Args("config", configPath)
|
||||
configData, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -95,7 +95,10 @@ func buildConfig(client *s3utils.Client, opts Options,
|
|||
return errors.WithMessagef(err, "config: %s", configPath)
|
||||
}
|
||||
|
||||
ro := cmd.NewRootOptions()
|
||||
ro, err := cmd.NewRootOptions()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ro.Architecture = opts.Architecture.String()
|
||||
ro.DriverVersion = driverVersion
|
||||
|
@ -123,19 +126,19 @@ func buildConfig(client *s3utils.Client, opts Options,
|
|||
if ro.Output.Module != "" {
|
||||
moduleName := filepath.Base(ro.Output.Module)
|
||||
if client.HeadDriver(opts.Options, driverVersion, moduleName) {
|
||||
logger.Info("output module already exists inside S3 bucket - skipping")
|
||||
root.Printer.Logger.Info("output module already exists inside S3 bucket - skipping", args)
|
||||
ro.Output.Module = "" // disable module build
|
||||
}
|
||||
}
|
||||
if ro.Output.Probe != "" {
|
||||
probeName := filepath.Base(ro.Output.Probe)
|
||||
if client.HeadDriver(opts.Options, driverVersion, probeName) {
|
||||
logger.Info("output probe already exists inside S3 bucket - skipping")
|
||||
root.Printer.Logger.Info("output probe already exists inside S3 bucket - skipping", args)
|
||||
ro.Output.Probe = "" // disable probe build
|
||||
}
|
||||
}
|
||||
if ro.Output.Module == "" && ro.Output.Probe == "" {
|
||||
logger.Info("drivers already available on S3 bucket, skipping build")
|
||||
root.Printer.Logger.Info("drivers already available on S3 bucket, skipping build", args)
|
||||
return nil // nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -143,14 +146,14 @@ func buildConfig(client *s3utils.Client, opts Options,
|
|||
// Ensure output folder exist; don't check for error, it will fail at next step anyway.
|
||||
_ = os.MkdirAll(filepath.Dir(driverkitYaml.Output.Module), 0700)
|
||||
|
||||
err = driverbuilder.NewDockerBuildProcessor(1000, "").Start(ro.ToBuild())
|
||||
err = driverbuilder.NewDockerBuildProcessor(1000, "").Start(ro.ToBuild(root.Printer))
|
||||
if err != nil {
|
||||
if redirectErrorsF != nil {
|
||||
logLine := fmt.Sprintf("config: %s | error: %s\n", configPath, err.Error())
|
||||
_, _ = redirectErrorsF.WriteString(logLine)
|
||||
}
|
||||
if opts.IgnoreErrors {
|
||||
logger.Error(err.Error())
|
||||
root.Printer.Logger.Error(err.Error(), args)
|
||||
return nil // do not break the configs loop, just try the next one
|
||||
}
|
||||
return err
|
||||
|
@ -170,17 +173,25 @@ func publishLoop(publishCh <-chan publishVal, opts root.Options, client *s3utils
|
|||
if val.out.Module != "" {
|
||||
err := client.PutDriver(opts, val.driverVersion, val.out.Module)
|
||||
if err != nil {
|
||||
slog.Warn("failed to upload module", "path", val.out.Module, "err", err.Error())
|
||||
root.Printer.Logger.Warn("failed to upload module",
|
||||
root.Printer.Logger.Args(
|
||||
"path", val.out.Module,
|
||||
"err", err.Error()))
|
||||
} else {
|
||||
slog.Info("published module", "path", val.out.Module)
|
||||
root.Printer.Logger.Info("published module",
|
||||
root.Printer.Logger.Args("path", val.out.Module))
|
||||
}
|
||||
}
|
||||
if val.out.Probe != "" {
|
||||
err := client.PutDriver(opts, val.driverVersion, val.out.Probe)
|
||||
if err != nil {
|
||||
slog.Warn("failed to upload probe", "path", val.out.Probe, "err", err.Error())
|
||||
root.Printer.Logger.Warn("failed to upload probe",
|
||||
root.Printer.Logger.Args(
|
||||
"path", val.out.Probe,
|
||||
"err", err.Error()))
|
||||
} else {
|
||||
slog.Info("published probe", "path", val.out.Probe)
|
||||
root.Printer.Logger.Info("published probe",
|
||||
root.Printer.Logger.Args("path", val.out.Probe))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ func TestBuild(t *testing.T) {
|
|||
DriverName: "falco",
|
||||
RepoRoot: "./test",
|
||||
Target: root.Target{
|
||||
Distro: "centos",
|
||||
KernelRelease: "5.14.0-370.el9.x86_64",
|
||||
Distro: "arch",
|
||||
KernelRelease: "6.0.5.arch1",
|
||||
KernelVersion: "1",
|
||||
},
|
||||
},
|
||||
|
@ -64,15 +64,15 @@ func TestBuild(t *testing.T) {
|
|||
IgnoreErrors: false,
|
||||
},
|
||||
expectedLocalObjects: []string{
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
},
|
||||
expectedBucketObjects: []string{
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
},
|
||||
shouldCreate: true,
|
||||
name: "build 5.0.1+driver centos 5.14.0-370.el9.x86_64",
|
||||
name: "build 5.0.1+driver arch 6.0.5.arch1",
|
||||
},
|
||||
{
|
||||
opts: Options{
|
||||
|
@ -82,8 +82,8 @@ func TestBuild(t *testing.T) {
|
|||
DriverName: "falco",
|
||||
RepoRoot: "./test",
|
||||
Target: root.Target{
|
||||
Distro: "centos",
|
||||
KernelRelease: "5.14.0-372.el9.x86_64",
|
||||
Distro: "arch",
|
||||
KernelRelease: "6.0.6.arch1",
|
||||
KernelVersion: "1",
|
||||
},
|
||||
},
|
||||
|
@ -92,17 +92,17 @@ func TestBuild(t *testing.T) {
|
|||
IgnoreErrors: false,
|
||||
},
|
||||
expectedLocalObjects: []string{
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.o",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
"falco_arch_6.0.6.arch1_1.ko",
|
||||
"falco_arch_6.0.6.arch1_1.o",
|
||||
},
|
||||
expectedBucketObjects: []string{
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
},
|
||||
shouldCreate: false, // since it is not publishing
|
||||
name: "build 5.0.1+driver centos 5.14.0-372.el9.x86_64",
|
||||
name: "build 5.0.1+driver arch 6.0.6.arch1",
|
||||
},
|
||||
{
|
||||
opts: Options{
|
||||
|
@ -112,8 +112,8 @@ func TestBuild(t *testing.T) {
|
|||
DriverName: "falco",
|
||||
RepoRoot: "./test",
|
||||
Target: root.Target{
|
||||
Distro: "centos",
|
||||
KernelRelease: "5.14.0-370.el9.x86_64", // try to rebuild same object.
|
||||
Distro: "arch",
|
||||
KernelRelease: "6.0.5.arch1", // try to rebuild same object.
|
||||
KernelVersion: "1",
|
||||
},
|
||||
},
|
||||
|
@ -122,17 +122,17 @@ func TestBuild(t *testing.T) {
|
|||
IgnoreErrors: false,
|
||||
},
|
||||
expectedLocalObjects: []string{
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.o",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
"falco_arch_6.0.6.arch1_1.ko",
|
||||
"falco_arch_6.0.6.arch1_1.o",
|
||||
},
|
||||
expectedBucketObjects: []string{
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
},
|
||||
shouldCreate: false, // since objects are already present, nothing should be created
|
||||
name: "rebuild 5.0.1+driver centos 5.14.0-370.el9.x86_64",
|
||||
name: "rebuild 5.0.1+driver arch 6.0.5.arch1",
|
||||
},
|
||||
{
|
||||
opts: Options{
|
||||
|
@ -142,8 +142,8 @@ func TestBuild(t *testing.T) {
|
|||
DriverName: "falco",
|
||||
RepoRoot: "./test",
|
||||
Target: root.Target{
|
||||
Distro: "centos",
|
||||
KernelRelease: "5.14.0-370.el9.x86_64", // try to rebuild same object.
|
||||
Distro: "arch",
|
||||
KernelRelease: "6.0.5.arch1", // try to rebuild same object.
|
||||
KernelVersion: "1",
|
||||
},
|
||||
},
|
||||
|
@ -152,17 +152,17 @@ func TestBuild(t *testing.T) {
|
|||
IgnoreErrors: false,
|
||||
},
|
||||
expectedLocalObjects: []string{
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-372.el9.x86_64_1.o",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
"falco_arch_6.0.6.arch1_1.ko",
|
||||
"falco_arch_6.0.6.arch1_1.o",
|
||||
},
|
||||
expectedBucketObjects: []string{
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.ko",
|
||||
"falco_centos_5.14.0-370.el9.x86_64_1.o",
|
||||
"falco_arch_6.0.5.arch1_1.ko",
|
||||
"falco_arch_6.0.5.arch1_1.o",
|
||||
},
|
||||
shouldCreate: true,
|
||||
name: "rebuild and publish 5.0.1+driver centos 5.14.0-370.el9.x86_64",
|
||||
name: "rebuild and publish 5.0.1+driver arch 6.0.5.arch1",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ limitations under the License.
|
|||
package cleanup
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
)
|
||||
|
||||
func Run(opts Options, cleaner Cleaner) error {
|
||||
slog.Info(cleaner.Info())
|
||||
root.Printer.Logger.Info(cleaner.Info())
|
||||
return cleaner.Cleanup(opts)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package cleanup
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -175,7 +176,9 @@ func TestCleanupFiltered(t *testing.T) {
|
|||
lines := 0
|
||||
testutils.RunTestParsingLogs(t, func() error {
|
||||
return Run(test.opts, NewFileCleaner())
|
||||
}, &messageJSON, func() bool {
|
||||
}, func(line []byte) bool {
|
||||
err = json.Unmarshal(line, &messageJSON)
|
||||
assert.NoError(t, err)
|
||||
if messageJSON.Path == "" {
|
||||
return true // skip and go on
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
json "github.com/json-iterator/go"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/yaml.v3"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
|
@ -36,7 +35,7 @@ var (
|
|||
)
|
||||
|
||||
func Run(opts Options) error {
|
||||
slog.Info("generating config files")
|
||||
root.Printer.Logger.Info("generating config files")
|
||||
if opts.Auto {
|
||||
return autogenerateConfigs(opts)
|
||||
} else if opts.IsSet() {
|
||||
|
@ -48,7 +47,8 @@ func Run(opts Options) error {
|
|||
// This is the only function where opts.Distro gets overridden using KernelCrawler namings
|
||||
func autogenerateConfigs(opts Options) error {
|
||||
url := fmt.Sprintf(urlArchFmt, opts.Architecture.ToNonDeb())
|
||||
slog.Debug("downloading json data", "url", url)
|
||||
root.Printer.Logger.Debug("downloading json data",
|
||||
root.Printer.Logger.Args("url", url))
|
||||
|
||||
// Fetch kernel list json
|
||||
var (
|
||||
|
@ -66,7 +66,7 @@ func autogenerateConfigs(opts Options) error {
|
|||
}
|
||||
}
|
||||
|
||||
slog.Debug("fetched json")
|
||||
root.Printer.Logger.Debug("fetched json")
|
||||
if testCacheData {
|
||||
testJsonData = jsonData
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func autogenerateConfigs(opts Options) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slog.Debug("unmarshaled json")
|
||||
root.Printer.Logger.Debug("unmarshalled json")
|
||||
var errGrp errgroup.Group
|
||||
|
||||
for distro, f := range fullJson {
|
||||
|
@ -155,7 +155,7 @@ func generateSingleConfig(opts Options) error {
|
|||
if errors.As(err, &unsupportedTargetError) {
|
||||
return unsupportedTargetError
|
||||
}
|
||||
slog.Warn(err.Error())
|
||||
root.Printer.Logger.Warn(err.Error())
|
||||
}
|
||||
driverkitYaml := validate.DriverkitYaml{
|
||||
KernelVersion: opts.KernelVersion,
|
||||
|
@ -167,12 +167,13 @@ func generateSingleConfig(opts Options) error {
|
|||
}
|
||||
|
||||
func dumpConfig(opts Options, dkYaml validate.DriverkitYaml) error {
|
||||
slog.Info("generating",
|
||||
"target", dkYaml.Target,
|
||||
"kernelrelease", dkYaml.KernelRelease,
|
||||
"kernelversion", dkYaml.KernelVersion)
|
||||
root.Printer.Logger.Info("generating",
|
||||
root.Printer.Logger.Args(
|
||||
"target", dkYaml.Target,
|
||||
"kernelrelease", dkYaml.KernelRelease,
|
||||
"kernelversion", dkYaml.KernelVersion))
|
||||
if opts.DryRun {
|
||||
slog.Info("skipping because of dry-run.")
|
||||
root.Printer.Logger.Info("skipping because of dry-run.")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@ limitations under the License.
|
|||
package publish
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
s3utils "github.com/falcosecurity/dbg-go/pkg/utils/s3"
|
||||
)
|
||||
|
@ -25,7 +23,7 @@ import (
|
|||
var testClient *s3utils.Client
|
||||
|
||||
func Run(opts Options) error {
|
||||
slog.Info("publishing drivers")
|
||||
root.Printer.Logger.Info("publishing drivers")
|
||||
var (
|
||||
client *s3utils.Client
|
||||
err error
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package root
|
||||
|
||||
import (
|
||||
"github.com/falcosecurity/falcoctl/pkg/output"
|
||||
"github.com/pterm/pterm"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
Printer = output.NewPrinter(pterm.LogLevelInfo, pterm.LogFormatterColorful, os.Stdout)
|
||||
)
|
|
@ -16,7 +16,6 @@ package root
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
|
||||
"github.com/falcosecurity/driverkit/pkg/driverbuilder/builder"
|
||||
|
@ -106,6 +105,7 @@ func LoadRootOptions() Options {
|
|||
KernelVersion: viper.GetString("target-kernelversion"),
|
||||
},
|
||||
}
|
||||
slog.Debug("loaded root options", "opts", opts)
|
||||
Printer.Logger.Debug("loaded root options",
|
||||
Printer.Logger.Args("opts", opts))
|
||||
return opts
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package root
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
|
@ -29,9 +28,10 @@ func (f *FsLooper) LoopFiltered(opts Options, message, tag string, worker RowWor
|
|||
return err
|
||||
}
|
||||
for _, file := range files {
|
||||
slog.Info(message, tag, file)
|
||||
Printer.Logger.Info(message,
|
||||
Printer.Logger.Args(tag, file))
|
||||
if opts.DryRun {
|
||||
slog.Info("skipping because of dry-run.")
|
||||
Printer.Logger.Info("skipping because of dry-run.")
|
||||
return nil
|
||||
}
|
||||
err = worker(driverVersion, file)
|
||||
|
|
|
@ -15,32 +15,21 @@ limitations under the License.
|
|||
package stats
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// Used by tests!
|
||||
// We cannot simply use table = tablewriter.NewWriter(log.Default().Writer())
|
||||
// as that would completely break tablewriter output.
|
||||
var testOutputWriter io.Writer
|
||||
|
||||
func Run(opts Options, statter Statter) error {
|
||||
slog.Info(statter.Info())
|
||||
root.Printer.Logger.Info(statter.Info())
|
||||
driverStatsByVersion, err := statter.GetDriverStats(opts.Options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var table *tablewriter.Table
|
||||
if testOutputWriter != nil {
|
||||
table = tablewriter.NewWriter(testOutputWriter)
|
||||
} else {
|
||||
table = tablewriter.NewWriter(os.Stdout)
|
||||
}
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Version", "Modules", "Probes"})
|
||||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
|
||||
table.SetCenterSeparator("|")
|
||||
|
|
|
@ -15,10 +15,7 @@ limitations under the License.
|
|||
package stats
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
|
@ -218,58 +215,12 @@ func TestStats(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
// capture output!
|
||||
|
||||
statter := NewFileStatter()
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// Use logged output to ensure we fetched correct stats
|
||||
type MessageJSON struct {
|
||||
Message string `json:"msg"`
|
||||
}
|
||||
var messageJSON MessageJSON
|
||||
outputStats := driverStats{}
|
||||
startParsing := false
|
||||
parsingIdx := 0
|
||||
testutils.RunTestParsingLogs(t,
|
||||
func() error {
|
||||
testOutputWriter = log.Default().Writer()
|
||||
return Run(test.opts, NewFileStatter())
|
||||
},
|
||||
&messageJSON,
|
||||
func() bool {
|
||||
messageJSON.Message = strings.ReplaceAll(messageJSON.Message, " ", "")
|
||||
// Example lines:
|
||||
//{"time":"2023-08-29T11:38:35.692782942+02:00","level":"INFO","msg":"1.0.0+driver"}
|
||||
//{"time":"2023-08-29T11:38:35.692784013+02:00","level":"INFO","msg":""}
|
||||
//{"time":"2023-08-29T11:38:35.692784775+02:00","level":"INFO","msg":"|"}
|
||||
//{"time":"2023-08-29T11:38:35.692785487+02:00","level":"INFO","msg":""}
|
||||
//{"time":"2023-08-29T11:38:35.69279484+02:00","level":"INFO","msg":"4"}
|
||||
//{"time":"2023-08-29T11:38:35.692796064+02:00","level":"INFO","msg":""}
|
||||
//{"time":"2023-08-29T11:38:35.692797001+02:00","level":"INFO","msg":"|"}
|
||||
//{"time":"2023-08-29T11:38:35.692797848+02:00","level":"INFO","msg":""}
|
||||
//{"time":"2023-08-29T11:38:35.69280042+02:00","level":"INFO","msg":"3"}
|
||||
if startParsing {
|
||||
parsingIdx++
|
||||
if parsingIdx%4 == 0 {
|
||||
n, err := strconv.ParseInt(messageJSON.Message, 10, 64)
|
||||
assert.NoError(t, err)
|
||||
switch parsingIdx / 4 {
|
||||
case 1:
|
||||
outputStats.NumModules = n
|
||||
case 2:
|
||||
outputStats.NumProbes = n
|
||||
}
|
||||
}
|
||||
}
|
||||
if messageJSON.Message == "1.0.0+driver" {
|
||||
startParsing = true
|
||||
} else if parsingIdx == 8 {
|
||||
// parsed both numbers
|
||||
return false // break out
|
||||
}
|
||||
return true // continue
|
||||
})
|
||||
assert.Equal(t, test.expectedStats, outputStats)
|
||||
driverStatsByVersion, err := statter.GetDriverStats(test.opts.Options)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.expectedStats, driverStatsByVersion["1.0.0+driver"])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ limitations under the License.
|
|||
package stats
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
|
@ -58,7 +57,8 @@ func getConfigStats(dStats *driverStats, configPath string) error {
|
|||
return errors.WithMessagef(err, "config: %s", configPath)
|
||||
}
|
||||
|
||||
slog.Debug("fetching stats", "parsedConfig", driverkitYaml)
|
||||
root.Printer.Logger.Debug("fetching stats",
|
||||
root.Printer.Logger.Args("parsedConfig", driverkitYaml))
|
||||
|
||||
if driverkitYaml.Output.Probe != "" {
|
||||
dStats.NumProbes++
|
||||
|
|
|
@ -15,7 +15,6 @@ limitations under the License.
|
|||
package stats
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
|
@ -39,10 +38,8 @@ func (f *s3Statter) Info() string {
|
|||
}
|
||||
|
||||
func (s *s3Statter) GetDriverStats(opts root.Options) (driverStatsByDriverVersion, error) {
|
||||
slog.SetDefault(slog.With("bucket", s3utils.S3Bucket))
|
||||
|
||||
driverStatsByVersion := make(driverStatsByDriverVersion)
|
||||
err := s.LoopFiltered(opts, "computing stats", "key", func(driverVersion, key string) error {
|
||||
err := s.LoopFiltered(opts, "computing stats for S3 bucket "+s3utils.S3Bucket, "key", func(driverVersion, key string) error {
|
||||
dStats := driverStatsByVersion[driverVersion]
|
||||
if strings.HasSuffix(key, ".ko") {
|
||||
dStats.NumModules++
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
@ -53,7 +52,8 @@ func (cl *Client) LoopFiltered(opts root.Options,
|
|||
}
|
||||
})
|
||||
for p.HasMorePages() {
|
||||
slog.Debug("fetched a page of objects", "prefix", prefix)
|
||||
root.Printer.Logger.Debug("fetched a page of objects",
|
||||
root.Printer.Logger.Args("prefix", prefix))
|
||||
page, err := p.NextPage(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -66,7 +66,8 @@ func (cl *Client) LoopFiltered(opts root.Options,
|
|||
key := filepath.Base(*object.Key)
|
||||
matches := s3DriverNameRegex.FindStringSubmatch(key)
|
||||
if len(matches) == 0 {
|
||||
slog.Warn("skipping key, malformed", "key", key)
|
||||
root.Printer.Logger.Warn("skipping key, malformed",
|
||||
root.Printer.Logger.Args("key", key))
|
||||
continue
|
||||
}
|
||||
for i, name := range s3DriverNameRegex.SubexpNames() {
|
||||
|
@ -87,9 +88,10 @@ func (cl *Client) LoopFiltered(opts root.Options,
|
|||
}
|
||||
}
|
||||
}
|
||||
slog.Info(message, tag, key)
|
||||
root.Printer.Logger.Info(message,
|
||||
root.Printer.Logger.Args(tag, key))
|
||||
if opts.DryRun {
|
||||
slog.Info("skipping because of dry-run.")
|
||||
root.Printer.Logger.Info("skipping because of dry-run.")
|
||||
return nil
|
||||
}
|
||||
err = keyProcessor(driverVersion, filepath.Join(prefix, key))
|
||||
|
|
|
@ -21,8 +21,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -34,25 +32,30 @@ import (
|
|||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/falcosecurity/dbg-go/pkg/root"
|
||||
s3utils "github.com/falcosecurity/dbg-go/pkg/utils/s3"
|
||||
"github.com/falcosecurity/falcoctl/pkg/output"
|
||||
"github.com/johannesboyne/gofakes3"
|
||||
"github.com/johannesboyne/gofakes3/backend/s3mem"
|
||||
json "github.com/json-iterator/go"
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func RunTestParsingLogs(t *testing.T, runTest func() error, parsedMsg interface{}, parsingCB func() bool) {
|
||||
func RunTestParsingLogs(t *testing.T, runTest func() error, parsingCB func([]byte) bool) {
|
||||
var buf bytes.Buffer
|
||||
logger := slog.New(slog.NewJSONHandler(io.Writer(&buf), nil))
|
||||
slog.SetDefault(logger)
|
||||
|
||||
// disable styling for tests and set json format
|
||||
printer := root.Printer
|
||||
root.Printer = output.NewPrinter(pterm.LogLevelInfo, pterm.LogFormatterJSON, &buf)
|
||||
defer func() {
|
||||
// reset default printer
|
||||
root.Printer = printer
|
||||
}()
|
||||
|
||||
err := runTest()
|
||||
assert.NoError(t, err)
|
||||
|
||||
scanner := bufio.NewScanner(&buf)
|
||||
for scanner.Scan() {
|
||||
err = json.Unmarshal(scanner.Bytes(), parsedMsg)
|
||||
assert.NoError(t, err)
|
||||
if parsingCB() == false {
|
||||
if parsingCB(scanner.Bytes()) == false {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package validate
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -28,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
func Run(opts Options) error {
|
||||
slog.Info("validate config files")
|
||||
root.Printer.Logger.Info("validate config files")
|
||||
looper := root.NewFsLooper(root.BuildConfigPath)
|
||||
return looper.LoopFiltered(opts.Options, "validating", "config", func(driverVersion, configPath string) error {
|
||||
return validateConfig(configPath, opts, driverVersion)
|
||||
|
@ -51,11 +50,12 @@ func validateConfig(configPath string, opts Options, driverVersion string) error
|
|||
return errors.WithMessagef(err, "config: %s", configPath)
|
||||
}
|
||||
|
||||
slog.Info("validating",
|
||||
"config", configPath,
|
||||
"target", driverkitYaml.Target,
|
||||
"kernelrelease", driverkitYaml.KernelRelease,
|
||||
"kernelversion", driverkitYaml.KernelVersion)
|
||||
root.Printer.Logger.Info("validating",
|
||||
root.Printer.Logger.Args(
|
||||
"config", configPath,
|
||||
"target", driverkitYaml.Target,
|
||||
"kernelrelease", driverkitYaml.KernelRelease,
|
||||
"kernelversion", driverkitYaml.KernelVersion))
|
||||
|
||||
// Check that filename is ok
|
||||
expectedFilename := driverkitYaml.ToConfigName()
|
||||
|
@ -88,7 +88,8 @@ func validateConfig(configPath string, opts Options, driverVersion string) error
|
|||
|
||||
if !kr.SupportsProbe() {
|
||||
// Not an error, just throw a warning
|
||||
slog.Warn("output probe set on an unsupported kernel release", "kernelrelease", driverkitYaml.KernelRelease)
|
||||
root.Printer.Logger.Warn("output probe set on an unsupported kernel release",
|
||||
root.Printer.Logger.Args("kernelrelease", driverkitYaml.KernelRelease))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +106,8 @@ func validateConfig(configPath string, opts Options, driverVersion string) error
|
|||
|
||||
if !kr.SupportsModule() {
|
||||
// Not an error, just throw a warning
|
||||
slog.Warn("output module set on an unsupported kernel release", "kernelrelease", driverkitYaml.KernelRelease)
|
||||
root.Printer.Logger.Warn("output module set on an unsupported kernel release",
|
||||
root.Printer.Logger.Args("kernelrelease", driverkitYaml.KernelRelease))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
package validate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -455,8 +456,9 @@ func TestValidateConfigFiltered(t *testing.T) {
|
|||
func() error {
|
||||
return Run(test.opts)
|
||||
},
|
||||
&messageJSON,
|
||||
func() bool {
|
||||
func(line []byte) bool {
|
||||
err = json.Unmarshal(line, &messageJSON)
|
||||
assert.NoError(t, err)
|
||||
if messageJSON.Config == "" {
|
||||
return true // go on
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue