Merge pull request #15280 from swordqiu/hotfix/qj-allow-upload-image-via-apigateway-proxy

fix: allow upload image via apigateway backend proxy
This commit is contained in:
Zexi Li
2022-11-04 12:26:19 +08:00
committed by GitHub
4 changed files with 45 additions and 10 deletions
+20 -1
View File
@@ -20,6 +20,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
"yunion.io/x/log"
@@ -84,7 +85,25 @@ func (h *SBackendServiceProxyHandler) requestManipulator(ctx context.Context, r
}
func (h *SBackendServiceProxyHandler) Bind(app *appsrv.Application) {
app.AddReverseProxyHandler(h.prefix, h.fetchReverseEndpoint(), h.requestManipulator)
app.AddReverseProxyHandlerWithCallbackConfig(
h.prefix, h.fetchReverseEndpoint(), h.requestManipulator,
func(method string, hi *appsrv.SHandlerInfo) *appsrv.SHandlerInfo {
if method == "OPTIONS" {
return nil
}
if method == "GET" || method == "PUT" || method == "POST" {
hi.SetProcessTimeout(6 * time.Hour)
}
var worker *appsrv.SWorkerManager
if method == "GET" || method == "HEAD" {
worker = appsrv.NewWorkerManager("apigateway-backend-api-read", 8, appsrv.DEFAULT_BACKLOG, false)
} else {
worker = appsrv.NewWorkerManager("apigateway-backend-api-write", 4, appsrv.DEFAULT_BACKLOG, false)
}
hi.SetWorkerManager(worker)
return hi
},
)
}
func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFactory {
+16 -1
View File
@@ -150,9 +150,24 @@ func (app *Application) getRoot(method string) *RadixNode {
}
func (app *Application) AddReverseProxyHandler(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator) {
app.AddReverseProxyHandlerWithCallbackConfig(prefix, ef, m,
func(method string, hi *SHandlerInfo) *SHandlerInfo {
return hi
},
)
}
func (app *Application) AddReverseProxyHandlerWithCallbackConfig(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator, confCb func(string, *SHandlerInfo) *SHandlerInfo) {
handler := proxy.NewHTTPReverseProxy(ef, m).ServeHTTP
for _, method := range []string{"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"} {
app.AddHandler(method, prefix, handler)
hi := &SHandlerInfo{}
hi = confCb(method, hi)
if hi != nil {
hi.SetMethod(method)
hi.SetPath(prefix)
hi.SetHandler(handler)
app.AddHandler3(hi)
}
}
}
+3 -3
View File
@@ -63,15 +63,15 @@ type IHost interface {
}
func GetComputeSession(ctx context.Context) *mcclient.ClientSession {
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region)
return auth.GetAdminSession(ctx, options.HostOptions.Region)
}
func GetK8sSession(ctx context.Context) *mcclient.ClientSession {
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region)
return auth.GetAdminSession(ctx, options.HostOptions.Region)
}
func GetImageSession(ctx context.Context, zone string) *mcclient.ClientSession {
return auth.AdminSessionWithInternal(ctx, options.HostOptions.Region, "")
return auth.AdminSession(ctx, options.HostOptions.Region, zone, "")
}
func TaskFailed(ctx context.Context, reason string) {
+6 -5
View File
@@ -370,7 +370,7 @@ func (catalog KeystoneServiceCatalogV3) getEndpoints(region string, endpointType
}
func RegionID(region, zone string) string {
if len(zone) > 0 {
if len(region) > 0 && len(zone) > 0 {
return fmt.Sprintf("%s%c%s", region, REGION_ZONE_SEP, zone)
} else {
return region
@@ -415,9 +415,10 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en
}
for j := 0; j < len(catalog[i].Endpoints); j++ {
ep := catalog[i].Endpoints[j]
if strings.HasPrefix(endpointType, ep.Interface) && (ep.RegionId == region ||
ep.RegionId == regionzone ||
len(region) == 0) {
if strings.HasPrefix(endpointType, ep.Interface) &&
(ep.RegionId == region ||
ep.RegionId == regionzone ||
len(region) == 0) {
_, ok := regeps[ep.RegionId]
if !ok {
regeps[ep.RegionId] = make([]string, 0)
@@ -432,7 +433,7 @@ func (catalog KeystoneServiceCatalogV3) GetServiceURLs(service, region, zone, en
break
}
} else {
return nil, fmt.Errorf("No default region")
return nil, fmt.Errorf("No default region for region(%s) zone(%s)", region, zone)
}
} else {
_, ok := regeps[regionzone]