Skip to content

Commit dc7f703

Browse files
authored
feat(tools): support for arbitrary version download of libddwaf (#84)
Signed-off-by: Eliott Bouhana <[email protected]>
1 parent d64577c commit dc7f703

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

_tools/libddwaf-updater/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/DataDog/go-libddwaf/libddwaf-updater
22

3-
go 1.18
3+
go 1.20
44

55
require (
66
github.com/bitfield/script v0.22.0

_tools/libddwaf-updater/update.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"context"
1212
_ "embed"
1313
"errors"
14+
"flag"
1415
"fmt"
1516
"io"
1617
"os"
@@ -34,24 +35,35 @@ const (
3435
goVersionUnsupported = "go1.23"
3536
)
3637

38+
var (
39+
forceFlag *bool
40+
versionFlag *string
41+
)
42+
3743
func main() {
38-
force := false
3944

40-
if len(os.Args) >= 2 {
41-
force = os.Args[1] == "--force"
42-
}
45+
flag.Parse()
46+
47+
var (
48+
release *github.RepositoryRelease
49+
err error
50+
gh = github.NewClient(nil)
51+
)
4352

44-
gh := github.NewClient(nil)
53+
if *versionFlag == "latest" {
54+
release, _, err = gh.Repositories.GetLatestRelease(context.Background(), "DataDog", "libddwaf")
55+
} else {
56+
release, _, err = gh.Repositories.GetReleaseByTag(context.Background(), "DataDog", "libddwaf", *versionFlag)
57+
}
4558

46-
release, _, err := gh.Repositories.GetLatestRelease(context.Background(), "DataDog", "libddwaf")
4759
if err != nil {
4860
panic(err)
4961
}
5062

5163
version := *release.TagName
5264
if version == currentVersion {
5365
fmt.Printf("Already up-to-date with v%s\n", version)
54-
if force {
66+
if *forceFlag {
5567
fmt.Println("--force is set, re-downloading assets anyway!")
5668
} else {
5769
return
@@ -71,7 +83,7 @@ func main() {
7183
wg := sync.WaitGroup{}
7284
wg.Add(len(targets))
7385
for _, tgt := range targets {
74-
go handleTarget(&wg, version, tgt, assets, force)
86+
go handleTarget(&wg, version, tgt, assets, *forceFlag)
7587
}
7688

7789
wg.Wait()
@@ -298,6 +310,14 @@ func (t target) embedSourceDirective() string {
298310
}
299311

300312
func init() {
313+
314+
forceFlag = flag.Bool("force", false, "Force the download of assets even if the version is the same")
315+
versionFlag = flag.String("version", "latest", "Force the download of assets for a specific version (by git tag), or 'latest' for the latest release")
316+
317+
if forceFlag == nil || versionFlag == nil {
318+
panic("unexpected nil flag")
319+
}
320+
301321
_, filename, _, _ := runtime.Caller(0)
302322
dir := path.Dir(filename)
303323
rootDir = path.Join(dir, "..", "..")

0 commit comments

Comments
 (0)