-
-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: registers RegisterFormatter
s for tinygo
#1027
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f824cfb
json formatter tinygo
M4tteoP 522eae6
registers formatters
M4tteoP 723399f
tries multiple go versions with latest tinygo
M4tteoP b747632
try tinygo 0.30
M4tteoP f26911f
try tinygo 0.30.0
M4tteoP 6d90828
try tinygo 0.28.1
M4tteoP 5ba7e60
tests names, tinygo 0.31.2
M4tteoP 2e08575
Merge branch 'main' into json_tinygo
M4tteoP e8355fe
nit: removed unneeded Tiny suffixes
M4tteoP 65ace81
avoids new declaration redeclaring Serial writer
M4tteoP 1a6bba0
Registers serialWriter to write on stdout or stderr
M4tteoP 60a6baa
Merge branch 'main' into json_tinygo
M4tteoP def8f8f
Merge branch 'main' into json_tinygo
M4tteoP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build tinygo | ||
// +build tinygo | ||
|
||
// Aimed to tinygo, initializing a dedicated serial writer | ||
package plugins_test | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/corazawaf/coraza/v3" | ||
"github.com/corazawaf/coraza/v3/experimental/plugins" | ||
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" | ||
) | ||
|
||
type testFormatter struct{} | ||
|
||
func (testFormatter) Format(al plugintypes.AuditLog) ([]byte, error) { | ||
return []byte(al.Transaction().ID()), nil | ||
} | ||
|
||
func (testFormatter) MIME() string { | ||
return "sample" | ||
} | ||
|
||
// ExampleRegisterAuditLogFormatter shows how to register a custom audit log formatter | ||
// and tests the output of the formatter. | ||
func ExampleRegisterAuditLogFormatter() { | ||
|
||
plugins.RegisterAuditLogWriter("wasmserial", func() plugintypes.AuditLogWriter { | ||
return &wasmSerial{} | ||
}) | ||
|
||
plugins.RegisterAuditLogFormatter("txid", &testFormatter{}) | ||
|
||
w, err := coraza.NewWAF( | ||
coraza.NewWAFConfig(). | ||
WithDirectives(` | ||
SecAuditEngine On | ||
SecAuditLogParts ABCFHZ | ||
SecAuditLog /dev/stdout | ||
SecAuditLogType wasmserial | ||
SecAuditLogFormat txid | ||
`), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
tx := w.NewTransactionWithID("abc123") | ||
tx.ProcessLogging() | ||
tx.Close() | ||
|
||
// Output: abc123 | ||
} | ||
|
||
// wasmSerial emulates a custom audit log writer that writes to the log in wasm | ||
type wasmSerial struct { | ||
io.Closer | ||
formatter plugintypes.AuditLogFormatter | ||
} | ||
|
||
func (s *wasmSerial) Init(cfg plugintypes.AuditLogConfig) error { | ||
s.formatter = cfg.Formatter | ||
return nil | ||
} | ||
|
||
func (s *wasmSerial) Write(al plugintypes.AuditLog) error { | ||
bts, err := s.formatter.Format(al) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(bts)) | ||
return nil | ||
} | ||
|
||
func (s *wasmSerial) Close() error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not call it wasmSerial but redeclare serial here for tinygo only