in internal/worker/server.go [52:113]
func NewServer(ctx context.Context, cfg Config) (_ *Server, err error) {
defer derrors.Wrap(&err, "NewServer(%q)", cfg.Namespace)
s := &Server{cfg: cfg}
tracerProvider, err := initOpenTelemetry(cfg.Project)
if err != nil {
return nil, err
}
s.traceHandler = eotel.NewTraceHandler(tracerProvider.Tracer("vulndb-worker"))
s.afterRequest = func() { tracerProvider.ForceFlush(ctx) }
// The propagator extracts incoming trace IDs so that we can connect our trace spans
// to the incoming ones constructed by Cloud Run.
s.propagator = propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
gcppropagator.New(),
)
if cfg.UseErrorReporting {
reportingClient, err := errorreporting.NewClient(ctx, cfg.Project, errorreporting.Config{
ServiceName: serviceID,
OnError: func(err error) {
log.Errorf(ctx, "Error reporting failed: %v", err)
},
})
if err != nil {
return nil, err
}
derrors.SetReportingClient(reportingClient)
}
if cfg.IssueRepo != "" {
owner, repoName, err := gitrepo.ParseGitHubRepo(cfg.IssueRepo)
if err != nil {
return nil, err
}
s.issueClient = issues.NewGitHubClient(owner, repoName, cfg.GitHubAccessToken)
log.Infof(ctx, "issue creation enabled for repo %s", cfg.IssueRepo)
} else {
log.Infof(ctx, "issue creation disabled")
}
s.indexTemplate, err = parseTemplate(staticPath, template.TrustedSourceFromConstant("index.tmpl"))
if err != nil {
return nil, err
}
s.handle(ctx, "/", s.indexPage)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticPath.String()))))
s.handle(ctx, "/favicon.ico", func(w http.ResponseWriter, r *http.Request) error {
http.ServeFile(w, r, filepath.Join(staticPath.String(), "favicon.ico"))
return nil
})
// update: Update the DB from the cvelist repo head and decide which CVEs need issues.
s.handle(ctx, "/update", s.handleUpdate)
// issues: File issues on GitHub for CVEs that need them.
s.handle(ctx, "/issues", s.handleIssues)
// update-and-issues: do update followed by issues.
s.handle(ctx, "/update-and-issues", s.handleUpdateAndIssues)
return s, nil
}