[Git][root/cli/netboxadm][main] feat: use new scheme for dns and dhcp updates

Fernando K pushed to branch main at Root / CLI / netboxadm Commits: 5ac2f16b by Fernando Monteiro Kiotheka at 2025-07-31T14:44:53-03:00 feat: use new scheme for dns and dhcp updates - - - - - 7 changed files: - cmd/backup/update.go - cmd/config/config.go - cmd/dhcp/update.go - cmd/dns/update.go - − config.yml - go.mod - go.sum Changes: ===================================== cmd/backup/update.go ===================================== @@ -32,10 +32,11 @@ var UpdateCmd = &cobra.Command{ PreRunE: config.AssertGitlabConfigured, } +const BACKUP_REPO_URL = "https://gitlab.c3sl.ufpr.br/root/services/vmbackups.git" + func updateBackup(cmd *cobra.Command, args []string) error { localPath := "/tmp/backup" callRenderScript := func() error { - // run the rendering script netboxURL := viper.GetString("netbox.url") netboxToken := viper.GetString("netbox.token") vmbackups.Render(localPath, netboxURL, netboxToken) @@ -44,7 +45,7 @@ func updateBackup(cmd *cobra.Command, args []string) error { } return nethuh.PerformPipelineUpdateWorkflow( - viper.GetString("backup.repoURL"), + BACKUP_REPO_URL, localPath, callRenderScript, ) ===================================== cmd/config/config.go ===================================== @@ -19,9 +19,7 @@ package config import ( "errors" - "os" "os/exec" - "path/filepath" "strings" "github.com/spf13/cobra" @@ -54,29 +52,17 @@ func InitConfig() error { viper.SetConfigName("config") viper.SetConfigType("yml") - home, err := os.UserHomeDir() - if err != nil { - return err - } - - configPath := filepath.Join(home, ".config", "netboxadm") - viper.AddConfigPath(configPath) - viper.AddConfigPath(".") viper.MustBindEnv("netbox.url", "NETBOX_URL") viper.MustBindEnv("netbox.token", "NETBOX_TOKEN") viper.MustBindEnv("gitlab.accessToken", "GITLAB_ACCESS_TOKEN") viper.MustBindEnv("gitlab.username", "GITLAB_USERNAME") - if err := viper.ReadInConfig(); err != nil { - return errors.New("failed to read config.yml") - } - if viper.GetString("netbox.url") == "" { - return errors.New("netbox.url should be set either in config or environment variable NETBOX_URL") + return errors.New("netbox.url should be set either in environment variable NETBOX_URL") } if viper.GetString("netbox.token") == "" { - return errors.New("netbox.token should be set either in config or environment variable NETBOX_TOKEN") + return errors.New("netbox.token should be set either in environment variable NETBOX_TOKEN") } return nil @@ -84,11 +70,11 @@ func InitConfig() error { func AssertGitlabConfigured(cmd *cobra.Command, args []string) error { if viper.GetString("gitlab.accessToken") == "" { - return errors.New("gitlab.accessToken should be set either in config or environment variable GITLAB_ACCESS_TOKEN") + return errors.New("gitlab.accessToken should be set either in environment variable GITLAB_ACCESS_TOKEN") } if viper.GetString("gitlab.username") == "" { - return errors.New("gitlab.username should be set either in config or environment variable GITLAB_USERNAME") + return errors.New("gitlab.username should be set either in environment variable GITLAB_USERNAME") } return nil ===================================== cmd/dhcp/update.go ===================================== @@ -18,14 +18,11 @@ package dhcp import ( - "fmt" - "os" - "os/exec" - "github.com/spf13/cobra" "github.com/spf13/viper" "gitlab.c3sl.ufpr.br/root/netboxadm/cmd/config" "gitlab.c3sl.ufpr.br/root/netboxadm/internal/nethuh" + "gitlab.c3sl.ufpr.br/root/services/dhcp" ) var UpdateCmd = &cobra.Command{ @@ -35,27 +32,20 @@ var UpdateCmd = &cobra.Command{ PreRunE: config.AssertGitlabConfigured, } +const DHCP_REPO_URL = "https://gitlab.c3sl.ufpr.br/root/services/dhcp.git" + func updateDHCP(cmd *cobra.Command, args []string) error { localPath := "/tmp/dhcp" callRenderScript := func() error { - // run the rendering script - // won't work in a workspace without the requirements - // they are: go - cmdRender := exec.Command("go", "run", "render.go", "--suppress_output") - cmdRender.Dir = localPath - cmdRender.Stdout = os.Stdout - cmdRender.Stderr = os.Stderr - - err := cmdRender.Run() - if err != nil { - return fmt.Errorf("error running DHCP render script: %w", err) - } + netboxURL := viper.GetString("netbox.url") + netboxToken := viper.GetString("netbox.token") + dhcp.Render(localPath, netboxURL, netboxToken) return nil } return nethuh.PerformPipelineUpdateWorkflow( - viper.GetString("dhcp.repoURL"), + DHCP_REPO_URL, localPath, callRenderScript, ) ===================================== cmd/dns/update.go ===================================== @@ -18,14 +18,11 @@ package dns import ( - "fmt" - "os" - "os/exec" - "github.com/spf13/cobra" - "github.com/spf13/viper" "gitlab.c3sl.ufpr.br/root/netboxadm/cmd/config" "gitlab.c3sl.ufpr.br/root/netboxadm/internal/nethuh" + "gitlab.c3sl.ufpr.br/root/services/dns" + "github.com/spf13/viper" ) var UpdateCmd = &cobra.Command{ @@ -35,24 +32,20 @@ var UpdateCmd = &cobra.Command{ PreRunE: config.AssertGitlabConfigured, } +const DNS_REPO_URL = "https://gitlab.c3sl.ufpr.br/root/services/dns.git" + func updateDNS(cmd *cobra.Command, args []string) error { localPath := "/tmp/dns" callRenderScript := func() error { - cmdRender := exec.Command("go", "run", "render.go", "--suppress_output") - cmdRender.Dir = localPath - cmdRender.Stdout = os.Stdout - cmdRender.Stderr = os.Stderr - - err := cmdRender.Run() - if err != nil { - return fmt.Errorf("error running DNS render script: %w", err) - } + netboxURL := viper.GetString("netbox.url") + netboxToken := viper.GetString("netbox.token") + dns.Render(localPath, netboxURL, netboxToken) return nil } return nethuh.PerformPipelineUpdateWorkflow( - viper.GetString("dns.repoURL"), + DNS_REPO_URL, localPath, callRenderScript, ) ===================================== config.yml deleted ===================================== @@ -1,11 +0,0 @@ -netbox: - url: https://ronnie.c3sl.ufpr.br - -dns: - repoURL: https://gitlab.c3sl.ufpr.br/root/services/dns.git - -dhcp: - repoURL: https://gitlab.c3sl.ufpr.br/root/services/dhcp.git - -backup: - repoURL: https://gitlab.c3sl.ufpr.br/root/services/vmbackups.git ===================================== go.mod ===================================== @@ -13,11 +13,17 @@ require ( github.com/seancfoley/ipaddress-go v1.7.1 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 + gitlab.c3sl.ufpr.br/root/services/dhcp v1.0.2 + gitlab.c3sl.ufpr.br/root/services/dns v1.0.2 gitlab.c3sl.ufpr.br/root/services/vmbackups v1.0.0 ) replace gitlab.c3sl.ufpr.br/root/services/vmbackups => gitlab.c3sl.ufpr.br/root/services/vmbackups.git v1.0.0 +replace gitlab.c3sl.ufpr.br/root/services/dns => gitlab.c3sl.ufpr.br/root/services/dns.git v1.0.2 + +replace gitlab.c3sl.ufpr.br/root/services/dhcp => gitlab.c3sl.ufpr.br/root/services/dhcp.git v1.0.2 + require ( dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect ===================================== go.sum ===================================== @@ -188,6 +188,10 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +gitlab.c3sl.ufpr.br/root/services/dhcp.git v1.0.2 h1:Wi9gBfwattPz10KdZgUhCyO1n2wNn/LzT85qbMh30Tw= +gitlab.c3sl.ufpr.br/root/services/dhcp.git v1.0.2/go.mod h1:1sv2r7hZ1dPsYwn71xBoBIzVgUlPBkhwu1McUXDnxwg= +gitlab.c3sl.ufpr.br/root/services/dns.git v1.0.2 h1:8x8pNllXTwyf5G9YvztymS+n53kNIxxB60DIuSLilAM= +gitlab.c3sl.ufpr.br/root/services/dns.git v1.0.2/go.mod h1:DgzAim9cbJw3WxecQh2KDPdM2/GwEuUzVwgVz0cZ7Aw= gitlab.c3sl.ufpr.br/root/services/vmbackups.git v1.0.0 h1:e5q7dA8aNDqTI0+7mXs+J8Xm3nejXItK6XVvEZbsNXg= gitlab.c3sl.ufpr.br/root/services/vmbackups.git v1.0.0/go.mod h1:eyNqTBI4DuroKzEbX7a1kjLuDB272vbp4s+TIT3xR3I= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= View it on GitLab: https://gitlab.c3sl.ufpr.br/root/cli/netboxadm/-/commit/5ac2f16be7c7ea0d767c... -- View it on GitLab: https://gitlab.c3sl.ufpr.br/root/cli/netboxadm/-/commit/5ac2f16be7c7ea0d767c... You're receiving this email because of your account on gitlab.c3sl.ufpr.br.
participantes (1)
-
Fernando K (@fmkiotheka)