Skip to content

Commit

Permalink
Use Go embed for normalizations.yaml data (elastic#104)
Browse files Browse the repository at this point in the history
* Use Go embed for normalizations.yaml data

* No need for project symlink in GOPATH with go modules

* Add editorconfig
  • Loading branch information
andrewkroh committed Feb 7, 2022
1 parent b9766df commit 6db53d8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 182 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://editorconfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.go]
indent_style = tab
indent_size = 4
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Update syscall, arches, and audit msg type tables for Linux 5.16. [#96](https://github.com/elastic/go-libaudit/pull/96)
- Go 1.16 or newer is required because the project uses the embed package. [#104](https://github.com/elastic/go-libaudit/pull/104)
- Fixed error messages from `AddRule()` in the audit client. [#103](https://github.com/elastic/go-libaudit/pull/103)

### Removed
Expand Down
8 changes: 3 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
GO_VERSION = File.read(File.join(File.dirname(__FILE__), ".go-version")).strip

create_symlink = <<SCRIPT
echo 'Creating github.com/elastic in the GOPATH'
mkdir -p ~/go/src/github.com/elastic
echo 'Symlinking /vagrant to ~/go/src/github.com/elastic'
cd ~/go/src/github.com/elastic
if [ -d "/vagrant" ] && [ ! -e "go-libaudit" ]; then ln -s /vagrant go-libaudit; fi
echo "Creating go-libaudit symlink in $HOME"
cd $HOME
if [ -d "/vagrant" ] && [ ! -e "go-libaudit" ]; then ln -s /vagrant go-libaudit; fi
SCRIPT

install_gvm = <<SCRIPT
Expand Down
126 changes: 0 additions & 126 deletions aucoalesce/mknormalize_data.go

This file was deleted.

14 changes: 6 additions & 8 deletions aucoalesce/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@
package aucoalesce

import (
_ "embed"
"fmt"
"strings"

"gopkg.in/yaml.v2"
)

//go:generate sh -c "go run mknormalize_data.go normalizationData normalizations.yaml > znormalize_data.go"

var (
//go:embed normalizations.yaml
normalizationDataYAML []byte

syscallNorms map[string]*Normalization
recordTypeNorms map[string][]*Normalization
)

func init() {
data, err := asset("normalizationData")
if err != nil {
panic("normalizationData not found in assets")
}

syscallNorms, recordTypeNorms, err = LoadNormalizationConfig(data)
var err error
syscallNorms, recordTypeNorms, err = LoadNormalizationConfig(normalizationDataYAML)
if err != nil {
panic(fmt.Errorf("failed to parse built in normalization mappings: %w", err))
}
Expand Down
42 changes: 0 additions & 42 deletions aucoalesce/znormalize_data.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/elastic/go-libaudit/v2

go 1.14
go 1.16

require (
github.com/davecgh/go-spew v1.1.0 // indirect
Expand Down

0 comments on commit 6db53d8

Please sign in to comment.