(ctx devspacecontext.Context, path string, pipeline types.Pipeline)
| 121 | } |
| 122 | |
| 123 | func newHandler(ctx devspacecontext.Context, path string, pipeline types.Pipeline) (*handler, error) { // Get kube config |
| 124 | kubeConfig, err := kubeconfig.NewLoader().LoadRawConfig() |
| 125 | if err != nil { |
| 126 | return nil, errors.Wrap(err, "load kube config") |
| 127 | } |
| 128 | |
| 129 | kubeContexts := map[string]string{} |
| 130 | for name, context := range kubeConfig.Contexts { |
| 131 | namespace := context.Namespace |
| 132 | if namespace == "" { |
| 133 | namespace = metav1.NamespaceDefault |
| 134 | } |
| 135 | |
| 136 | kubeContexts[name] = namespace |
| 137 | } |
| 138 | |
| 139 | handler := &handler{ |
| 140 | ctx: ctx, |
| 141 | pipeline: pipeline, |
| 142 | mux: http.NewServeMux(), |
| 143 | path: path, |
| 144 | kubeContexts: kubeContexts, |
| 145 | ports: make(map[string]*forward), |
| 146 | clientCache: make(map[string]kubectl.Client), |
| 147 | terminalResizeQueues: make(map[string]TerminalResizeQueue), |
| 148 | } |
| 149 | handler.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 150 | http.ServeFile(w, r, filepath.Join(path, "index.html")) |
| 151 | }) |
| 152 | handler.mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(filepath.Join(path, "static"))))) |
| 153 | handler.mux.HandleFunc("/api/ping", handler.ping) |
| 154 | handler.mux.HandleFunc("/api/exclude-dependency", handler.excludeDependency) |
| 155 | handler.mux.HandleFunc("/api/version", handler.version) |
| 156 | handler.mux.HandleFunc("/api/command", handler.command) |
| 157 | handler.mux.HandleFunc("/api/resource", handler.request) |
| 158 | handler.mux.HandleFunc("/api/config", handler.returnConfig) |
| 159 | handler.mux.HandleFunc("/api/forward", handler.forward) |
| 160 | handler.mux.HandleFunc("/api/enter", handler.enter) |
| 161 | handler.mux.HandleFunc("/api/resize", handler.resize) |
| 162 | handler.mux.HandleFunc("/api/logs", handler.logs) |
| 163 | return handler, nil |
| 164 | } |
| 165 | |
| 166 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 167 | /*w.Header().Set("Access-Control-Allow-Origin", "*") |
no test coverage detected