MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / NewHTTPServer

Function NewHTTPServer

app/artifact-cas/internal/server/http.go:36–72  ·  view source on GitHub ↗

NewHTTPServer new a HTTP server.

(c *conf.Server, authConf *conf.Auth, downloadSvc *service.DownloadService, providers backend.Providers, logger log.Logger)

Source from the content-addressed store, hash-verified

34
35// NewHTTPServer new a HTTP server.
36func NewHTTPServer(c *conf.Server, authConf *conf.Auth, downloadSvc *service.DownloadService, providers backend.Providers, logger log.Logger) (*http.Server, error) {
37 var opts = []http.ServerOption{
38 http.Middleware(
39 recovery.Recovery(),
40 logging.Server(logger),
41 ),
42 }
43 if c.Http.Network != "" {
44 opts = append(opts, http.Network(c.Http.Network))
45 }
46 if c.Http.Addr != "" {
47 opts = append(opts, http.Address(c.Http.Addr))
48 }
49 if c.Http.Timeout != nil {
50 opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration()))
51 }
52
53 // Load the key on initialization instead of on every request
54 // TODO: implement jwks endpoint
55 publicKeyPath := authConf.GetPublicKeyPath()
56 if publicKeyPath == "" {
57 // Maintain backwards compatibility
58 publicKeyPath = authConf.RobotAccountPublicKeyPath
59 }
60
61 rawKey, err := os.ReadFile(publicKeyPath)
62 if err != nil {
63 return nil, fmt.Errorf("failed to load public key: %w", err)
64 }
65
66 srv := http.NewServer(opts...)
67
68 downloadHandler := middlewares_http.AuthFromQueryParam(loadPublicKey(rawKey), claimsFunc(), casJWT.SigningMethod, downloadSvc)
69 srv.Handle(service.DownloadPath, CORSMiddleware(c.GetHttp().GetCors().GetAllowOrigins(), downloadHandler))
70 api.RegisterStatusServiceHTTPServer(srv, service.NewStatusService(Version, providers))
71 return srv, nil
72}
73
74// claimsFunc returns the claims function for the JWT middleware that casts the claims to the correct type
75func claimsFunc() middlewares_http.ClaimsFunc {

Callers 1

wireAppFunction · 0.92

Calls 9

NewStatusServiceFunction · 0.92
claimsFuncFunction · 0.85
CORSMiddlewareFunction · 0.85
ServerMethod · 0.80
GetPublicKeyPathMethod · 0.80
GetAllowOriginsMethod · 0.80
GetCorsMethod · 0.80
loadPublicKeyFunction · 0.70
GetHttpMethod · 0.45

Tested by

no test coverage detected