Skip to content

Commit

Permalink
Merge pull request #52 from coreruleset/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
theseion authored Nov 19, 2022
2 parents b752cd9 + 0d9cc61 commit 7499b7c
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linters-settings:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- prefix(github.com/theseion/crs-toolchain) # Custom section: groups all imports with the specified Prefix.
- prefix(github.com/coreruleset/crs-toolchain) # Custom section: groups all imports with the specified Prefix.
# - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
Expand Down
18 changes: 9 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ release:
prerelease: auto
dockers:
- image_templates:
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-amd64"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-amd64"
use: buildx
goarch: amd64
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-arm64"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-arm64"
use: buildx
goarch: arm64
build_flag_templates:
- "--platform=linux/arm64"
docker_manifests:
- name_template: "ghcr.io/theseion/crs-toolchain:latest"
- name_template: "ghcr.io/coreruleset/crs-toolchain:latest"
image_templates:
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-amd64"
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-arm64"
- name_template: "ghcr.io/theseion/crs-toolchain:{{ .Version }}"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-amd64"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-arm64"
- name_template: "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}"
image_templates:
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-amd64"
- "ghcr.io/theseion/crs-toolchain:{{ .Version }}-arm64"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-amd64"
- "ghcr.io/coreruleset/crs-toolchain:{{ .Version }}-arm64"
nfpms:
- id: "crs-toolchain"
builds: ["crs-toolchain"]
Expand All @@ -79,7 +79,7 @@ nfpms:
deb:
file_name_template: "{{ .ProjectName }}-{{ .Version }}_{{ .Arch }}"
vendor:
homepage: https://github.com/theseion/crs-toolchain
homepage: https://github.com/coreruleset/crs-toolchain
maintainer: [email protected]
description:
CRS ToolChain helper
Expand Down
2 changes: 1 addition & 1 deletion cmd/flag_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (w *workingDirectory) Type() string {

func findRootDirectory(startPath string) (string, error) {
logger.Trace().Msgf("Searching for root directory starting at %s", startPath)
dataPath := path.Join("data")
dataPath := path.Join("regex-assembly")
currentPath := startPath
// root directory only will have a separator as the last rune
for currentPath[len(currentPath)-1] != filepath.Separator {
Expand Down
10 changes: 5 additions & 5 deletions cmd/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/spf13/cobra"

"github.com/theseion/crs-toolchain/v2/regex"
"github.com/coreruleset/crs-toolchain/v2/regex"
)

// generateCmd represents the generate command
Expand All @@ -31,9 +31,9 @@ func createRegexCommand() *cobra.Command {
Use: "regex",
Short: "Commands that process regular expressions",
Long: `The commands in this group all interact with regular expressions.
For example, they generate regular expressions from data files, update regular expressions
For example, they generate regular expressions from regex-assembly files, update regular expressions
in rule files, or compare the regular expressions in rule files against what would be
generated from the current data file.`,
generated from the current regex-assembly file.`,
}

}
Expand Down Expand Up @@ -72,8 +72,8 @@ func parseRuleId(idAndChainOffset string) error {
return errors.New("failed to match chain offset. Value must not be larger than 255")
}

if !strings.HasSuffix(fileName, ".data") {
fileName += ".data"
if !strings.HasSuffix(fileName, ".ra") {
fileName += ".ra"
}

ruleValues.id = id
Expand Down
14 changes: 7 additions & 7 deletions cmd/regex_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/spf13/cobra"

"github.com/theseion/crs-toolchain/v2/regex"
"github.com/theseion/crs-toolchain/v2/regex/processors"
"github.com/coreruleset/crs-toolchain/v2/regex"
"github.com/coreruleset/crs-toolchain/v2/regex/processors"
)

type ComparisonError struct {
Expand All @@ -46,9 +46,9 @@ This command is mainly used for debugging.
It prints regular expressions in fixed sized chunks and detects the
first change.
You can use this command to quickly check whether any rules are out of
sync with their data file.
sync with their regex-assembly file.
RULE_ID is the ID of the rule, e.g., 932100, or the data file name.
RULE_ID is the ID of the rule, e.g., 932100, or the regex-assembly file name.
If the rule is a chained rule, RULE_ID must be specified with the
offset of the chain from the chain starter rule. For example, to
generate a second level chained rule, RULE_ID would be 932100-chain2.`,
Expand Down Expand Up @@ -88,7 +88,7 @@ generate a second level chained rule, RULE_ID would be 932100-chain2.`,
func buildCompareCommand() {
regexCmd.AddCommand(compareCmd)
compareCmd.Flags().BoolP("all", "a", false, `Instead of supplying a RULE_ID, you can tell the script to
compare all rules from their data files`)
compare all rules from their regex-assembly files`)
}

func rebuildCompareCommand() {
Expand All @@ -110,7 +110,7 @@ func performCompare(processAll bool, ctx *processors.Context) {
return err
}

if path.Ext(dirEntry.Name()) == ".data" {
if path.Ext(dirEntry.Name()) == ".ra" {
subs := regex.RuleIdFileNameRegex.FindAllStringSubmatch(dirEntry.Name(), -1)
if subs == nil {
// continue
Expand Down Expand Up @@ -164,7 +164,7 @@ func processRegexForCompare(ruleId string, chainOffset uint8, regex string, ctxt
}

filePath := matches[0]
logger.Debug().Msgf("Processing data file %s", filePath)
logger.Debug().Msgf("Processing regex-assembly file %s", filePath)

currentRegex := readCurrentRegex(filePath, ruleId, chainOffset)
return compareRegex(filePath, ruleId, chainOffset, regex, currentRegex)
Expand Down
8 changes: 4 additions & 4 deletions cmd/regex_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *compareTestSuite) SetupTest() {
s.NoError(err)
s.tempDir = tempDir

s.dataDir = path.Join(s.tempDir, "data")
s.dataDir = path.Join(s.tempDir, "regex-assembly")
err = os.MkdirAll(s.dataDir, fs.ModePerm)
s.NoError(err)

Expand All @@ -57,7 +57,7 @@ func TestRunCompareTestSuite(t *testing.T) {
}

func (s *compareTestSuite) TestCompare_NormalRuleId() {
s.writeDataFile("123456.data", "")
s.writeDataFile("123456.ra", "")
s.writeRuleFile("123456", `SecRule... "@rx regex" \\`+"\nid:123456")
rootCmd.SetArgs([]string{"-d", s.tempDir, "regex", "compare", "123456"})
cmd, _ := rootCmd.ExecuteC()
Expand All @@ -81,8 +81,8 @@ func (s *compareTestSuite) TestCompare_AllFlag() {
id:123456
SecRule... "@rx oldbar" \
id:123457`)
s.writeDataFile("123456.data", "foo")
s.writeDataFile("123457.data", "bar")
s.writeDataFile("123456.ra", "foo")
s.writeDataFile("123457.ra", "bar")
rootCmd.SetArgs([]string{"-d", s.tempDir, "regex", "compare", "--all"})
cmd, _ := rootCmd.ExecuteC()

Expand Down
20 changes: 10 additions & 10 deletions cmd/regex_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

"github.com/spf13/cobra"

"github.com/theseion/crs-toolchain/v2/regex"
"github.com/theseion/crs-toolchain/v2/regex/parser"
"github.com/theseion/crs-toolchain/v2/regex/processors"
"github.com/coreruleset/crs-toolchain/v2/regex"
"github.com/coreruleset/crs-toolchain/v2/regex/parser"
"github.com/coreruleset/crs-toolchain/v2/regex/processors"
)

// formatCmd represents the generate command
Expand All @@ -38,16 +38,16 @@ func init() {
func createFormatCommand() *cobra.Command {
return &cobra.Command{
Use: "format [RULE_ID | INCLUDE_NAME]",
Short: "Format one or more regular expression data files",
Long: `Format one or more reguler expression data files.
Short: "Format one or more regular expression regex-assembly files",
Long: `Format one or more reguler expression regex-assembly files.
RULE_ID is the ID of the rule, e.g., 932100, or the data file name.
RULE_ID is the ID of the rule, e.g., 932100, or the regex-assembly file name.
If the rule is a chained rule, RULE_ID must be specified with the
offset of the chain from the chain starter rule. For example, to
generate a second level chained rule, RULE_ID would be 932100-chain2.
INCLUDE_NAME is the name of the a file in the "include" directory.
These files are also data files but don't follow the same naming
INCLUDE_NAME is the name of the file in the "include" directory, without the extension.
These files are also regex-assembly files but don't follow the same naming
scheme, as they don't correspond to any particular rule.`,
Args: cobra.MatchAll(cobra.MaximumNArgs(1), func(cmd *cobra.Command, args []string) error {
allFlag := cmd.Flags().Lookup("all")
Expand All @@ -72,7 +72,7 @@ scheme, as they don't correspond to any particular rule.`,
} else {
filename := args[0]
if path.Ext(filename) == "" {
filename += ".data"
filename += ".ra"
}
filePath := path.Join(ctxt.RootContext().IncludeDir(), filename)
if err = parseRuleId(filename); err == nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func processAll(ctxt *processors.Context) error {
return nil
}

if path.Ext(d.Name()) == ".data" {
if path.Ext(d.Name()) == ".ra" {
return processFile(filePath, ctxt)
}
return nil
Expand Down
Loading

0 comments on commit 7499b7c

Please sign in to comment.