fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

zoekt-sourcegraph-indexserver: set internal actor on requests (#219)

Requests from zoekt-sourcegraph-indexserver do not have actor IDs set,
which means our actor middleware must treat an unset actor header as
an internal user. This change explicitly sets an internal actor on outgoing
requests, which removes the need for such a workaround.

Related: https://github.com/sourcegraph/sourcegraph/issues/28451

+21 -2
+21 -2
cmd/zoekt-sourcegraph-indexserver/sg.go
··· 65 65 // zero a value of 10000 is used. 66 66 BatchSize int 67 67 68 + // Client is used to make requests to the Sourcegraph instance. Prefer to 69 + // use .doRequest() to ensure the appropriate headers are set. 68 70 Client *retryablehttp.Client 69 71 70 72 // configFingerprint is the last config fingerprint returned from ··· 185 187 req.Header.Set("X-Sourcegraph-Config-Fingerprint", fingerprint) 186 188 } 187 189 188 - resp, err := s.Client.Do(req) 190 + resp, err := s.doRequest(req) 189 191 if err != nil { 190 192 return nil, "", err 191 193 } ··· 239 241 } 240 242 241 243 u := s.Root.ResolveReference(&url.URL{Path: "/.internal/repos/index"}) 242 - resp, err := s.Client.Post(u.String(), "application/json; charset=utf8", bytes.NewReader(body)) 244 + req, err := retryablehttp.NewRequest(http.MethodPost, u.String(), bytes.NewReader(body)) 245 + if err != nil { 246 + return nil, err 247 + } 248 + req.Header.Set("Content-Type", "application/json; charset=utf8") 249 + 250 + resp, err := s.doRequest(req) 243 251 if err != nil { 244 252 return nil, err 245 253 } ··· 260 268 metricNumAssigned.Set(float64(len(data.RepoIDs))) 261 269 262 270 return data.RepoIDs, nil 271 + } 272 + 273 + // doRequest executes the provided request after adding the appropriate headers 274 + // for interacting with a Sourcegraph instance. 275 + func (s *sourcegraphClient) doRequest(req *retryablehttp.Request) (*http.Response, error) { 276 + // Make all requests as an internal user. 277 + // 278 + // Should match github.com/sourcegraph/sourcegraph/internal/actor.headerKeyActorUID 279 + // and github.com/sourcegraph/sourcegraph/internal/actor.headerValueInternalActor 280 + req.Header.Set("X-Sourcegraph-Actor-UID", "internal") 281 + return s.Client.Do(req) 263 282 } 264 283 265 284 type sourcegraphFake struct {