tenseleyflow/shithub / 40877b4

Browse files

Wire shithubd config print/validate; enrich version with sink summary

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
40877b41464141d039bf7db2ec1afc59314a6cd9
Parents
0661c5a
Tree
b95d487

3 changed files

StatusFile+-
A cmd/shithubd/config.go 47 0
M cmd/shithubd/root.go 1 1
M cmd/shithubd/version.go 34 1
cmd/shithubd/config.goadded
@@ -0,0 +1,47 @@
1
+// SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+package main
4
+
5
+import (
6
+	"fmt"
7
+
8
+	"github.com/spf13/cobra"
9
+
10
+	"github.com/tenseleyFlow/shithub/internal/infra/config"
11
+)
12
+
13
+var configCmd = &cobra.Command{
14
+	Use:   "config",
15
+	Short: "Inspect the resolved shithub configuration",
16
+}
17
+
18
+var configPrintCmd = &cobra.Command{
19
+	Use:   "print",
20
+	Short: "Print the active configuration with secrets redacted",
21
+	RunE: func(_ *cobra.Command, _ []string) error {
22
+		cfg, err := config.Load(nil)
23
+		if err != nil {
24
+			return err
25
+		}
26
+		out, err := config.PrintRedacted(cfg)
27
+		if err != nil {
28
+			return err
29
+		}
30
+		fmt.Print(out)
31
+		return nil
32
+	},
33
+}
34
+
35
+var configValidateCmd = &cobra.Command{
36
+	Use:   "validate",
37
+	Short: "Validate config (exits non-zero on failure)",
38
+	RunE: func(_ *cobra.Command, _ []string) error {
39
+		_, err := config.Load(nil)
40
+		return err
41
+	},
42
+}
43
+
44
+func init() {
45
+	configCmd.AddCommand(configPrintCmd)
46
+	configCmd.AddCommand(configValidateCmd)
47
+}
cmd/shithubd/root.gomodified
@@ -39,5 +39,5 @@ func init() {
3939
 	rootCmd.AddCommand(stubCmd("storage", "Storage health checks", "S04"))
4040
 	rootCmd.AddCommand(stubCmd("hook", "Git hook entrypoint", "S14"))
4141
 	rootCmd.AddCommand(stubCmd("admin", "Site-admin CLI", "S34"))
42
-	rootCmd.AddCommand(stubCmd("config", "Config introspection", "S03"))
42
+	rootCmd.AddCommand(configCmd)
4343
 }
cmd/shithubd/version.gomodified
@@ -8,17 +8,50 @@ import (
88
 
99
 	"github.com/spf13/cobra"
1010
 
11
+	"github.com/tenseleyFlow/shithub/internal/infra/config"
1112
 	"github.com/tenseleyFlow/shithub/internal/version"
1213
 )
1314
 
1415
 var versionCmd = &cobra.Command{
1516
 	Use:   "version",
16
-	Short: "Print version, commit, build time, and Go runtime",
17
+	Short: "Print version, commit, build time, Go runtime, and configured observability sinks",
1718
 	Run: func(cmd *cobra.Command, args []string) {
1819
 		fmt.Printf("shithubd %s\n", version.Version)
1920
 		fmt.Printf("  commit: %s\n", version.Commit)
2021
 		fmt.Printf("  built:  %s\n", version.BuiltAt)
2122
 		fmt.Printf("  go:     %s\n", runtime.Version())
2223
 		fmt.Printf("  os:     %s/%s\n", runtime.GOOS, runtime.GOARCH)
24
+
25
+		cfg, err := config.Load(nil)
26
+		if err != nil {
27
+			fmt.Printf("  config: <invalid: %s>\n", err)
28
+			return
29
+		}
30
+		fmt.Printf("  env:     %s\n", cfg.Env)
31
+		fmt.Printf("  log:     %s/%s\n", cfg.Log.Format, cfg.Log.Level)
32
+		fmt.Printf("  metrics: %s\n", boolStr(cfg.Metrics.Enabled))
33
+		fmt.Printf("  tracing: %s\n", tracingStr(cfg.Tracing))
34
+		fmt.Printf("  errrep:  %s\n", errrepStr(cfg.ErrorReporting))
2335
 	},
2436
 }
37
+
38
+func boolStr(b bool) string {
39
+	if b {
40
+		return "enabled"
41
+	}
42
+	return "disabled"
43
+}
44
+
45
+func tracingStr(t config.TracingConfig) string {
46
+	if !t.Enabled {
47
+		return "disabled"
48
+	}
49
+	return fmt.Sprintf("enabled (endpoint=%s, sample=%.2f)", t.Endpoint, t.SampleRate)
50
+}
51
+
52
+func errrepStr(e config.ErrorReportingConfig) string {
53
+	if e.DSN == "" {
54
+		return "disabled"
55
+	}
56
+	return "enabled (dsn=*** env=" + e.Environment + ")"
57
+}