Skip to content

Commit

Permalink
Fixed issues in the generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
valllabh committed Jan 8, 2024
1 parent 08afbb9 commit 7562b14
Show file tree
Hide file tree
Showing 20 changed files with 33,396 additions and 171,466 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ ocsf-tool
schema

# Ignore proto directory
proto
proto

schema.json
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ create-proto-files:

compile-proto: clean-output
@echo "Compiling proto files..."
buf generate
/home/linuxbrew/.linuxbrew/bin/buf generate

@echo "Preparing Enum Value Map..."
bash ./enum-value/enum-value-map.sh

clean-output:
@echo "Cleaning output directory..."
rm -rf ./ocsf

generate-documentation:
gomarkdoc ./ >> docs.md

build: create-proto-files compile-proto
@echo "Building Finished."
29 changes: 29 additions & 0 deletions enum-value/enum-value-map.go.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package enumValueMap

import (
"embed"
"encoding/json"
)

//go:embed enum-value-map.json
var embedFs embed.FS

// struct to hold the enum value
type EnumValue struct {
Name string `json:"name"`
Value int64 `json:"value"`
}

type EnumValueMap = map[string]EnumValue

var enumValueMap EnumValueMap

func init() {
data, _ := embedFs.ReadFile("enum-value-map.json")
json.Unmarshal(data, &enumValueMap)
}

func GetEnumValue(name string) (EnumValue, bool) {
enumValue, enumValueExits := enumValueMap[name]
return enumValue, enumValueExits
}
31 changes: 31 additions & 0 deletions enum-value/enum-value-map.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash


while IFS= read -r -d '' enumValueMapJson; do
echo "Processing $enumValueMapJson"

# replace proto from $file
newEnumValueMapJson=${enumValueMapJson/proto\//}
newEnumValueMapJson=${enumValueMapJson/enum-value-map.json/enum-value-map/enum-value-map.json/}

# create directory if not exist
mkdir -p $(dirname $newEnumValueMapJson)

# copy file
echo "Creating to $newEnumValueMapJson"
cp $enumValueMapJson $newEnumValueMapJson

# replace enum-value-map.json to enum-value-map.go.template from $newFile
enumValueMapGoFile=${newEnumValueMapJson/enum-value-map.json/enum-value-map/map.go}

# create directory if not exist
mkdir -p $(dirname $enumValueMapGoFile)

# copy file
echo "Creating to $enumValueMapGoFile"
cp "./enum-value/enum-value-map.go.template" $enumValueMapGoFile

echo ""

done < <(find ./proto -name "enum-value-map.json" -print0)

2,616 changes: 1,324 additions & 1,292 deletions ocsf/v1_0_0/events/application/application.pb.go

Large diffs are not rendered by default.

20,848 changes: 1,297 additions & 19,551 deletions ocsf/v1_0_0/events/application/enums/enums.pb.go

Large diffs are not rendered by default.

1,405 changes: 711 additions & 694 deletions ocsf/v1_0_0/events/discovery/discovery.pb.go

Large diffs are not rendered by default.

Loading

0 comments on commit 7562b14

Please sign in to comment.