feat: add optional basic auth support for Loki client
Some Loki deployments (e.g., behind a reverse proxy or Grafana Cloud) require HTTP Basic Authentication. This adds optional --loki-username and --loki-password flags (and corresponding env vars) to the lab-monitoring server, along with NixOS module options for secure credential management via systemd LoadCredential. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"git.t-juice.club/torjus/labmcp/internal/monitoring"
|
||||
)
|
||||
|
||||
const version = "0.3.0"
|
||||
const version = "0.3.1"
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
@@ -40,6 +40,16 @@ func main() {
|
||||
Usage: "Loki base URL (optional, enables log query tools)",
|
||||
EnvVars: []string{"LOKI_URL"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "loki-username",
|
||||
Usage: "Username for Loki basic auth",
|
||||
EnvVars: []string{"LOKI_USERNAME"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "loki-password",
|
||||
Usage: "Password for Loki basic auth",
|
||||
EnvVars: []string{"LOKI_PASSWORD"},
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
serveCommand(),
|
||||
@@ -189,7 +199,11 @@ func runServe(c *cli.Context) error {
|
||||
|
||||
var loki *monitoring.LokiClient
|
||||
if lokiURL := c.String("loki-url"); lokiURL != "" {
|
||||
loki = monitoring.NewLokiClient(lokiURL)
|
||||
loki = monitoring.NewLokiClient(monitoring.LokiClientOptions{
|
||||
BaseURL: lokiURL,
|
||||
Username: c.String("loki-username"),
|
||||
Password: c.String("loki-password"),
|
||||
})
|
||||
}
|
||||
|
||||
config.InstructionsFunc = func() string {
|
||||
@@ -432,7 +446,11 @@ func runLogs(c *cli.Context, logql string) error {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
loki := monitoring.NewLokiClient(lokiURL)
|
||||
loki := monitoring.NewLokiClient(monitoring.LokiClientOptions{
|
||||
BaseURL: lokiURL,
|
||||
Username: c.String("loki-username"),
|
||||
Password: c.String("loki-password"),
|
||||
})
|
||||
|
||||
now := time.Now()
|
||||
start, err := parseCLITime(c.String("start"), now.Add(-time.Hour))
|
||||
@@ -487,7 +505,11 @@ func runLabels(c *cli.Context) error {
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
loki := monitoring.NewLokiClient(lokiURL)
|
||||
loki := monitoring.NewLokiClient(monitoring.LokiClientOptions{
|
||||
BaseURL: lokiURL,
|
||||
Username: c.String("loki-username"),
|
||||
Password: c.String("loki-password"),
|
||||
})
|
||||
|
||||
if label := c.String("values"); label != "" {
|
||||
values, err := loki.LabelValues(ctx, label)
|
||||
|
||||
Reference in New Issue
Block a user