MCPcopy Index your code
hub / github.com/devspace-sh/devspace / request

Method request

pkg/devspace/server/server.go:266–330  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

264}
265
266func (h *handler) request(w http.ResponseWriter, r *http.Request) {
267 resource, ok := r.URL.Query()["resource"]
268 if !ok || len(resource) != 1 {
269 http.Error(w, "resource is missing", http.StatusBadRequest)
270 return
271 }
272
273 // Build request options
274 options := &kubectl.GenericRequestOptions{Resource: resource[0]}
275
276 // Kube Context
277 kubeContext := h.ctx.KubeClient().CurrentContext()
278 context, ok := r.URL.Query()["context"]
279 if ok && len(context) == 1 && context[0] != "" {
280 kubeContext = context[0]
281 }
282
283 // Namespace
284 kubeNamespace := h.ctx.KubeClient().Namespace()
285 namespace, ok := r.URL.Query()["namespace"]
286 if ok && len(namespace) == 1 && namespace[0] != "" {
287 kubeNamespace = namespace[0]
288 options.Namespace = namespace[0]
289 }
290
291 // Api version
292 apiVersion, ok := r.URL.Query()["apiVersion"]
293 if ok && len(apiVersion) == 1 {
294 options.APIVersion = apiVersion[0]
295 }
296
297 // Name
298 name, ok := r.URL.Query()["name"]
299 if ok && len(name) == 1 {
300 options.Name = name[0]
301 }
302
303 // LabelSelector
304 labelSelector, ok := r.URL.Query()["labelSelector"]
305 if ok && len(name) == 1 {
306 options.LabelSelector = labelSelector[0]
307 }
308
309 // check client cache
310 client, err := h.getClientFromCache(kubeContext, kubeNamespace)
311 if err != nil {
312 h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err)
313 http.Error(w, err.Error(), http.StatusInternalServerError)
314 return
315 }
316
317 // Do the request
318 out, err := client.GenericRequest(r.Context(), options)
319 if err != nil {
320 if strings.Index(err.Error(), "request: unknown") != 0 {
321 h.ctx.Log().Errorf("Error in %s: %v", r.URL.String(), err)
322 }
323

Callers

nothing calls this directly

Calls 12

getClientFromCacheMethod · 0.95
CurrentContextMethod · 0.65
KubeClientMethod · 0.65
NamespaceMethod · 0.65
LogMethod · 0.65
GenericRequestMethod · 0.65
ContextMethod · 0.65
ErrorMethod · 0.45
ErrorfMethod · 0.45
StringMethod · 0.45
SetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected