From 6d55b554d799113126e1d9ada8af11c501abf973 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 24 Dec 2025 14:04:30 +0100 Subject: [PATCH 1/3] f-8: conf: move configuration files Signed-off-by: GnomeZworc --- conf/agent/config.dev.yml | 2 ++ {exemple => conf}/agent/config.exemple.yml | 0 2 files changed, 2 insertions(+) create mode 100644 conf/agent/config.dev.yml rename {exemple => conf}/agent/config.exemple.yml (100%) diff --git a/conf/agent/config.dev.yml b/conf/agent/config.dev.yml new file mode 100644 index 0000000..62cb624 --- /dev/null +++ b/conf/agent/config.dev.yml @@ -0,0 +1,2 @@ +database: + path: "./data/" \ No newline at end of file diff --git a/exemple/agent/config.exemple.yml b/conf/agent/config.exemple.yml similarity index 100% rename from exemple/agent/config.exemple.yml rename to conf/agent/config.exemple.yml From f1492acd85d87aa22dc315ac24e76c22afaef31a Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 24 Dec 2025 14:05:47 +0100 Subject: [PATCH 2/3] f-8: internal/conf: delete conf file existance check Signed-off-by: GnomeZworc --- internal/config/agent/struct.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/config/agent/struct.go b/internal/config/agent/struct.go index 12a46d3..c9537bf 100644 --- a/internal/config/agent/struct.go +++ b/internal/config/agent/struct.go @@ -17,9 +17,7 @@ func LoadConfig(path string) (*Config, error) { v.SetDefault("database.path", "/var/lib/two/data/") - if err := v.ReadInConfig(); err != nil { - return nil, err - } + v.ReadInConfig() var cfg Config if err := v.Unmarshal(&cfg); err != nil { From a1f7c438881e666b5be10ae35789b524aff52a8b Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Wed, 24 Dec 2025 22:02:18 +0100 Subject: [PATCH 3/3] f-8: code: add params for meta_cli #8 Signed-off-by: GnomeZworc --- cmd/meta_cli/main.go | 45 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/cmd/meta_cli/main.go b/cmd/meta_cli/main.go index 9fec4db..ce97286 100644 --- a/cmd/meta_cli/main.go +++ b/cmd/meta_cli/main.go @@ -1,17 +1,54 @@ package main import ( + "flag" "fmt" "os" + "strings" + + configuration "git.g3e.fr/syonad/two/internal/config/agent" + "git.g3e.fr/syonad/two/pkg/db/kv" + "github.com/dgraph-io/badger/v4" ) -var ( - bin_name = os.Args[0] -) +var DB *badger.DB + +func AddInDB(dbName string, line string) error { + // ID = partie avant le premier ';' + id := strings.Split(line, ";")[0] + "/bash" + key := []byte(dbName + "/" + id) + + return DB.Update(func(txn *badger.Txn) error { + return txn.Set(key, []byte(line)) + }) +} func main() { + conf_file := flag.String("conf", "/etc/two/agent.yml", "configuration file") + vm_name := flag.String("vm_name", "", "Nom de la vm") + vpc := flag.String("vpc_name", "", "vpc name") + bind_ip := flag.String("ip", "", "bind ip") + bind_port := flag.String("port", "", "bind port") + ssh_key := flag.String("key", "", "Clef ssh") + password := flag.String("pass", "", "password user") + start := flag.Bool("start", false, "start metadata server") + stop := flag.Bool("stop", false, "stop metadata server") - fmt.Printf("Start %s conf\n", bin_name) + flag.Parse() + + conf, err := configuration.LoadConfig(*conf_file) + if err != nil { + fmt.Println(err) + return + } + fmt.Print(conf) + + DB = kv.InitDB(kv.Config{ + Path: conf.Database.Path, + }) + defer DB.Close() + + fmt.Printf("conf metadata for %s\n - this key %s\n - this password %s\n", *vm_name, *ssh_key, *password) os.Exit(0) }