Commit 6b1ca99a authored by leitao.zhang's avatar leitao.zhang

Merge branch 'dev'

parents 7fc26e82 bb28b487
...@@ -2,22 +2,21 @@ workspace: ...@@ -2,22 +2,21 @@ workspace:
path: src/gitlab.wodcloud.com/apaas/apaas-meshproxy path: src/gitlab.wodcloud.com/apaas/apaas-meshproxy
clone: clone:
git: git:
image: registry.cn-qingdao.aliyuncs.com/wod-devops/git:1.5.0 image: registry.cn-qingdao.aliyuncs.com/wod/devops-git:1.0
dns: 223.5.5.5 dns: 223.5.5.5
pipeline: pipeline:
go: go:
image: registry.cn-qingdao.aliyuncs.com/wod-devops/go:1.13.1-stretch image: registry.cn-qingdao.aliyuncs.com/wod/devops-go:1.14.4-stretch
dns: 223.5.5.5 dns: 223.5.5.5
environment: environment:
- GOPROXY=https://goproxy.cn,direct - GOPROXY=https://goproxy.cn,direct
main: src main: src
binary: proxy binary: proxy
volumes: volumes:
# - /cache/gopath/pkg:/drone/pkg
- /data/cache/gopath/pkg:/drone/pkg - /data/cache/gopath/pkg:/drone/pkg
docker-dev: docker-dev:
dns: 223.5.5.5 dns: 223.5.5.5
image: registry.cn-qingdao.aliyuncs.com/wod-devops/docker:1.0 image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker:1.0
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8 base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8
...@@ -31,10 +30,10 @@ pipeline: ...@@ -31,10 +30,10 @@ pipeline:
- source: REGISTRY_PASSWORD_ALIYUN - source: REGISTRY_PASSWORD_ALIYUN
target: REGISTRY_PASSWORD target: REGISTRY_PASSWORD
when: when:
branch: [dev] branch: [ dev ]
docker-master: docker-master:
dns: 223.5.5.5 dns: 223.5.5.5
image: registry.cn-qingdao.aliyuncs.com/wod-devops/docker:1.0 image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker:1.0
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8 base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8
...@@ -47,20 +46,20 @@ pipeline: ...@@ -47,20 +46,20 @@ pipeline:
- source: REGISTRY_PASSWORD_ALIYUN - source: REGISTRY_PASSWORD_ALIYUN
target: REGISTRY_PASSWORD target: REGISTRY_PASSWORD
when: when:
branch: [master] branch: [ master ]
# docker-latest: docker-release:
# image: registry.cn-qingdao.aliyuncs.com/wod-devops/docker:1.0 dns: 223.5.5.5
# volumes: image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker:1.0
# - /var/run/docker.sock:/var/run/docker.sock volumes:
# base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8 - /var/run/docker.sock:/var/run/docker.sock
# repo: wod/apaas-meshproxy base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.8
# version: v3 repo: wod/apaas-meshproxy
# registry: hub.wodcloud.com version: "v3.0"
# secrets: registry: registry.cn-qingdao.aliyuncs.com
# - source: REGISTRY_USER secrets:
# target: REGISTRY_USER - source: REGISTRY_USER_ALIYUN
# - source: REGISTRY_PASSWORD target: REGISTRY_USER
# target: REGISTRY_PASSWORD - source: REGISTRY_PASSWORD_ALIYUN
# when: target: REGISTRY_PASSWORD
# branch: [master] when:
branch: [ master ]
\ No newline at end of file
...@@ -8,11 +8,11 @@ import ( ...@@ -8,11 +8,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/spf13/cast"
"github.com/vulcand/oxy/forward" "github.com/vulcand/oxy/forward"
"github.com/vulcand/oxy/testutils" "github.com/vulcand/oxy/testutils"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/service" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/service"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
...@@ -165,7 +165,24 @@ func Proxy(c *gin.Context) { ...@@ -165,7 +165,24 @@ func Proxy(c *gin.Context) {
reqURL.RawQuery = c.Request.URL.RawQuery reqURL.RawQuery = c.Request.URL.RawQuery
} else { } else {
if c.Request.URL.RawQuery != "" { if c.Request.URL.RawQuery != "" {
reqURL.RawQuery = "&" + c.Request.URL.RawQuery oldQ := c.Request.URL.Query()
newQ := c.Request.URL.Query()
for k, v := range newQ {
if len(v) > 1 {
for kk, vv := range v {
if kk == 0 {
oldQ.Set(k, vv)
} else {
oldQ.Add(k, vv)
}
}
} else if len(v) == 1 {
oldQ.Set(k, v[0])
} else {
oldQ.Del(k)
}
}
reqURL.RawQuery = oldQ.Encode()
} }
} }
...@@ -174,6 +191,10 @@ func Proxy(c *gin.Context) { ...@@ -174,6 +191,10 @@ func Proxy(c *gin.Context) {
c.Request.RequestURI = reqURL.RequestURI() c.Request.RequestURI = reqURL.RequestURI()
fmt.Println("c.Request-------", c.Request) fmt.Println("c.Request-------", c.Request)
c.Request.Host = getHost(proxyData.ReqUrl) c.Request.Host = getHost(proxyData.ReqUrl)
//发送服务ID和用户ID
c.Request.Header.Set("applyuserid", proxyData.ApplyUserId)
c.Request.Header.Set("applyserviceid", cast.ToString(proxyData.ServiceId))
fmt.Println("proxyData.RealUrl-------", proxyData.ReqUrl) fmt.Println("proxyData.RealUrl-------", proxyData.ReqUrl)
forwarder.ServeHTTP(c.Writer, c.Request) forwarder.ServeHTTP(c.Writer, c.Request)
} }
...@@ -248,39 +269,44 @@ func getHost(httpurl string) (path string) { ...@@ -248,39 +269,44 @@ func getHost(httpurl string) (path string) {
func HealthCheck(c *gin.Context) { func HealthCheck(c *gin.Context) {
res := model.WebRes{} res := model.WebRes{}
apiId := c.Param("apiid")
proxyData, err := service.GetReqPath(apiId)
if err != nil {
res.Data = err.Error()
c.JSON(500, res)
return
}
var requstMethod string
//获取真实地址1GET 2POST 3 PUT 4 DELETE
if proxyData.ReqType == 1 {
requstMethod = "GET"
} else if proxyData.ReqType == 2 {
requstMethod = "POST"
} else if proxyData.ReqType == 3 {
requstMethod = "PUT"
} else if proxyData.ReqType == 4 {
requstMethod = "DELETE"
}
header := make(map[string]string, 0)
resp, err := tools.ProxySendRes(c.Request, requstMethod, proxyData.ReqUrl, "", header)
if err != nil {
res.Data = err.Error()
c.JSON(500, res)
return
}
fmt.Println(resp)
if resp.StatusCode < 400 {
res.Data = "success"
} else {
res.Data = "fail"
}
res.Success = 1 res.Success = 1
//请求真实地址根据返回状态码判断是否服务可用 res.Data = "success"
c.JSON(200, res) c.JSON(200, res)
return
//
//apiId := c.Param("apiid")
//proxyData, err := service.GetReqPath(apiId)
//if err != nil {
// res.Data = err.Error()
// c.JSON(500, res)
// return
//}
//var requstMethod string
////获取真实地址1GET 2POST 3 PUT 4 DELETE
//if proxyData.ReqType == 1 {
// requstMethod = "GET"
//} else if proxyData.ReqType == 2 {
// requstMethod = "POST"
//} else if proxyData.ReqType == 3 {
// requstMethod = "PUT"
//} else if proxyData.ReqType == 4 {
// requstMethod = "DELETE"
//}
//header := make(map[string]string, 0)
//resp, err := tools.ProxySendRes(c.Request, requstMethod, proxyData.ReqUrl, "", header)
//if err != nil {
// res.Data = err.Error()
// c.JSON(500, res)
// return
//}
//fmt.Println(resp)
//if resp.StatusCode < 400 {
// res.Data = "success"
//} else {
// res.Data = "fail"
//}
//res.Success = 1
////请求真实地址根据返回状态码判断是否服务可用
//c.JSON(200, res)
//return
} }
...@@ -50,7 +50,7 @@ func Options(c *gin.Context) { ...@@ -50,7 +50,7 @@ func Options(c *gin.Context) {
// and resource access headers. // and resource access headers.
func Secure(c *gin.Context) { func Secure(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Origin", "*")
c.Header("X-Frame-Options", "DENY") c.Header("X-Frame-Options", "ALLOWALL")
c.Header("X-Content-Type-Options", "nosniff") c.Header("X-Content-Type-Options", "nosniff")
c.Header("X-XSS-Protection", "1; mode=block") c.Header("X-XSS-Protection", "1; mode=block")
if c.Request.TLS != nil { if c.Request.TLS != nil {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package service package service
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/spf13/cast" "github.com/spf13/cast"
...@@ -280,16 +279,20 @@ func ApplyCallCounts(proxyData model.ProxyData) (err error) { ...@@ -280,16 +279,20 @@ func ApplyCallCounts(proxyData model.ProxyData) (err error) {
//过滤返回字段 //过滤返回字段
func FiledFilter(proxyData model.ProxyData, respbody []byte) []byte { func FiledFilter(proxyData model.ProxyData, respbody []byte) []byte {
var fields []request.ServiceField
fields = dataconvertutil.GetResponseField(proxyData.ResFields)
_, arrmodel := dataconvertutil.ConvertJson(fields)
realData := make(map[string]interface{})
json.Unmarshal(respbody, &realData)
if arrmodel != nil && len(arrmodel) != 0 && len(realData) != 0 {
bytes, _ := json.Marshal(Change(arrmodel[0], realData))
return bytes
}
return respbody return respbody
//var fields []request.ServiceField
//fields = dataconvertutil.GetResponseField(proxyData.ResFields)
//_, arrmodel := dataconvertutil.ConvertJson(fields)
//realData := make(map[string]interface{})
//if err := json.Unmarshal(respbody, &realData); err != nil {
// return respbody
//}
//if arrmodel != nil && len(arrmodel) != 0 && len(realData) != 0 {
// bytes, _ := json.Marshal(Change(arrmodel[0], realData))
// return bytes
//}
//return respbody
} }
//返回申请字段 //返回申请字段
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment