Prepare for GitHub migration (#24)
Moves node-lookup to IUCLabs/node-lookup on GitHub; it must carry no internal hostnames or Woodpecker release. - Loads PuppetDB, Puppetboard and domain from config (flags > env > ~/.config > /etc) for all 3 tools; errors name the config paths - Ships packaging/config.example.yaml as an RPM doc - Rewrites .goreleaser.yaml: raw binaries + amd64 RPM with completions, signed checksums - Adds GitHub CI/release workflows, CODEOWNERS, zizmor config, README - Makes patch/minor/major draft a GitHub release; make rpm runs a goreleaser snapshot - Removes the Woodpecker release pipeline, nfpm.yaml and build-rpm.sh Reviewed-on: #24 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #24.
This commit is contained in:
@@ -23,10 +23,17 @@ import (
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
if err := execute(os.Args[1:]); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// execute builds and runs the CLI; cobra prints any returned error.
|
||||
func execute(args []string) error {
|
||||
cfg, err := puppet.Load()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "config error:", err)
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -52,6 +59,9 @@ func main() {
|
||||
if cmd.Flags().Changed("url") {
|
||||
cfg.PuppetDBURL = pdbURL
|
||||
}
|
||||
if err := cfg.Require("puppetdb_url", "puppetboard_url"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loc := time.Local
|
||||
if tz != "" {
|
||||
@@ -91,7 +101,6 @@ func main() {
|
||||
SilenceUsage: true,
|
||||
})
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
root.SetArgs(args)
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"node-lookup/internal/puppet"
|
||||
)
|
||||
|
||||
func TestExecute_MissingConfigNamesBothKeys(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", dir)
|
||||
t.Setenv("NODE_LOOKUP_URL", "")
|
||||
t.Setenv("NODE_LOOKUP_PUPPETBOARD_URL", "")
|
||||
old := puppet.SystemConfigPath
|
||||
puppet.SystemConfigPath = filepath.Join(dir, "etc-config.yaml")
|
||||
t.Cleanup(func() { puppet.SystemConfigPath = old })
|
||||
|
||||
err := execute([]string{"host1"})
|
||||
if err == nil || !strings.Contains(err.Error(), "puppetdb_url") || !strings.Contains(err.Error(), "puppetboard_url") {
|
||||
t.Fatalf("expected missing puppetdb_url and puppetboard_url error, got %v", err)
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -19,10 +19,17 @@ import (
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
if err := execute(os.Args[1:]); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// execute builds and runs the CLI; cobra prints any returned error.
|
||||
func execute(args []string) error {
|
||||
cfg, err := puppet.Load()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "config error:", err)
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
var boardURL string
|
||||
@@ -38,6 +45,9 @@ func main() {
|
||||
if cmd.Flags().Changed("puppetboard-url") {
|
||||
cfg.PuppetboardURL = boardURL
|
||||
}
|
||||
if err := cfg.Require("puppetboard_url"); err != nil {
|
||||
return err
|
||||
}
|
||||
hosts := puppet.ReadHosts(os.Stdin, args)
|
||||
if len(hosts) == 0 {
|
||||
return fmt.Errorf("no hosts given (pass as arguments or pipe node-lookup output)")
|
||||
@@ -57,7 +67,6 @@ func main() {
|
||||
SilenceUsage: true,
|
||||
})
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
root.SetArgs(args)
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"node-lookup/internal/puppet"
|
||||
)
|
||||
|
||||
func TestExecute_MissingPuppetboardURL(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", dir)
|
||||
t.Setenv("NODE_LOOKUP_PUPPETBOARD_URL", "")
|
||||
old := puppet.SystemConfigPath
|
||||
puppet.SystemConfigPath = filepath.Join(dir, "etc-config.yaml")
|
||||
t.Cleanup(func() { puppet.SystemConfigPath = old })
|
||||
|
||||
err := execute([]string{"host1"})
|
||||
if err == nil || !strings.Contains(err.Error(), "puppetboard_url") {
|
||||
t.Fatalf("expected missing puppetboard_url error, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user