-
-
Notifications
You must be signed in to change notification settings - Fork 22
Fix MCP server pointer error and integrate dashboard toggle #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7da020c
4e42a59
147bbe9
8d2ff0d
a83329c
f5e6715
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,7 +184,7 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| if err := config.GenerateSample(configPath); err != nil { | ||
| return fmt.Errorf("failed to generate config: %w", err) | ||
| } | ||
| log.Printf("Sample configuration written to %s", configPath) | ||
| log.Info().Str("path", configPath).Msg("sample configuration written") | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -251,13 +251,54 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| var m *metrics.Metrics | ||
| if metricsEnabled { | ||
| m = metrics.New(version, commit, date) | ||
| log.Println("Prometheus metrics enabled at /metrics") | ||
| log.Info().Msg("Prometheus metrics enabled at /metrics") | ||
| } | ||
|
|
||
| ctx, stop := signal.NotifyContext(ctx, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM) | ||
| defer stop() | ||
|
|
||
| server := api.NewServer(store, cfg.Server.Host, cfg.Server.Port, m) | ||
| server.SetLogger(log) | ||
|
|
||
| // Configure MCP integration (OAuth config parsed from flags) | ||
| var oauthCfg *oauth.Config | ||
| if mcpOAuthEnabled { | ||
| var scopes []string | ||
| if mcpOAuthScopes != "" { | ||
| for _, s := range strings.Split(mcpOAuthScopes, ",") { | ||
| scopes = append(scopes, strings.TrimSpace(s)) | ||
| } | ||
| } | ||
|
|
||
| var resourceServerURL, audience string | ||
| if mcpOAuthAudience != "" { | ||
| resourceServerURL = mcpOAuthAudience | ||
| audience = mcpOAuthAudience | ||
| } else { | ||
| resourceServerURL = fmt.Sprintf("http://localhost:%d/mcp", cfg.Server.Port) | ||
| audience = resourceServerURL | ||
| } | ||
|
|
||
| oauthCfg = &oauth.Config{ | ||
| Enabled: true, | ||
| Issuer: mcpOAuthIssuer, | ||
| Audience: audience, | ||
| ClientID: mcpOAuthClientID, | ||
| ClientSecret: mcpOAuthClientSecret, | ||
| RequiredScopes: scopes, | ||
| IntrospectionEndpoint: mcpOAuthIntrospection, | ||
| ResourceServerURL: resourceServerURL, | ||
| ResourceName: mcpOAuthResourceName, | ||
| InsecureSkipVerify: mcpOAuthInsecure, | ||
| } | ||
|
Comment on lines
+265
to
+294
|
||
| } | ||
|
|
||
| server.SetMCPConfig(&api.MCPConfig{ | ||
| Version: version, | ||
| OAuth: oauthCfg, | ||
| Logger: log, | ||
| }) | ||
|
|
||
| serverErrChan := make(chan error, 1) | ||
| go func() { | ||
| serverErrChan <- server.Start(ctx) | ||
|
|
@@ -267,10 +308,10 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| server.RefreshMetrics() | ||
|
|
||
| if serveOnly { | ||
| log.Println("Running in serve-only mode") | ||
| log.Info().Msg("running in serve-only mode") | ||
| select { | ||
| case <-ctx.Done(): | ||
| log.Println("Shutting down...") | ||
| log.Info().Msg("shutting down") | ||
| case err := <-serverErrChan: | ||
| if err != nil { | ||
| return fmt.Errorf("server error: %w", err) | ||
|
|
@@ -284,14 +325,14 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| return fmt.Errorf("failed to fetch reports: %w", err) | ||
| } | ||
| server.RefreshMetrics() | ||
| log.Println("Fetch complete") | ||
| log.Info().Msg("fetch complete") | ||
| return nil | ||
| } | ||
|
|
||
| log.Printf("Starting continuous fetch mode (interval: %d seconds)", fetchInterval) | ||
| log.Info().Int64("interval_seconds", fetchInterval).Msg("starting continuous fetch mode") | ||
|
|
||
| if err := fetchReports(cfg, store, m); err != nil { | ||
| log.Printf("Initial fetch failed: %v", err) | ||
| log.Error().Err(err).Msg("initial fetch failed") | ||
| } | ||
| server.RefreshMetrics() | ||
|
|
||
|
|
@@ -302,11 +343,11 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| select { | ||
| case <-ticker.C: | ||
| if err := fetchReports(cfg, store, m); err != nil { | ||
| log.Printf("Fetch failed: %v", err) | ||
| log.Error().Err(err).Msg("fetch failed") | ||
| } | ||
| server.RefreshMetrics() | ||
| case <-ctx.Done(): | ||
| log.Println("Shutting down...") | ||
| log.Info().Msg("shutting down") | ||
| return nil | ||
| case err := <-serverErrChan: | ||
| if err != nil { | ||
|
|
@@ -317,7 +358,7 @@ func run(ctx context.Context, cmd *cli.Command) error { | |
| } | ||
|
|
||
| func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics) error { | ||
| log.Println("Fetching DMARC reports...") | ||
| log.Info().Msg("fetching DMARC reports") | ||
|
|
||
| fetchStart := time.Now() | ||
| if m != nil { | ||
|
|
@@ -353,15 +394,15 @@ func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics | |
| } | ||
|
|
||
| if len(reports) == 0 { | ||
| log.Println("No new reports found") | ||
| log.Info().Msg("no new reports found") | ||
| if m != nil { | ||
| m.RecordFetchDuration(time.Since(fetchStart)) | ||
| m.LastFetchTimestamp.SetToCurrentTime() | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| log.Printf("Processing %d reports...", len(reports)) | ||
| log.Info().Int("count", len(reports)).Msg("processing reports") | ||
|
|
||
| // Process each report | ||
| processed := 0 | ||
|
|
@@ -373,7 +414,7 @@ func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics | |
|
|
||
| feedback, err := parser.ParseReport(attachment.Data) | ||
| if err != nil { | ||
| log.Printf("Failed to parse %s: %v", attachment.Filename, err) | ||
| log.Error().Err(err).Str("filename", attachment.Filename).Msg("failed to parse report") | ||
| if m != nil { | ||
| m.ReportParseErrors.Inc() | ||
| } | ||
|
|
@@ -384,7 +425,7 @@ func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics | |
| } | ||
|
|
||
| if err := store.SaveReport(feedback); err != nil { | ||
| log.Printf("Failed to save report %s: %v", feedback.ReportMetadata.ReportID, err) | ||
| log.Error().Err(err).Str("report_id", feedback.ReportMetadata.ReportID).Msg("failed to save report") | ||
| if m != nil { | ||
| m.ReportStoreErrors.Inc() | ||
| } | ||
|
|
@@ -394,11 +435,12 @@ func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics | |
| m.ReportsStored.Inc() | ||
| } | ||
|
|
||
| log.Printf("Saved report: %s from %s (domain: %s, messages: %d)", | ||
| feedback.ReportMetadata.ReportID, | ||
| feedback.ReportMetadata.OrgName, | ||
| feedback.PolicyPublished.Domain, | ||
| feedback.GetTotalMessages()) | ||
| log.Info(). | ||
| Str("report_id", feedback.ReportMetadata.ReportID). | ||
| Str("org", feedback.ReportMetadata.OrgName). | ||
| Str("domain", feedback.PolicyPublished.Domain). | ||
| Int("messages", feedback.GetTotalMessages()). | ||
| Msg("saved report") | ||
| processed++ | ||
| } | ||
| } | ||
|
|
@@ -408,7 +450,7 @@ func fetchReports(cfg *config.Config, store *storage.Storage, m *metrics.Metrics | |
| m.LastFetchTimestamp.SetToCurrentTime() | ||
| } | ||
|
|
||
| log.Printf("Successfully processed %d reports", processed) | ||
| log.Info().Int("count", processed).Msg("successfully processed reports") | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
basePathparameter is documented in the comment but never used in the function body. The OAuth metadata URL is constructed fromoauthCfg.ResourceServerURLinstead. Either remove this unused parameter or use it to construct the metadata URL if that was the intent.