-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds context to transaction. (#963)
* feat: adds context to transaction. * feat: uses options instead of functional arguments for NewTransactionWithOptions.
- Loading branch information
Showing
9 changed files
with
146 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package experimental | ||
|
||
import ( | ||
"github.com/corazawaf/coraza/v3/internal/corazawaf" | ||
"github.com/corazawaf/coraza/v3/types" | ||
) | ||
|
||
type Options = corazawaf.Options | ||
|
||
// WAFWithOptions is an interface that allows to create transactions | ||
// with options | ||
type WAFWithOptions interface { | ||
NewTransactionWithOptions(Options) types.Transaction | ||
} |
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,32 @@ | ||
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package experimental_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/corazawaf/coraza/v3" | ||
"github.com/corazawaf/coraza/v3/experimental" | ||
) | ||
|
||
func ExampleWAFWithOptions_NewTransactionWithOptions() { | ||
waf, err := coraza.NewWAF(coraza.NewWAFConfig()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
oWAF, ok := waf.(experimental.WAFWithOptions) | ||
if !ok { | ||
panic("WAF does not implement WAFWithOptions") | ||
} | ||
|
||
tx := oWAF.NewTransactionWithOptions(experimental.Options{ | ||
ID: "abc123", | ||
}) | ||
|
||
fmt.Println("Transaction ID:", tx.ID()) | ||
|
||
// Output: | ||
// Transaction ID: abc123 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,5 +45,6 @@ type MatchedRule interface { | |
Rule() RuleMetadata | ||
|
||
AuditLog() string | ||
|
||
ErrorLog() string | ||
} |
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