Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.24"
go-version: "1.26.0"

-
name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ "stable", "oldstable", "1.x" ]
go-version: [ "1.26.0" ]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Build stage
FROM golang:alpine AS builder
FROM golang:1.26.0-alpine3.23 AS builder
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -o baffo ./cmd/baffo/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o baffo ./cmd/baffo/main.go

# Run stage
FROM alpine:latest
FROM scratch
WORKDIR /app
COPY --from=builder /app/baffo ./baffo
COPY --from=builder /app/README.md ./README.md
COPY --from=builder --chown=1000:1000 /app/baffo ./baffo
COPY --from=builder --chown=1000:1000 /app/README.md ./README.md

USER 1000:1000
# Copy any other files needed at runtime here
ENTRYPOINT ["/app/baffo"]
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The main highlight is the transpile command, which converts Logstash pipelines i
You can try out the tool online at https://herrbez.github.io/baffo/. Simply paste your Logstash pipeline and
see the conversion in action.

For more advanced usage—such as converting multiple pipelines or integrating into your workflow—install baffo locally.
For more advanced usage—such as converting multiple pipelines or integrating into your workflow—install baffo locally or use the docker image.


## Installation
Expand All @@ -28,6 +28,10 @@ For more advanced usage—such as converting multiple pipelines or integrating i
go install github.com/herrBez/baffo/cmd/baffo@latest
```

```bash
docker run briomkez/baffo:latest
```


## Name

Expand Down Expand Up @@ -67,7 +71,7 @@ baffo transpile file.conf \
> ⚠️ Disclaimer: Semantic equivalence between the input Logstash pipelines and the generated Elasticsearch ingest pipelines is not formally guaranteed. The output should not be used in production without careful review and testing.


If you need a quick conversion without bothering creating a file you can:
If you need a quick conversion without bothering creating a file you can execute:

```
baffo transpile /dev/stdin --deal_with_error_locally=false \
Expand Down
2 changes: 1 addition & 1 deletion ast/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewNotFoundError(err error) error {

// NotFoundErrorf formats according to a format specifier and returns the string
// as a value that satisfies NotFounder.
func NotFoundErrorf(format string, a ...interface{}) error {
func NotFoundErrorf(format string, a ...any) error {
return NewNotFoundError(fmt.Errorf(format, a...))
}

Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
module github.com/herrBez/baffo

go 1.24
go 1.26

require (
github.com/hashicorp/go-multierror v1.1.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.34.0
github.com/sergi/go-diff v1.4.0
github.com/spf13/cobra v1.10.1
github.com/spf13/viper v1.21.0
go.elastic.co/ecszerolog v0.2.0
)

require github.com/hashicorp/errwrap v1.1.0 // indirect

require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlnd
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
14 changes: 6 additions & 8 deletions internal/app/check/check.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package check

import (
"fmt"
"os"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"errors"

config "github.com/herrBez/baffo"
"github.com/herrBez/baffo/internal/format"
)

type Check struct{}
Expand All @@ -18,12 +17,12 @@ func New() Check {
}

func (f Check) Run(args []string) error {
var result *multierror.Error
var result error

for _, filename := range args {
stat, err := os.Stat(filename)
if err != nil {
result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
}
if stat.IsDir() {
continue
Expand All @@ -33,16 +32,15 @@ func (f Check) Run(args []string) error {
if err != nil {
if errMsg, hasErr := config.GetFarthestFailure(); hasErr {
if !strings.Contains(err.Error(), errMsg) {
err = errors.Errorf("%s: %v\n%s", filename, err, errMsg)
err = fmt.Errorf("%s: %v\n%s", filename, err, errMsg)
}
}
result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
continue
}
}

if result != nil {
result.ErrorFormat = format.MultiErr
return result
}

Expand Down
18 changes: 7 additions & 11 deletions internal/app/ecs_check/ecs_check.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package ecs_check

import (
"fmt"
"log"
"os"

// "strings"
// "fmt"
"github.com/herrBez/baffo/ast/astutil"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"

"errors"
"reflect"

config "github.com/herrBez/baffo"
"github.com/herrBez/baffo/internal/format"

ast "github.com/herrBez/baffo/ast"
)
Expand All @@ -26,12 +24,11 @@ func New() ECSCheck {
}

func (f ECSCheck) Run(args []string) error {
var result *multierror.Error

var result error
for _, filename := range args {
stat, err := os.Stat(filename)
if err != nil {
result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
}
if stat.IsDir() {
continue
Expand All @@ -47,14 +44,14 @@ func (f ECSCheck) Run(args []string) error {

// if errMsg, hasErr := config.GetFarthestFailure(); hasErr {
// if !strings.Contains(err.Error(), errMsg) {
// err = errors.Errorf("%s: %v\n%s", filename, err, errMsg)
// err = fmt.Errorf("%s: %v\n%s", filename, err, errMsg)
// }
// }
// result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
// result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
// continue
} else {
var tree ast.Config = res.(ast.Config)
log.Println(reflect.TypeOf(tree))
log.Println(reflect.TypeFor[ast.Config]())

var input_plugin_names []string = getAllPluginNames(tree.Input)
var filter_plugin_names []string = getAllPluginNames(tree.Filter)
Expand All @@ -69,7 +66,6 @@ func (f ECSCheck) Run(args []string) error {
}

if result != nil {
result.ErrorFormat = format.MultiErr
return result
}

Expand Down
12 changes: 5 additions & 7 deletions internal/app/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"strings"

"github.com/pkg/errors"

config "github.com/herrBez/baffo"
"github.com/herrBez/baffo/ast"
)
Expand All @@ -28,7 +26,7 @@ func (f Format) Run(args []string) error {
for _, filename := range args {
stat, err := os.Stat(filename)
if err != nil {
return errors.Errorf("%s: %v", filename, err)
return fmt.Errorf("%s: %v", filename, err)
}
if stat.IsDir() {
continue
Expand All @@ -38,24 +36,24 @@ func (f Format) Run(args []string) error {
if err != nil {
if errMsg, hasErr := config.GetFarthestFailure(); hasErr {
if !strings.Contains(err.Error(), errMsg) {
return errors.Errorf("%s: %v\n%s", filename, err, errMsg)
return fmt.Errorf("%s: %v\n%s", filename, err, errMsg)
}
}
return errors.Errorf("%s: %v", filename, err)
return fmt.Errorf("%s: %v", filename, err)
}

if f.writeToSource {
err := func() error {
f, err := os.Create(filename)
if err != nil {
return errors.Wrap(err, "failed to open file for writting with automatically fixed ID")
return fmt.Errorf("failed to open file for writting with automatically fixed ID: %w", err)
}
defer f.Close()

conf := c.(ast.Config)
_, err = f.WriteString(conf.String())
if err != nil {
return errors.Wrap(err, "failed to write file with automatically fixed ID")
return fmt.Errorf("failed to write file with automatically fixed ID: %w", err)
}

return nil
Expand Down
28 changes: 11 additions & 17 deletions internal/app/lint/lint.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package lint

import (
"errors"
"fmt"
"os"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"

config "github.com/herrBez/baffo"
"github.com/herrBez/baffo/ast"
"github.com/herrBez/baffo/ast/astutil"
"github.com/herrBez/baffo/internal/format"
)

type Lint struct {
Expand All @@ -25,12 +22,12 @@ func New(autoFixID bool) Lint {
}

func (l Lint) Run(args []string) error {
var result *multierror.Error
var result error

for _, filename := range args {
stat, err := os.Stat(filename)
if err != nil {
result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
}
if stat.IsDir() {
continue
Expand All @@ -40,15 +37,15 @@ func (l Lint) Run(args []string) error {
if err != nil {
if errMsg, hasErr := config.GetFarthestFailure(); hasErr {
if !strings.Contains(err.Error(), errMsg) {
err = errors.Errorf("%s: %v\n%s", filename, err, errMsg)
err = fmt.Errorf("%s: %v\n%s", filename, err, errMsg)
}
}
result = multierror.Append(result, errors.Errorf("%s: %v", filename, err))
result = errors.Join(result, fmt.Errorf("%s: %v", filename, err))
continue
}
conf := c.(ast.Config)
for _, warning := range conf.Warnings {
result = multierror.Append(result, errors.New(warning))
result = errors.Join(result, errors.New(warning))
}

v := validator{
Expand Down Expand Up @@ -76,37 +73,36 @@ func (l Lint) Run(args []string) error {
for _, block := range v.noIDs {
errMsg.WriteString(block + "\n")
}
result = multierror.Append(result, errors.New(errMsg.String()))
result = errors.Join(result, errors.New(errMsg.String()))
}
if len(v.duplicateIDs) > 0 {
errMsg := strings.Builder{}
errMsg.WriteString(fmt.Sprintf("%s: duplicate IDs found in:\n", filename))
for _, block := range v.duplicateIDs {
errMsg.WriteString(block + "\n")
}
result = multierror.Append(result, errors.New(errMsg.String()))
result = errors.Join(result, errors.New(errMsg.String()))
}

if l.autoFixID && v.changed {
func() {
f, err := os.Create(filename)
if err != nil {
result = multierror.Append(result, errors.Wrap(err, "failed to open file for writting with automatically fixed ID"))
result = errors.Join(result, fmt.Errorf("failed to open file for writting with automatically fixed ID: %w", err))
return
}
defer f.Close()

_, err = f.WriteString(conf.String())
if err != nil {
result = multierror.Append(result, errors.Wrap(err, "failed to write file with automatically fixed ID"))
result = errors.Join(result, fmt.Errorf("failed to write file with automatically fixed ID: %w", err))
return
}
}()
}
}

if result != nil {
result.ErrorFormat = format.MultiErr
return result
}

Expand All @@ -131,9 +127,7 @@ func (v *validator) walk(c *astutil.Cursor) {
v.changed = true

plugin := c.Plugin()
// plugin.Attributes = append(plugin.Attributes, ast.NewStringAttribute("id", fmt.Sprintf("%s-%d", c.Plugin().Name(), v.count), ast.DoubleQuoted))

// plugin.Attributes = append(plugin.Attributes, ast.NewStringAttribute("id", fmt.Sprintf("%s", c.Plugin().Name()), ast.DoubleQuoted))
plugin.Attributes = append(plugin.Attributes, ast.NewStringAttribute("id", fmt.Sprintf("%s-%d", c.Plugin().Name(), v.count), ast.DoubleQuoted))

c.Replace(plugin)
} else {
Expand Down
Loading
Loading