Skip to content
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(experimental): adds seclang parser. #1101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions experimental/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Experimental
# Experimental

This is an experimental Go package that provides some new functionality or feature. It's currently under development and should be considered unstable and subject to change. Use at your own risk.
This is an experimental Go package that provides some new functionality or feature. It's currently under development and should be considered unstable and subject to change. Use at your own risk.
45 changes: 45 additions & 0 deletions experimental/seclang/parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0

package seclang

import (
"io/fs"

"github.com/corazawaf/coraza/v3/internal/corazawaf"
"github.com/corazawaf/coraza/v3/internal/io"
"github.com/corazawaf/coraza/v3/internal/seclang"
)

// Parser is an interface for parsing SecLang rules
type Parser interface {
FromFile(string) error
FromString(string) error
}

// ParserConfig is an interface for configuring the parser
type ParserConfig interface {
WithRoot(root fs.FS) ParserConfig
}

// NewParser creates a new SecLang parser
func NewParser(config ParserConfig) Parser {
return seclang.NewParser(corazawaf.NewWAF())
}

type parserConfig struct {
root fs.FS
}

func (c *parserConfig) WithRoot(root fs.FS) ParserConfig {
ret := &parserConfig{root: c.root}
ret.root = root
return ret
}

// NewParserConfig creates a new parser configuration
func NewParserConfig() ParserConfig {
return &parserConfig{
root: io.OSFS{},
}
}
Loading