/
chartmuseum.go
38 lines (36 loc) · 977 Bytes
/
chartmuseum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package proxy
import (
"crypto/tls"
"fmt"
"github.com/KubeOperator/KubeOperator/pkg/constant"
"github.com/kataras/iris/v12/context"
"net/http"
"net/http/httputil"
"net/url"
)
func ChartmuseumProxy(ctx context.Context) {
clusterName := ctx.Params().Get("cluster_name")
proxyPath := ctx.Params().Get("p")
if clusterName == "" {
_, _ = ctx.JSON(http.StatusBadRequest)
return
}
endpoint, err := clusterService.GetRouterEndpoint(clusterName)
if err != nil {
_, _ = ctx.JSON(http.StatusInternalServerError)
return
}
u, err := url.Parse(fmt.Sprintf("http://%s", endpoint.Address))
if err != nil {
_, _ = ctx.JSON(http.StatusInternalServerError)
return
}
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
req := ctx.Request()
req.Host = fmt.Sprintf(constant.DefaultChartmuseumIngress)
req.URL.Path = proxyPath
proxy.ServeHTTP(ctx.ResponseWriter(), req)
}