Compare commits

...

3 commits

Author SHA1 Message Date
a1f7c43888
f-8: code: add params for meta_cli #8
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-12-24 22:02:18 +01:00
f1492acd85
f-8: internal/conf: delete conf file existance check
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-12-24 14:05:47 +01:00
6d55b554d7
f-8: conf: move configuration files
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-12-24 14:04:30 +01:00
4 changed files with 44 additions and 7 deletions

View file

@ -1,17 +1,54 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "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 ( var DB *badger.DB
bin_name = os.Args[0]
) 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() { 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) os.Exit(0)
} }

View file

@ -0,0 +1,2 @@
database:
path: "./data/"

View file

@ -17,9 +17,7 @@ func LoadConfig(path string) (*Config, error) {
v.SetDefault("database.path", "/var/lib/two/data/") v.SetDefault("database.path", "/var/lib/two/data/")
if err := v.ReadInConfig(); err != nil { v.ReadInConfig()
return nil, err
}
var cfg Config var cfg Config
if err := v.Unmarshal(&cfg); err != nil { if err := v.Unmarshal(&cfg); err != nil {