@@ -26,16 +26,26 @@ import (
2626 log "github.com/golang/glog"
2727 "github.com/google/fleetspeak/fleetspeak/src/common"
2828 "github.com/google/fleetspeak/fleetspeak/src/server/authorizer"
29+ "github.com/google/fleetspeak/fleetspeak/src/server/comms"
2930 "golang.org/x/time/rate"
3031)
3132
3233// unauthorizedLogging is used to rate-limit logging of unauthorized file
3334// requests to avoid spam during potential DoS attacks.
3435var unauthorizedLogging = rate.Sometimes {Interval : time .Minute }
3536
36- // fileServer wraps a Communicator in order to serve files.
37+ // fileServer uses a subset of Communicator in order to serve files.
3738type fileServer struct {
38- * Communicator
39+ fs func () comms.Context
40+ p Params
41+ }
42+
43+ // NewFileServer allows reuse of fileServer in non-HTTPS communicators.
44+ func NewFileServer (fs func () comms.Context , p Params ) fileServer {
45+ return fileServer {
46+ fs : fs ,
47+ p : p ,
48+ }
3949}
4050
4151// ServeHTTP implements http.Handler
@@ -67,9 +77,9 @@ func (s fileServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
6777 }
6878
6979 ctx := req .Context ()
70- data , modtime , err := s .fs .ReadFile (ctx , service , name )
80+ data , modtime , err := s .fs () .ReadFile (ctx , service , name )
7181 if err != nil {
72- if s .fs .IsNotFound (err ) {
82+ if s .fs () .IsNotFound (err ) {
7383 http .Error (res , "file not found" , http .StatusNotFound )
7484 return
7585 }
@@ -86,7 +96,7 @@ func (s fileServer) authorizeFileRequest(req *http.Request) error {
8696 return err
8797 }
8898 addr := net .TCPAddrFromAddrPort (addrPort )
89- if ! s .fs .Authorizer ().Allow1 (addr ) {
99+ if ! s .fs () .Authorizer ().Allow1 (addr ) {
90100 return fmt .Errorf ("unauthorized via Allow1 (addr: %v)" , addr )
91101 }
92102
@@ -105,7 +115,7 @@ func (s fileServer) authorizeFileRequest(req *http.Request) error {
105115 ClientLabels : req .Header ["X-Fleetspeak-Labels" ],
106116 }
107117
108- if ! s .fs .Authorizer ().Allow2 (addr , ci ) {
118+ if ! s .fs () .Authorizer ().Allow2 (addr , ci ) {
109119 return fmt .Errorf ("unauthorized via Allow2 (addr: %v, contact: %v)" , addr , ci )
110120 }
111121 return nil
0 commit comments