Skip to content

Commit

Permalink
build: go: switch rules location (#1772)
Browse files Browse the repository at this point in the history
* build: go: switch rules location

The recommended ruleset was moved from dd-trace-go/internal/appsec/rules.json to appsec-internal-go/appsec/rules.json. Since this script references the rules location to extract its version, we need to modify it

* add appsec-internal-go as contigent when the ruleset is not available in dd-trace-go
  • Loading branch information
eliottness authored Oct 30, 2023
1 parent 9964dbc commit c80bced
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions utils/build/docker/golang/install_ddtrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ fi
go mod tidy

# Read the library version out of the version.go file
mod_dir=$(go list -f '{{.Dir}}' -m gopkg.in/DataDog/dd-trace-go.v1)
version=$(sed -nrE 's#.*"v(.*)".*#\1#p' $mod_dir/internal/version/version.go) # Parse the version string content "v.*"
lib_mod_dir=$(go list -f '{{.Dir}}' -m gopkg.in/DataDog/dd-trace-go.v1)
version=$(sed -nrE 's#.*"v(.*)".*#\1#p' $lib_mod_dir/internal/version/version.go) # Parse the version string content "v.*"
echo $version > SYSTEM_TESTS_LIBRARY_VERSION

touch SYSTEM_TESTS_LIBDDWAF_VERSION

rules_mod_dir=$(go list -f '{{.Dir}}' -m github.com/DataDog/appsec-internal-go)

# Read the rule file version
if [[ -f $mod_dir/internal/appsec/rules.json ]]; then
# Parse the appsec rules version string out of the inlined rules json
rules_version=$(jq -r .metadata.rules_version $mod_dir/internal/appsec/rules.json)
elif [[ $(cat $mod_dir/internal/appsec/rule.go) =~ rules_version\\\":\\\"([[:digit:].-]+)\\\" ]]; then
if [[ -f $lib_mod_dir/internal/appsec/rules.json ]]; then
# Look for the ruleset in dd-trace-go
rules_version=$(jq -r .metadata.rules_version $lib_mod_dir/internal/appsec/rules.json)
elif [[ -f $rules_mod_dir/appsec/rules.json ]]; then
# Look for the ruleset in appsec-internal-go
rules_version=$(jq -r .metadata.rules_version $rules_mod_dir/appsec/rules.json)
elif [[ $(cat $rules_mod_dir/appsec/rules.go) =~ rules_version\\\":\\\"([[:digit:].-]+)\\\" ]]; then
# Parse the appsec rules version string out of the inlined rules json
rules_version="${BASH_REMATCH[1]}"
else
Expand Down

0 comments on commit c80bced

Please sign in to comment.