From 9e3b7eb4a2dce4acc83e62c59b9b5d87a7932f3b Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 23 Apr 2025 22:17:46 +0200 Subject: [PATCH 01/13] start: init agent project Signed-off-by: GnomeZworc --- cmd/agent/.keep | 0 go.mod | 3 +++ internal/.keep | 0 pkg/.keep | 0 4 files changed, 3 insertions(+) create mode 100644 cmd/agent/.keep create mode 100644 go.mod create mode 100644 internal/.keep create mode 100644 pkg/.keep diff --git a/cmd/agent/.keep b/cmd/agent/.keep new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8978629 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.g3e.fr/syonad + +go 1.23.8 diff --git a/internal/.keep b/internal/.keep new file mode 100644 index 0000000..e69de29 diff --git a/pkg/.keep b/pkg/.keep new file mode 100644 index 0000000..e69de29 From a569cb43f26efea5a5f4c258c90d9d6e3b8189fe Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 3 Dec 2025 23:54:12 +0100 Subject: [PATCH 02/13] start: init metadata serveur Signed-off-by: GnomeZworc --- cmd/metadata/main.go | 5 +++ go.mod | 2 +- internal/metadata/server.go | 75 +++++++++++++++++++++++++++++++++++++ internal/metadata/struct.go | 8 ++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 cmd/metadata/main.go create mode 100644 internal/metadata/server.go create mode 100644 internal/metadata/struct.go diff --git a/cmd/metadata/main.go b/cmd/metadata/main.go new file mode 100644 index 0000000..e97962b --- /dev/null +++ b/cmd/metadata/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + metadata.startServer() +} diff --git a/go.mod b/go.mod index 8978629..3721544 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module git.g3e.fr/syonad +module git.g3e.fr/syonad/two go 1.23.8 diff --git a/internal/metadata/server.go b/internal/metadata/server.go new file mode 100644 index 0000000..d7fc2dd --- /dev/null +++ b/internal/metadata/server.go @@ -0,0 +1,75 @@ +package metadata + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" + "log" + "net" + "net/http" + "time" +) + +var data NoCloudData + +var ( + iface = flag.String("interface", "0.0.0.0", "Interface IP à écouter") + port = flag.Int("port", 8080, "Port à utiliser") + file = flag.String("file", "", "Fichier JSON contenant les données NoCloud") +) + +func getIP(r *http.Request) string { + ip, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + return r.RemoteAddr + } + return ip +} + +func rootHandler(w http.ResponseWriter, r *http.Request) { + ip := getIP(r) + path := r.URL.Path + timestamp := time.Now().Format(time.RFC3339) + userAgent := r.Header.Get("User-Agent") + + log.Printf("[%s] Requête IP %s vers %s | User-Agent: %s", timestamp, ip, path, userAgent) + + w.Header().Set("Content-Type", "text/yaml") + + switch path { + case "/user-data": + fmt.Fprint(w, data.UserData) + case "/meta-data": + fmt.Fprint(w, data.MetaData) + case "/network-config": + fmt.Fprint(w, data.NetworkConfig) + case "/vendor-data": + fmt.Fprint(w, data.VendorData) + default: + http.NotFound(w, r) + } +} + +func startServer() { + flag.Parse() + + if *file == "" { + log.Fatal("Vous devez spécifier un fichier via --file") + } + + raw, err := ioutil.ReadFile(*file) + if err != nil { + log.Fatalf("Erreur de lecture du fichier: %v", err) + } + + if err := json.Unmarshal(raw, &data); err != nil { + log.Fatalf("Erreur de parsing JSON: %v", err) + } + + http.HandleFunc("/", rootHandler) + + address := fmt.Sprintf("%s:%d", *iface, *port) + log.Printf("Serveur NoCloud démarré sur http://%s/", address) + log.Fatal(http.ListenAndServe(address, nil)) +} diff --git a/internal/metadata/struct.go b/internal/metadata/struct.go new file mode 100644 index 0000000..f1edf18 --- /dev/null +++ b/internal/metadata/struct.go @@ -0,0 +1,8 @@ +package metadata + +type NoCloudData struct { + MetaData string `json:"meta-data"` + UserData string `json:"user-data"` + NetworkConfig string `json:"network-config"` + VendorData string `json:"vendor-data"` +} From 3b64498086b677cd2417f6c26d8cccc2fc6e7584 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 4 Dec 2025 00:00:14 +0100 Subject: [PATCH 03/13] start: fix non fonctional metadata server Signed-off-by: GnomeZworc --- cmd/metadata/main.go | 6 +++++- internal/metadata/server.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/metadata/main.go b/cmd/metadata/main.go index e97962b..54bae88 100644 --- a/cmd/metadata/main.go +++ b/cmd/metadata/main.go @@ -1,5 +1,9 @@ package main +import ( + "git.g3e.fr/syonad/two/internal/metadata" +) + func main() { - metadata.startServer() + metadata.StartServer() } diff --git a/internal/metadata/server.go b/internal/metadata/server.go index d7fc2dd..336f754 100644 --- a/internal/metadata/server.go +++ b/internal/metadata/server.go @@ -51,7 +51,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { } } -func startServer() { +func StartServer() { flag.Parse() if *file == "" { From 786e0f03f8baf2c88dc173111620db2eef1040c4 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 10 Dec 2025 20:38:51 +0100 Subject: [PATCH 04/13] start: add a first db in golang Signed-off-by: GnomeZworc --- cmd/db/main.go | 184 ++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 18 +++++ pkg/db/kv/init.go | 19 +++++ 3 files changed, 221 insertions(+) create mode 100644 cmd/db/main.go create mode 100644 pkg/db/kv/init.go diff --git a/cmd/db/main.go b/cmd/db/main.go new file mode 100644 index 0000000..fd7d09a --- /dev/null +++ b/cmd/db/main.go @@ -0,0 +1,184 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "git.g3e.fr/syonad/two/pkg/db/kv" + "github.com/dgraph-io/badger/v4" +) + +var DB *badger.DB + +func CheckInDB(dbName, id string) int { + prefix := []byte(dbName + "/bash/") + key := []byte(dbName + "/bash/" + id) + + // vérifier si DB contient au moins une entrée avec ce préfixe + hasPrefix := false + + DB.View(func(txn *badger.Txn) error { + it := txn.NewIterator(badger.DefaultIteratorOptions) + defer it.Close() + it.Seek(prefix) + if it.ValidForPrefix(prefix) { + hasPrefix = true + } + return nil + }) + + if !hasPrefix { + return 1 + } + + // vérifier si la clé existe + err := DB.View(func(txn *badger.Txn) error { + _, err := txn.Get(key) + return err + }) + + if err == badger.ErrKeyNotFound { + return 2 + } + + return 0 +} + +func AddInDB(dbName string, line string) error { + // ID = partie avant le premier ';' + id := strings.Split(line, ";")[0] + key := []byte(dbName + "/bash/" + id) + + return DB.Update(func(txn *badger.Txn) error { + return txn.Set(key, []byte(line)) + }) +} + +func DeleteInDB(dbName, id string) error { + key := []byte(dbName + "/bash/" + id) + + return DB.Update(func(txn *badger.Txn) error { + return txn.Delete(key) + }) +} + +func CountInDB(dbName, id string) int { + prefix := []byte(dbName + "/bash/" + id) + count := 0 + + DB.View(func(txn *badger.Txn) error { + it := txn.NewIterator(badger.DefaultIteratorOptions) + defer it.Close() + + for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() { + count++ + } + return nil + }) + + return count +} + +func GetFromDB(dbName, id string) (string, error) { + key := []byte(dbName + "/bash/" + id) + + var result string + + err := DB.View(func(txn *badger.Txn) error { + item, err := txn.Get(key) + if err != nil { + return err + } + return item.Value(func(val []byte) error { + result = string(val) + return nil + }) + }) + + return result, err +} + +func printDB() { + err := DB.View(func(txn *badger.Txn) error { + it := txn.NewIterator(badger.DefaultIteratorOptions) + defer it.Close() + + for it.Rewind(); it.Valid(); it.Next() { + item := it.Item() + key := item.Key() + err := item.Value(func(val []byte) error { + fmt.Printf("%s:%s\n", string(key), string(val)) + return nil + }) + if err != nil { + return err + } + } + return nil + }) + + if err != nil { + fmt.Println("Error reading DB:", err) + } +} + +func main() { + DB = kv.InitDB() + defer DB.Close() + + printDB() + + if len(os.Args) < 2 { + fmt.Println("Usage: db [args...]") + return + } + + cmd := os.Args[1] + + switch cmd { + case "check_in_db": + if len(os.Args) != 4 { + fmt.Println("Usage: check_in_db ") + os.Exit(1) + } + ret := CheckInDB(os.Args[2], os.Args[3]) + os.Exit(ret) + case "add_in_db": + if len(os.Args) < 4 { + fmt.Println("Usage: add_in_db ") + os.Exit(1) + } + line := strings.Join(os.Args[3:], ";") + if err := AddInDB(os.Args[2], line); err != nil { + fmt.Println("Error:", err) + os.Exit(1) + } + case "delete_in_db": + if len(os.Args) != 4 { + fmt.Println("Usage: delete_in_db ") + os.Exit(1) + } + if err := DeleteInDB(os.Args[2], os.Args[3]); err != nil { + fmt.Println("Error:", err) + os.Exit(1) + } + case "count_in_db": + if len(os.Args) != 4 { + fmt.Println("Usage: count_in_db ") + os.Exit(1) + } + count := CountInDB(os.Args[2], os.Args[3]) + fmt.Println(count) + case "get_from_db": + if len(os.Args) != 4 { + fmt.Println("Usage: get_from_db ") + os.Exit(1) + } + line, _ := GetFromDB(os.Args[2], os.Args[3]) + fmt.Println(line) + default: + fmt.Println("Unknown command:", cmd) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod index 3721544..e348de1 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,21 @@ module git.g3e.fr/syonad/two go 1.23.8 + +require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/dgraph-io/badger/v4 v4.8.0 // indirect + github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/flatbuffers v25.2.10+incompatible // indirect + github.com/klauspost/compress v1.18.0 // indirect + go.opentelemetry.io/auto/sdk v1.1.0 // indirect + go.opentelemetry.io/otel v1.37.0 // indirect + go.opentelemetry.io/otel/metric v1.37.0 // indirect + go.opentelemetry.io/otel/trace v1.37.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sys v0.34.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect +) diff --git a/pkg/db/kv/init.go b/pkg/db/kv/init.go new file mode 100644 index 0000000..ebc2f1f --- /dev/null +++ b/pkg/db/kv/init.go @@ -0,0 +1,19 @@ +package kv + +import ( + "github.com/dgraph-io/badger/v4" +) + +func InitDB() *badger.DB { + opts := badger.DefaultOptions("./data") + opts.Logger = nil + opts.ValueLogFileSize = 10 << 20 // 10 Mo par fichier vlog + opts.NumMemtables = 1 + opts.NumLevelZeroTables = 1 + opts.NumLevelZeroTablesStall = 2 + db, err := badger.Open(opts) + if err != nil { + panic(err) + } + return db +} From 568098af1de7d5f89d9309b194a9784bd178f6b7 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 11 Dec 2025 21:43:48 +0100 Subject: [PATCH 05/13] start: add config struct for db path Signed-off-by: GnomeZworc --- cmd/db/main.go | 6 +++++- pkg/db/kv/init.go | 4 ++-- pkg/db/kv/struct.go | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 pkg/db/kv/struct.go diff --git a/cmd/db/main.go b/cmd/db/main.go index fd7d09a..6dbbca4 100644 --- a/cmd/db/main.go +++ b/cmd/db/main.go @@ -124,7 +124,11 @@ func printDB() { } func main() { - DB = kv.InitDB() + var conf kv.Config = kv.Config{ + Path: "./data/", + } + + DB = kv.InitDB(conf) defer DB.Close() printDB() diff --git a/pkg/db/kv/init.go b/pkg/db/kv/init.go index ebc2f1f..18148df 100644 --- a/pkg/db/kv/init.go +++ b/pkg/db/kv/init.go @@ -4,8 +4,8 @@ import ( "github.com/dgraph-io/badger/v4" ) -func InitDB() *badger.DB { - opts := badger.DefaultOptions("./data") +func InitDB(conf Config) *badger.DB { + opts := badger.DefaultOptions(conf.Path) opts.Logger = nil opts.ValueLogFileSize = 10 << 20 // 10 Mo par fichier vlog opts.NumMemtables = 1 diff --git a/pkg/db/kv/struct.go b/pkg/db/kv/struct.go new file mode 100644 index 0000000..71b195f --- /dev/null +++ b/pkg/db/kv/struct.go @@ -0,0 +1,5 @@ +package kv + +type Config struct { + Path string +} From 115456258cea5ae488e8e45b8d9e6a3c972c99ee Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sat, 13 Dec 2025 00:14:18 +0100 Subject: [PATCH 06/13] start: add config system Signed-off-by: GnomeZworc --- cmd/db/main.go | 25 +++++++++++++++---------- go.mod | 12 ++++++++++++ internal/config/struct.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 internal/config/struct.go diff --git a/cmd/db/main.go b/cmd/db/main.go index 6dbbca4..e17dd6f 100644 --- a/cmd/db/main.go +++ b/cmd/db/main.go @@ -5,6 +5,7 @@ import ( "os" "strings" + "git.g3e.fr/syonad/two/internal/config" "git.g3e.fr/syonad/two/pkg/db/kv" "github.com/dgraph-io/badger/v4" ) @@ -12,8 +13,8 @@ import ( var DB *badger.DB func CheckInDB(dbName, id string) int { - prefix := []byte(dbName + "/bash/") - key := []byte(dbName + "/bash/" + id) + prefix := []byte(dbName + "/") + key := []byte(dbName + "/" + id) // vérifier si DB contient au moins une entrée avec ce préfixe hasPrefix := false @@ -47,8 +48,8 @@ func CheckInDB(dbName, id string) int { func AddInDB(dbName string, line string) error { // ID = partie avant le premier ';' - id := strings.Split(line, ";")[0] - key := []byte(dbName + "/bash/" + id) + id := strings.Split(line, ";")[0] + "/bash" + key := []byte(dbName + "/" + id) return DB.Update(func(txn *badger.Txn) error { return txn.Set(key, []byte(line)) @@ -56,7 +57,7 @@ func AddInDB(dbName string, line string) error { } func DeleteInDB(dbName, id string) error { - key := []byte(dbName + "/bash/" + id) + key := []byte(dbName + "/" + id + "/bash") return DB.Update(func(txn *badger.Txn) error { return txn.Delete(key) @@ -64,7 +65,7 @@ func DeleteInDB(dbName, id string) error { } func CountInDB(dbName, id string) int { - prefix := []byte(dbName + "/bash/" + id) + prefix := []byte(dbName + "/" + id + "/bash") count := 0 DB.View(func(txn *badger.Txn) error { @@ -81,7 +82,7 @@ func CountInDB(dbName, id string) int { } func GetFromDB(dbName, id string) (string, error) { - key := []byte(dbName + "/bash/" + id) + key := []byte(dbName + "/" + id + "/bash") var result string @@ -124,11 +125,15 @@ func printDB() { } func main() { - var conf kv.Config = kv.Config{ - Path: "./data/", + configuration, err := config.LoadConfig("./two.yaml") + if err != nil { + fmt.Println(err) + return } - DB = kv.InitDB(conf) + DB = kv.InitDB(kv.Config{ + Path: configuration.Database.Path, + }) defer DB.Close() printDB() diff --git a/go.mod b/go.mod index e348de1..cbc34b5 100644 --- a/go.mod +++ b/go.mod @@ -7,15 +7,27 @@ require ( github.com/dgraph-io/badger/v4 v4.8.0 // indirect github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/google/flatbuffers v25.2.10+incompatible // indirect github.com/klauspost/compress v1.18.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/spf13/viper v1.21.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/otel v1.37.0 // indirect go.opentelemetry.io/otel/metric v1.37.0 // indirect go.opentelemetry.io/otel/trace v1.37.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/net v0.41.0 // indirect golang.org/x/sys v0.34.0 // indirect + golang.org/x/text v0.28.0 // indirect google.golang.org/protobuf v1.36.6 // indirect ) diff --git a/internal/config/struct.go b/internal/config/struct.go new file mode 100644 index 0000000..a3708fb --- /dev/null +++ b/internal/config/struct.go @@ -0,0 +1,30 @@ +package config + +import ( + "github.com/spf13/viper" +) + +type Config struct { + Database struct { + Path string `mapstructure:"path"` + } `mapstructure:"database"` +} + +func LoadConfig(path string) (*Config, error) { + v := viper.New() + v.SetConfigFile(path) + v.SetConfigType("yaml") + + v.SetDefault("database.path", "./data/") + + if err := v.ReadInConfig(); err != nil { + return nil, err + } + + var cfg Config + if err := v.Unmarshal(&cfg); err != nil { + return nil, err + } + + return &cfg, nil +} From 518e2010cd66365f0a803d6dc6b5add3cf36a570 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sat, 13 Dec 2025 00:17:08 +0100 Subject: [PATCH 07/13] start: add db dir in gitignore Signed-off-by: GnomeZworc --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5b90e79..3a0b507 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ go.work.sum # env file .env +# ignore local info +data/ \ No newline at end of file From c7bb3b353f5b442b4d71da3f35969fd308a1c65e Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sat, 13 Dec 2025 00:25:44 +0100 Subject: [PATCH 08/13] start: rename config for split agent and futur intel Signed-off-by: GnomeZworc --- cmd/db/main.go | 11 ++++++----- internal/config/{ => agent}/struct.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) rename internal/config/{ => agent}/struct.go (95%) diff --git a/cmd/db/main.go b/cmd/db/main.go index e17dd6f..898d4c7 100644 --- a/cmd/db/main.go +++ b/cmd/db/main.go @@ -5,7 +5,7 @@ import ( "os" "strings" - "git.g3e.fr/syonad/two/internal/config" + configuration "git.g3e.fr/syonad/two/internal/config/agent" "git.g3e.fr/syonad/two/pkg/db/kv" "github.com/dgraph-io/badger/v4" ) @@ -125,19 +125,17 @@ func printDB() { } func main() { - configuration, err := config.LoadConfig("./two.yaml") + conf, err := configuration.LoadConfig("./two.yaml") if err != nil { fmt.Println(err) return } DB = kv.InitDB(kv.Config{ - Path: configuration.Database.Path, + Path: conf.Database.Path, }) defer DB.Close() - printDB() - if len(os.Args) < 2 { fmt.Println("Usage: db [args...]") return @@ -186,6 +184,9 @@ func main() { } line, _ := GetFromDB(os.Args[2], os.Args[3]) fmt.Println(line) + case "print": + printDB() + os.Exit(1) default: fmt.Println("Unknown command:", cmd) os.Exit(1) diff --git a/internal/config/struct.go b/internal/config/agent/struct.go similarity index 95% rename from internal/config/struct.go rename to internal/config/agent/struct.go index a3708fb..b19d6da 100644 --- a/internal/config/struct.go +++ b/internal/config/agent/struct.go @@ -1,4 +1,4 @@ -package config +package configuration import ( "github.com/spf13/viper" From fb7f44a31a77076d41ebf0ed74d1a1acf5f1bc23 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sun, 14 Dec 2025 22:14:19 +0100 Subject: [PATCH 09/13] start: add ci Signed-off-by: GnomeZworc --- .forgejo/workflows/build.yml | 43 ++++++++++++++++++++++++ .forgejo/workflows/prerelease.yml | 55 ++++++++++++++++++++++++++++++ .forgejo/workflows/release.yml | 56 +++++++++++++++++++++++++++++++ go.sum | 56 +++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 .forgejo/workflows/build.yml create mode 100644 .forgejo/workflows/prerelease.yml create mode 100644 .forgejo/workflows/release.yml create mode 100644 go.sum diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..9cd29e6 --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,43 @@ +on: + workflow_call: + inputs: + tag: + required: true + type: string + goos: + required: true + type: string + goarch: + required: true + type: string + binari: + required: true + type: string + +jobs: + build: + runs-on: docker + env: + RELEASE_CIBLE: ${{ inputs.tag }} + GOOS: ${{ inputs.goos }} + GOARCH: ${{ inputs.goarch }} + BINARI: ${{ inputs.binari }} + CGO_ENABLED: 0 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v5 + with: + go-version: "1.21" + - name: Build du projet + run: | + echo "Building for ${BINARI}/${GOOS}/${GOARCH} (release: ${RELEASE_CIBLE})" + go env GOOS GOARCH + mkdir -p dist/ + go build -o dist/${BINARI}_${GOOS}_${GOARCH} ./cmd/${BINARI} + echo "artifact pour ${RELEASE_CIBLE} ${BINARI} ${GOOS} ${GOARCH}" > dist/${BINARI}-${GOOS}-${GOARCH}.txt + ls -l ./dist + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.BINARI }}-${{ env.RELEASE_CIBLE }}-${{ env.GOOS }}-${{ env.GOARCH }} + path: dist/${{ env.BINARI }}_${{ env.GOOS }}_${{ env.GOARCH }} \ No newline at end of file diff --git a/.forgejo/workflows/prerelease.yml b/.forgejo/workflows/prerelease.yml new file mode 100644 index 0000000..0ced880 --- /dev/null +++ b/.forgejo/workflows/prerelease.yml @@ -0,0 +1,55 @@ +name: Pre Release Workflow + +on: + push: + tags: + - '*' + branches: + - main + pull_request: + types: [closed] + branches: + - main + +jobs: + set-release-target: + runs-on: docker + outputs: + release_cible: ${{ steps.setvar.outputs.release_cible }} + steps: + - name: Déterminer la release cible + id: setvar + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + TAG="${GITHUB_REF#refs/tags/}" + echo "release_cible=$TAG" >> $GITHUB_OUTPUT + elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then + echo "release_cible=latest" >> $GITHUB_OUTPUT + else + echo "release_cible=unknown" >> $GITHUB_OUTPUT + fi + + - name: Afficher la variable + run: echo "Release cible = ${{ steps.setvar.outputs.release_cible }}" + build: + runs-on: docker + needs: [set-release-target] + strategy: + matrix: + goos: [linux] + goarch: [amd64] + binaries: [db, metadata] + uses: ./.forgejo/workflows/build.yml + with: + tag: ${{ needs.set-release-target.outputs.release_cible }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + binari: ${{ matrix.binaries }} + secrets: inherit + prerelease: + runs-on: docker + needs: [set-release-target, build] + uses: ./.forgejo/workflows/release.yml + with: + tag: ${{ needs.set-release-target.outputs.release_cible }} + secrets: inherit \ No newline at end of file diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..efc7694 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,56 @@ +on: + workflow_call: + inputs: + tag: + required: true + type: string + +jobs: + release: + runs-on: docker + env: + TOKEN: ${{ secrets.RELEASE }} + TAG: ${{ inputs.tag }} + steps: + - name: Download all build artifacts + uses: actions/download-artifact@v3 + with: + path: dist/ + - name: Publier tous les binaires + run: ls -lR dist/ + - name: Install jq + run: | + apt-get update + apt-get install -y jq + - name: Create prerelease + run: | + curl -X POST \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + "https://git.g3e.fr/api/v1/repos/${{ github.repository }}/releases" \ + -d @- < Date: Wed, 17 Dec 2025 23:42:59 +0100 Subject: [PATCH 10/13] start: change release for prerelease Signed-off-by: GnomeZworc --- .forgejo/workflows/prerelease.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.forgejo/workflows/prerelease.yml b/.forgejo/workflows/prerelease.yml index 0ced880..fcb74c6 100644 --- a/.forgejo/workflows/prerelease.yml +++ b/.forgejo/workflows/prerelease.yml @@ -3,13 +3,7 @@ name: Pre Release Workflow on: push: tags: - - '*' - branches: - - main - pull_request: - types: [closed] - branches: - - main + - '*rc*' jobs: set-release-target: From 01abbaa3956c8aa4a2fd5445d3f8f890cdfbbc03 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 18 Dec 2025 11:32:59 +0100 Subject: [PATCH 11/13] start: change default values Signed-off-by: GnomeZworc --- cmd/db/main.go | 2 +- internal/config/agent/struct.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/db/main.go b/cmd/db/main.go index 898d4c7..0c6c1ba 100644 --- a/cmd/db/main.go +++ b/cmd/db/main.go @@ -125,7 +125,7 @@ func printDB() { } func main() { - conf, err := configuration.LoadConfig("./two.yaml") + conf, err := configuration.LoadConfig("/etc/two/agent.yml") if err != nil { fmt.Println(err) return diff --git a/internal/config/agent/struct.go b/internal/config/agent/struct.go index b19d6da..12a46d3 100644 --- a/internal/config/agent/struct.go +++ b/internal/config/agent/struct.go @@ -15,7 +15,7 @@ func LoadConfig(path string) (*Config, error) { v.SetConfigFile(path) v.SetConfigType("yaml") - v.SetDefault("database.path", "./data/") + v.SetDefault("database.path", "/var/lib/two/data/") if err := v.ReadInConfig(); err != nil { return nil, err From 590723ae5eaa10eb576a55b41c43626041d747d4 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 18 Dec 2025 11:34:33 +0100 Subject: [PATCH 12/13] start: add example fil for agent config Signed-off-by: GnomeZworc --- exemple/agent/config.exemple.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 exemple/agent/config.exemple.yml diff --git a/exemple/agent/config.exemple.yml b/exemple/agent/config.exemple.yml new file mode 100644 index 0000000..a2b9f1b --- /dev/null +++ b/exemple/agent/config.exemple.yml @@ -0,0 +1,2 @@ +database: + path: "/var/lib/two/data/" \ No newline at end of file From ceda93338b1b6690fa01a0ab7586b83c9b605869 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 23 Apr 2025 22:13:48 +0200 Subject: [PATCH 13/13] add notice file Signed-off-by: GnomeZworc --- NOTICE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 NOTICE.md diff --git a/NOTICE.md b/NOTICE.md new file mode 100644 index 0000000..d8b9386 --- /dev/null +++ b/NOTICE.md @@ -0,0 +1,11 @@ +# 🔒 Utilisation de logiciels open source + +Notre logiciel utilise des composants open source, notamment **NetBox**, un outil de gestion d'infrastructure réseau développé par la communauté NetBox. + +NetBox est distribué sous la **licence Apache License, Version 2.0**. Vous pouvez consulter cette licence à l'adresse suivante : +http://www.apache.org/licenses/LICENSE-2.0 + +Aucune modification n’a été apportée à NetBox dans notre intégration. Il est utilisé tel quel, en tant que base de données d'infrastructure. + +Copyright © 2025 NetBox Contributors. +Nous reconnaissons et respectons le travail de la communauté NetBox. \ No newline at end of file