Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4c76d33ef | ||
|
|
c1410dfef1 | ||
|
|
e2d8bd206c | ||
|
|
e47db8325c | ||
|
|
115aa7ffb7 | ||
|
|
6bb28160c8 |
No files matched your search
+5
-7
@@ -9,10 +9,8 @@ httpInnerAddress:
|
|||||||
port: 9003
|
port: 9003
|
||||||
moduleName: isp-gate
|
moduleName: isp-gate
|
||||||
instanceUuid: 9d89354b-c728-4b48-b002-a7d3b229f151
|
instanceUuid: 9d89354b-c728-4b48-b002-a7d3b229f151
|
||||||
locations:
|
routerConfig:
|
||||||
- pathPrefix: /api
|
routerModuleName: router
|
||||||
protocol: grpc
|
pathPrefix: /api
|
||||||
targetModule: router
|
skipAuth: false
|
||||||
- pathPrefix: /mdm
|
skipExistCheck: false
|
||||||
protocol: http
|
|
||||||
targetModule: mdm-api
|
|
||||||
+6
-24
@@ -11,31 +11,13 @@ type (
|
|||||||
ConfigServiceAddress structure.AddressConfiguration `valid:"required~Required"`
|
ConfigServiceAddress structure.AddressConfiguration `valid:"required~Required"`
|
||||||
HttpOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"httpOuterAddress"`
|
HttpOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"httpOuterAddress"`
|
||||||
HttpInnerAddress structure.AddressConfiguration `valid:"required~Required" json:"httpInnerAddress"`
|
HttpInnerAddress structure.AddressConfiguration `valid:"required~Required" json:"httpInnerAddress"`
|
||||||
Locations []Location
|
RouterConfig RouterConfig `valid:"required~Required" json:"routerConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Location struct {
|
RouterConfig struct {
|
||||||
SkipAuth bool
|
RouterModuleName string `valid:"required~Required"`
|
||||||
SkipExistCheck bool
|
PathPrefix string `valid:"required~Required"`
|
||||||
PathPrefix string `valid:"required~Required"`
|
SkipAuth bool
|
||||||
Protocol string `valid:"required~Required"`
|
SkipExistCheck bool
|
||||||
TargetModule string `valid:"required~Required"`
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetLocationsByTargetModule(locations []Location) map[string][]Location {
|
|
||||||
requiredModules := make(map[string][]Location)
|
|
||||||
|
|
||||||
for _, location := range locations {
|
|
||||||
if location.TargetModule == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if loc, ok := requiredModules[location.TargetModule]; ok {
|
|
||||||
requiredModules[location.TargetModule] = append(loc, location)
|
|
||||||
} else {
|
|
||||||
requiredModules[location.TargetModule] = []Location{location}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return requiredModules
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.3.5
|
github.com/golang/protobuf v1.3.5
|
||||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f
|
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f
|
||||||
github.com/integration-system/isp-journal v1.5.0
|
github.com/integration-system/isp-journal v1.5.0
|
||||||
github.com/integration-system/isp-lib/v2 v2.6.3-0.20200925192756-f336302805fa
|
github.com/integration-system/isp-lib/v2 v2.6.3
|
||||||
github.com/integration-system/isp-log v1.1.5
|
github.com/integration-system/isp-log v1.1.5
|
||||||
github.com/json-iterator/go v1.1.10
|
github.com/json-iterator/go v1.1.10
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f h1:52UOJ
|
|||||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f/go.mod h1:w+dmaWojuIwNujSYg6qt1wKHhSdorLOivCEl/XuLzbM=
|
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f/go.mod h1:w+dmaWojuIwNujSYg6qt1wKHhSdorLOivCEl/XuLzbM=
|
||||||
github.com/integration-system/gowsdl v1.0.0 h1:rDv5HrzNUs6aWTj9roSDS9ZdIf58FzF0YVP2nusvbto=
|
github.com/integration-system/gowsdl v1.0.0 h1:rDv5HrzNUs6aWTj9roSDS9ZdIf58FzF0YVP2nusvbto=
|
||||||
github.com/integration-system/gowsdl v1.0.0/go.mod h1:ZwTCE+Av5aQLnPj2/3PIop6mzCs1FY7jXrcWDvSjrBA=
|
github.com/integration-system/gowsdl v1.0.0/go.mod h1:ZwTCE+Av5aQLnPj2/3PIop6mzCs1FY7jXrcWDvSjrBA=
|
||||||
github.com/integration-system/isp-etp-go/v2 v2.1.0 h1:qRw4J04vwYxSm52OUIt6lKWpxEQE2aZjUT7kZDG/A4Q=
|
|
||||||
github.com/integration-system/isp-etp-go/v2 v2.1.0/go.mod h1:Ndq5DMM3sDJjZn4cyKKvZrVED0FMeoXMRWHZTq+2Z1o=
|
github.com/integration-system/isp-etp-go/v2 v2.1.0/go.mod h1:Ndq5DMM3sDJjZn4cyKKvZrVED0FMeoXMRWHZTq+2Z1o=
|
||||||
github.com/integration-system/isp-etp-go/v2 v2.1.1 h1:6LU9eE1cGVpp8HNRYu83K4hY49YlNPFd/uj3+Iog4ro=
|
github.com/integration-system/isp-etp-go/v2 v2.1.1 h1:6LU9eE1cGVpp8HNRYu83K4hY49YlNPFd/uj3+Iog4ro=
|
||||||
github.com/integration-system/isp-etp-go/v2 v2.1.1/go.mod h1:Ndq5DMM3sDJjZn4cyKKvZrVED0FMeoXMRWHZTq+2Z1o=
|
github.com/integration-system/isp-etp-go/v2 v2.1.1/go.mod h1:Ndq5DMM3sDJjZn4cyKKvZrVED0FMeoXMRWHZTq+2Z1o=
|
||||||
@@ -193,10 +192,9 @@ github.com/integration-system/isp-io v0.0.0-20190723122940-3daf588d878f h1:nJGOo
|
|||||||
github.com/integration-system/isp-io v0.0.0-20190723122940-3daf588d878f/go.mod h1:1cjy4g5F8WXrOB3l/bL3mw+TCWDppOL1pz08wOAMi9Y=
|
github.com/integration-system/isp-io v0.0.0-20190723122940-3daf588d878f/go.mod h1:1cjy4g5F8WXrOB3l/bL3mw+TCWDppOL1pz08wOAMi9Y=
|
||||||
github.com/integration-system/isp-journal v1.5.0 h1:7Lpt7dHhpq1zRY4qRRYUMiEnaQZbxyPHRcy/ik/Vm8I=
|
github.com/integration-system/isp-journal v1.5.0 h1:7Lpt7dHhpq1zRY4qRRYUMiEnaQZbxyPHRcy/ik/Vm8I=
|
||||||
github.com/integration-system/isp-journal v1.5.0/go.mod h1:B6cLJqjNL+XHWv4IzKt5aIZ7AjbHX2tQFXgRSaWNNIo=
|
github.com/integration-system/isp-journal v1.5.0/go.mod h1:B6cLJqjNL+XHWv4IzKt5aIZ7AjbHX2tQFXgRSaWNNIo=
|
||||||
github.com/integration-system/isp-lib/v2 v2.3.1 h1:jPsrovXg3yt+A64AQB+Mc/KyJYcC8d+MZK3OLSHCxZY=
|
|
||||||
github.com/integration-system/isp-lib/v2 v2.3.1/go.mod h1:eRSmS3+S8WXTUKu7YtSimFJDrLF+/esM/989NBEsP2o=
|
github.com/integration-system/isp-lib/v2 v2.3.1/go.mod h1:eRSmS3+S8WXTUKu7YtSimFJDrLF+/esM/989NBEsP2o=
|
||||||
github.com/integration-system/isp-lib/v2 v2.6.3-0.20200925192756-f336302805fa h1:sORWdPlJqhLpYnYfyB67dDQ1u8LJqPwlawQQhEiNQ4k=
|
github.com/integration-system/isp-lib/v2 v2.6.3 h1:YbIids+aslyi4ieToYjUuWbPoQ4i4d4Ld4dNC8AVvSU=
|
||||||
github.com/integration-system/isp-lib/v2 v2.6.3-0.20200925192756-f336302805fa/go.mod h1:ZGW7qQsCuELBHRBnSSDSEonPx+FxAfHiAfwsGQZzVO4=
|
github.com/integration-system/isp-lib/v2 v2.6.3/go.mod h1:ZGW7qQsCuELBHRBnSSDSEonPx+FxAfHiAfwsGQZzVO4=
|
||||||
github.com/integration-system/isp-log v1.1.2 h1:bnWxPjDOC1Y/tEzFxa42aG+xaPRWizuJADAwXgp2i5U=
|
github.com/integration-system/isp-log v1.1.2 h1:bnWxPjDOC1Y/tEzFxa42aG+xaPRWizuJADAwXgp2i5U=
|
||||||
github.com/integration-system/isp-log v1.1.2/go.mod h1:VVMr3cHW+RuFurPUSeVz71KUnOGQxogxO5atV9N8ISs=
|
github.com/integration-system/isp-log v1.1.2/go.mod h1:VVMr3cHW+RuFurPUSeVz71KUnOGQxogxO5atV9N8ISs=
|
||||||
github.com/integration-system/isp-log v1.1.5 h1:YiMx+hV2YyCTfHu5vIjtqSkRtPjr/WY9xvKsvONDVNU=
|
github.com/integration-system/isp-log v1.1.5 h1:YiMx+hV2YyCTfHu5vIjtqSkRtPjr/WY9xvKsvONDVNU=
|
||||||
@@ -221,11 +219,13 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
|
|||||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||||
|
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
|
||||||
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||||
github.com/klauspost/compress v1.10.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
github.com/klauspost/compress v1.10.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||||
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
|
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
|
||||||
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||||
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||||
|
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
|
||||||
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||||
@@ -388,6 +388,7 @@ github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2
|
|||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.4.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
|
github.com/valyala/fasthttp v1.4.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
|
||||||
|
github.com/valyala/fasthttp v1.9.0 h1:hNpmUdy/+ZXYpGy0OBfm7K0UQTzb73W0T0U4iJIVrMw=
|
||||||
github.com/valyala/fasthttp v1.9.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
|
github.com/valyala/fasthttp v1.9.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
|
||||||
github.com/valyala/fasthttp v1.16.0 h1:9zAqOYLl8Tuy3E5R6ckzGDJ1g8+pw15oQp2iL9Jl6gQ=
|
github.com/valyala/fasthttp v1.16.0 h1:9zAqOYLl8Tuy3E5R6ckzGDJ1g8+pw15oQp2iL9Jl6gQ=
|
||||||
github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
|
github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
|
||||||
@@ -413,13 +414,10 @@ go.opentelemetry.io/otel v0.5.0 h1:tdIR1veg/z+VRJaw/6SIxz+QX3l+m+BDleYLTs+GC1g=
|
|||||||
go.opentelemetry.io/otel v0.5.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek=
|
go.opentelemetry.io/otel v0.5.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek=
|
||||||
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
||||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
|
|
||||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||||
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
|
|
||||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
|
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||||
go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||||
@@ -443,10 +441,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
|
|||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@@ -539,7 +535,6 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df h1:oQFmpjL+rb2xLkgPCpdGSAGDdq1geTZVvIfCMxSB/wQ=
|
|
||||||
golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200220224806-8a925fa4c0df/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200826040757-bc8aaaa29e06 h1:ChBCbOHeLqK+j+znGPlWCcvx/t2PdxmyPBheVZxXbcc=
|
golang.org/x/tools v0.0.0-20200826040757-bc8aaaa29e06 h1:ChBCbOHeLqK+j+znGPlWCcvx/t2PdxmyPBheVZxXbcc=
|
||||||
golang.org/x/tools v0.0.0-20200826040757-bc8aaaa29e06/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200826040757-bc8aaaa29e06/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
@@ -598,7 +593,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
|||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.2 h1:8w2Ud1JmaU9M5os2j8aKMpPs4guVq+RMUN5phK2najE=
|
|
||||||
honnef.co/go/tools v0.0.1-2020.1.2/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.2/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
|
mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
|
||||||
mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
|
mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
|
||||||
|
|||||||
+2
-2
@@ -67,7 +67,8 @@ func CompleteRequest(ctx *fasthttp.RequestCtx) {
|
|||||||
func (handlerHelper) AuthenticateAccountingProxy(ctx *fasthttp.RequestCtx) (string, domain.ProxyResponse) {
|
func (handlerHelper) AuthenticateAccountingProxy(ctx *fasthttp.RequestCtx) (string, domain.ProxyResponse) {
|
||||||
initialPath := string(ctx.Path())
|
initialPath := string(ctx.Path())
|
||||||
|
|
||||||
p, path := proxy.Find(initialPath)
|
p := proxy.RoutingProxy
|
||||||
|
path := proxy.GetPathWithoutApiPrefix(initialPath)
|
||||||
if p == nil {
|
if p == nil {
|
||||||
msg := fmt.Sprintf("unknown proxy for '%s'", initialPath)
|
msg := fmt.Sprintf("unknown proxy for '%s'", initialPath)
|
||||||
utils.WriteError(ctx, msg, codes.NotFound, nil)
|
utils.WriteError(ctx, msg, codes.NotFound, nil)
|
||||||
@@ -96,7 +97,6 @@ func (handlerHelper) AuthenticateAccountingProxy(ctx *fasthttp.RequestCtx) (stri
|
|||||||
utils.WriteError(ctx, message, status, details)
|
utils.WriteError(ctx, message, status, details)
|
||||||
return path, domain.Create().SetError(err)
|
return path, domain.Create().SetError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !accounting.AcceptRequest(applicationId, path) {
|
if !accounting.AcceptRequest(applicationId, path) {
|
||||||
err := errAccounting
|
err := errAccounting
|
||||||
utils.WriteError(ctx, "too many requests", codes.ResourceExhausted, nil)
|
utils.WriteError(ctx, "too many requests", codes.ResourceExhausted, nil)
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
"github.com/integration-system/isp-lib/v2/config/schema"
|
"github.com/integration-system/isp-lib/v2/config/schema"
|
||||||
"github.com/integration-system/isp-lib/v2/metric"
|
"github.com/integration-system/isp-lib/v2/metric"
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
"github.com/integration-system/isp-lib/v2/structure"
|
||||||
log "github.com/integration-system/isp-log"
|
|
||||||
"github.com/integration-system/isp-log/stdcodes"
|
|
||||||
"isp-gate-service/accounting"
|
"isp-gate-service/accounting"
|
||||||
"isp-gate-service/authenticate"
|
"isp-gate-service/authenticate"
|
||||||
"isp-gate-service/conf"
|
"isp-gate-service/conf"
|
||||||
@@ -39,17 +37,11 @@ func main() {
|
|||||||
SocketConfiguration(socketConfiguration).
|
SocketConfiguration(socketConfiguration).
|
||||||
RequireRoutes(handleRouteUpdate).
|
RequireRoutes(handleRouteUpdate).
|
||||||
RequireModule("journal", invoker.Journal.ReceiveServiceAddressList, false).
|
RequireModule("journal", invoker.Journal.ReceiveServiceAddressList, false).
|
||||||
SubscribeBroadcastEvent(bootstrap.ListenRestartEvent())
|
SubscribeBroadcastEvent(bootstrap.ListenRestartEvent()).OnShutdown(onShutdown)
|
||||||
|
|
||||||
requiredModules, err := proxy.InitProxies(cfg.Locations)
|
proxy.ApiPathPrefix = cfg.RouterConfig.PathPrefix
|
||||||
if err != nil {
|
proxyConsumer := proxy.InitRoutingProxy(cfg.RouterConfig.SkipAuth, cfg.RouterConfig.SkipExistCheck)
|
||||||
log.Fatal(stdcodes.ModuleInvalidLocalConfig, err)
|
bs.RequireModule(cfg.RouterConfig.RouterModuleName, proxyConsumer, true).
|
||||||
}
|
|
||||||
for module, consumer := range requiredModules {
|
|
||||||
bs.RequireModule(module, consumer, false)
|
|
||||||
}
|
|
||||||
bs.RequireModule(cfg.ModuleName, accounting.NewConnectionConsumer, false).
|
|
||||||
OnShutdown(onShutdown).
|
|
||||||
OnRemoteConfigReceive(onRemoteConfigReceive).
|
OnRemoteConfigReceive(onRemoteConfigReceive).
|
||||||
Run()
|
Run()
|
||||||
}
|
}
|
||||||
@@ -99,10 +91,6 @@ func onShutdown(_ context.Context, _ os.Signal) {
|
|||||||
|
|
||||||
func handleRouteUpdate(configs structure.RoutingConfig) bool {
|
func handleRouteUpdate(configs structure.RoutingConfig) bool {
|
||||||
routing.InitRoutes(configs)
|
routing.InitRoutes(configs)
|
||||||
err := proxy.InitProxiesFromConfigs(configs)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(stdcodes.ReceiveErrorFromConfig, err)
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
package grpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/proxy/grpc/handlers"
|
|
||||||
)
|
|
||||||
|
|
||||||
type grpcProxy struct {
|
|
||||||
client *backend.RxGrpcClient
|
|
||||||
skipAuth bool
|
|
||||||
skipExistCheck bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProxy(skipAuth, skipExistCheck bool) *grpcProxy {
|
|
||||||
return &grpcProxy{
|
|
||||||
client: backend.NewRxGrpcClient(
|
|
||||||
backend.WithDialOptions(
|
|
||||||
grpc.WithInsecure(),
|
|
||||||
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(int(conf.DefaultMaxResponseBodySize))),
|
|
||||||
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(int(conf.DefaultMaxResponseBodySize))),
|
|
||||||
)),
|
|
||||||
skipAuth: skipAuth,
|
|
||||||
skipExistCheck: skipExistCheck,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *grpcProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
|
|
||||||
return handlers.Handler.Get(ctx).Complete(ctx, path, p.client)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *grpcProxy) Consumer(addr []structure.AddressConfiguration) bool {
|
|
||||||
return p.client.ReceiveAddressList(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *grpcProxy) SkipAuth() bool {
|
|
||||||
return p.skipAuth
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *grpcProxy) SkipExistCheck() bool {
|
|
||||||
return p.skipExistCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *grpcProxy) Close() {
|
|
||||||
_ = p.client.Close()
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
structpb "github.com/golang/protobuf/ptypes/struct"
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
"github.com/integration-system/isp-lib/v2/config"
|
|
||||||
http2 "github.com/integration-system/isp-lib/v2/http"
|
|
||||||
"github.com/integration-system/isp-lib/v2/isp"
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
|
||||||
"github.com/integration-system/isp-lib/v2/utils"
|
|
||||||
log "github.com/integration-system/isp-log"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/log_code"
|
|
||||||
utils2 "isp-gate-service/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
headerKeyContentDisposition = "Content-Disposition"
|
|
||||||
headerKeyContentType = "Content-Type"
|
|
||||||
headerKeyContentLength = "Content-Length"
|
|
||||||
headerKeyTransferEncoding = "Transfer-Encoding"
|
|
||||||
|
|
||||||
errorMsgInternal = "Internal server error"
|
|
||||||
errorMsgInvalidArg = "Not able to read request body"
|
|
||||||
)
|
|
||||||
|
|
||||||
var json = jsoniter.ConfigFastest
|
|
||||||
|
|
||||||
func convertError(err error) ([]byte, int) {
|
|
||||||
s, ok := status.FromError(err)
|
|
||||||
if !ok {
|
|
||||||
return []byte(utils.ServiceError), http.StatusServiceUnavailable
|
|
||||||
}
|
|
||||||
cfg := config.GetRemote().(*conf.RemoteConfig).GrpcSetting
|
|
||||||
if cfg.EnableOriginalProtoErrors {
|
|
||||||
body, err := proto.Marshal(s.Proto())
|
|
||||||
if err != nil {
|
|
||||||
return []byte(utils.ServiceError), http.StatusServiceUnavailable
|
|
||||||
}
|
|
||||||
return body, http2.CodeToHttpStatus(s.Code())
|
|
||||||
}
|
|
||||||
|
|
||||||
details := s.Details()
|
|
||||||
newDetails := make([]interface{}, len(details))
|
|
||||||
for i, detail := range details {
|
|
||||||
switch typeOfDetail := detail.(type) {
|
|
||||||
case *structpb.Struct:
|
|
||||||
newDetails[i] = utils.ConvertGrpcStructToInterface(
|
|
||||||
&structpb.Value{Kind: &structpb.Value_StructValue{StructValue: typeOfDetail}},
|
|
||||||
)
|
|
||||||
case *isp.Message:
|
|
||||||
newDetails[i] = utils.ConvertGrpcStructToInterface(
|
|
||||||
backend.ResolveBody(typeOfDetail),
|
|
||||||
)
|
|
||||||
default:
|
|
||||||
newDetails[i] = typeOfDetail
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var respBody interface{}
|
|
||||||
if cfg.ProxyGrpcErrorDetails && len(newDetails) > 0 {
|
|
||||||
respBody = newDetails[0]
|
|
||||||
} else {
|
|
||||||
respBody = structure.GrpcError{ErrorMessage: s.Message(), ErrorCode: s.Code().String(), Details: newDetails}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorData, err := json.Marshal(respBody)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn(log_code.WarnConvertErrorDataMarshalResponse, err)
|
|
||||||
return []byte(utils.ServiceError), http.StatusServiceUnavailable
|
|
||||||
}
|
|
||||||
return errorData, http2.CodeToHttpStatus(s.Code())
|
|
||||||
}
|
|
||||||
|
|
||||||
func getResponse(msg *isp.Message, err error) ([]byte, int, error) {
|
|
||||||
if err != nil {
|
|
||||||
errorBody, errorStatus := convertError(err)
|
|
||||||
return errorBody, errorStatus, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes := msg.GetBytesBody()
|
|
||||||
if bytes != nil {
|
|
||||||
return bytes, http.StatusOK, nil
|
|
||||||
}
|
|
||||||
result := backend.ResolveBody(msg)
|
|
||||||
data := utils.ConvertGrpcStructToInterface(result)
|
|
||||||
byteResponse, err := json.Marshal(data)
|
|
||||||
return byteResponse, http.StatusOK, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func logHandlerError(typeData, method string, err error) {
|
|
||||||
log.WithMetadata(map[string]interface{}{
|
|
||||||
log_code.MdTypeData: typeData,
|
|
||||||
log_code.MdMethod: method,
|
|
||||||
}).Warn(log_code.WarnProxyGrpcHandler, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func openStream(headers *fasthttp.RequestHeader, method string, timeout time.Duration, client *backend.RxGrpcClient) (
|
|
||||||
isp.BackendService_RequestStreamClient, context.CancelFunc, error) {
|
|
||||||
cli := client.Conn()
|
|
||||||
md, _ := makeMetadata(headers, method)
|
|
||||||
ctx := metadata.NewOutgoingContext(context.Background(), md)
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
|
||||||
stream, err := cli.RequestStream(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
return stream, cancel, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeMetadata(r *fasthttp.RequestHeader, method string) (metadata.MD, string) {
|
|
||||||
md := make(metadata.MD, 5)
|
|
||||||
md[utils.ProxyMethodNameHeader] = []string{method}
|
|
||||||
r.VisitAll(func(key, v []byte) {
|
|
||||||
lowerHeader := bytes.ToLower(key)
|
|
||||||
if len(v) > 0 && bytes.HasPrefix(lowerHeader, []byte("x-")) {
|
|
||||||
md[string(lowerHeader)] = []string{string(v)}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return md, method
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkError(err error, ctx *fasthttp.RequestCtx, method string) (bool, bool, domain.ProxyResponse) {
|
|
||||||
var (
|
|
||||||
ok = true
|
|
||||||
eof = false
|
|
||||||
resp = domain.ProxyResponse{}
|
|
||||||
msg = errorMsgInternal
|
|
||||||
code = codes.Internal
|
|
||||||
details []interface{} = nil
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
s, itStatus := status.FromError(err)
|
|
||||||
if itStatus {
|
|
||||||
msg = s.Message()
|
|
||||||
code = s.Code()
|
|
||||||
details = s.Details()
|
|
||||||
}
|
|
||||||
logHandlerError(log_code.TypeData.GetFile, method, err)
|
|
||||||
utils2.WriteError(ctx, msg, code, details)
|
|
||||||
resp = domain.Create().SetError(err)
|
|
||||||
ok, eof = false, false
|
|
||||||
} else {
|
|
||||||
ok, eof = true, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ok, eof, resp
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
u "github.com/integration-system/isp-lib/v2/utils"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/utils"
|
|
||||||
"mime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Handler handlerHelper
|
|
||||||
|
|
||||||
type (
|
|
||||||
handlerHelper struct{}
|
|
||||||
|
|
||||||
handler interface {
|
|
||||||
Complete(ctx *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient) domain.ProxyResponse
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h handlerHelper) Get(ctx *fasthttp.RequestCtx) handler {
|
|
||||||
isMultipart := h.isMultipart(ctx)
|
|
||||||
isExpectFile := string(ctx.Request.Header.Peek(u.ExpectFileHeader)) == "true"
|
|
||||||
|
|
||||||
if isMultipart {
|
|
||||||
ctx.Response.Header.SetContentTypeBytes(utils.JsonContentType)
|
|
||||||
return sendMultipartData
|
|
||||||
}
|
|
||||||
if isExpectFile {
|
|
||||||
return getFile
|
|
||||||
}
|
|
||||||
ctx.Response.Header.SetContentTypeBytes(utils.JsonContentType)
|
|
||||||
return handleJson
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h handlerHelper) isMultipart(ctx *fasthttp.RequestCtx) bool {
|
|
||||||
if !ctx.IsPost() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
v := string(ctx.Request.Header.ContentType())
|
|
||||||
if v == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
d, params, err := mime.ParseMediaType(v)
|
|
||||||
if err != nil || d != "multipart/form-data" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_, ok := params["boundary"]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
"github.com/integration-system/isp-lib/v2/config"
|
|
||||||
"github.com/integration-system/isp-lib/v2/isp"
|
|
||||||
s "github.com/integration-system/isp-lib/v2/streaming"
|
|
||||||
u "github.com/integration-system/isp-lib/v2/utils"
|
|
||||||
log "github.com/integration-system/isp-log"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"io"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/log_code"
|
|
||||||
"isp-gate-service/utils"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errInvalidJson = errors.New("invalid json format. Expected object or array")
|
|
||||||
getFile getFileDesc
|
|
||||||
)
|
|
||||||
|
|
||||||
type getFileDesc struct{}
|
|
||||||
|
|
||||||
func (g getFileDesc) Complete(ctx *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient) domain.ProxyResponse {
|
|
||||||
req, err := g.readJsonBody(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return g.formError(ctx, err, method, err.Error(), codes.InvalidArgument)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout := config.GetRemote().(*conf.RemoteConfig).GrpcSetting.GetStreamInvokeTimeout()
|
|
||||||
stream, cancel, err := openStream(&ctx.Request.Header, method, timeout, client)
|
|
||||||
defer func() {
|
|
||||||
if cancel != nil {
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return g.formError(ctx, err, method, errorMsgInternal, codes.Internal)
|
|
||||||
}
|
|
||||||
|
|
||||||
if req != nil {
|
|
||||||
value := u.ConvertInterfaceToGrpcStruct(req)
|
|
||||||
err := stream.Send(backend.WrapBody(value))
|
|
||||||
if err != nil {
|
|
||||||
return g.formError(ctx, err, method, errorMsgInternal, codes.Internal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err := stream.Recv()
|
|
||||||
if err != nil {
|
|
||||||
response, status, err := getResponse(nil, err)
|
|
||||||
if err == nil {
|
|
||||||
ctx.SetStatusCode(status)
|
|
||||||
ctx.SetBody(response)
|
|
||||||
}
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bf := s.BeginFile{}
|
|
||||||
err = bf.FromMessage(msg)
|
|
||||||
if err != nil {
|
|
||||||
response, status, err := getResponse(nil, err)
|
|
||||||
if err == nil {
|
|
||||||
ctx.SetStatusCode(status)
|
|
||||||
ctx.SetBody(response)
|
|
||||||
}
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
header := &ctx.Response.Header
|
|
||||||
header.Set(headerKeyContentDisposition, fmt.Sprintf("attachment; filename=%s", bf.FileName))
|
|
||||||
header.Set(headerKeyContentType, bf.ContentType)
|
|
||||||
if bf.ContentLength > 0 {
|
|
||||||
header.Set(headerKeyContentLength, strconv.Itoa(int(bf.ContentLength)))
|
|
||||||
} else {
|
|
||||||
header.Set(headerKeyTransferEncoding, "chunked")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = g.write(ctx, stream, method)
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint
|
|
||||||
func (getFileDesc) write(ctx *fasthttp.RequestCtx, stream isp.BackendService_RequestStreamClient, method string) error {
|
|
||||||
for {
|
|
||||||
msg, err := stream.Recv()
|
|
||||||
if s.IsEndOfFile(msg) || err == io.EOF {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.GetFile, method, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
bytes := msg.GetBytesBody()
|
|
||||||
if bytes == nil {
|
|
||||||
log.WithMetadata(map[string]interface{}{
|
|
||||||
log_code.MdTypeData: log_code.TypeData.GetFile,
|
|
||||||
log_code.MdMethod: method,
|
|
||||||
}).Errorf(log_code.WarnProxyGrpcHandler, "Method %s. Expected bytes array", method)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_, err = ctx.Write(bytes)
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.GetFile, method, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (getFileDesc) readJsonBody(ctx *fasthttp.RequestCtx) (interface{}, error) {
|
|
||||||
requestBody := ctx.Request.Body()
|
|
||||||
var body interface{}
|
|
||||||
if len(requestBody) == 0 {
|
|
||||||
requestBody = []byte("{}")
|
|
||||||
}
|
|
||||||
switch requestBody[0] {
|
|
||||||
case '{':
|
|
||||||
body = make(map[string]interface{})
|
|
||||||
case '[':
|
|
||||||
body = make([]interface{}, 0)
|
|
||||||
default:
|
|
||||||
return nil, errInvalidJson
|
|
||||||
}
|
|
||||||
err := json.Unmarshal(requestBody, &body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return body, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (getFileDesc) formError(ctx *fasthttp.RequestCtx, err error, method, msg string, code codes.Code) domain.ProxyResponse {
|
|
||||||
logHandlerError(log_code.TypeData.GetFile, method, err)
|
|
||||||
utils.WriteError(ctx, msg, code, nil)
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
"github.com/integration-system/isp-lib/v2/config"
|
|
||||||
"github.com/integration-system/isp-lib/v2/isp"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/log_code"
|
|
||||||
"isp-gate-service/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
var handleJson handleJsonDesc
|
|
||||||
|
|
||||||
type handleJsonDesc struct{}
|
|
||||||
|
|
||||||
func (p handleJsonDesc) Complete(c *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient) domain.ProxyResponse {
|
|
||||||
body := c.Request.Body()
|
|
||||||
|
|
||||||
md, methodName := makeMetadata(&c.Request.Header, method)
|
|
||||||
ctx := metadata.NewOutgoingContext(context.Background(), md)
|
|
||||||
grpcSetting := config.GetRemote().(*conf.RemoteConfig).GrpcSetting
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, grpcSetting.GetSyncInvokeTimeout())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
cli := client.Conn()
|
|
||||||
|
|
||||||
msg, invokerErr := cli.Request(
|
|
||||||
ctx,
|
|
||||||
&isp.Message{
|
|
||||||
Body: &isp.Message_BytesBody{BytesBody: body},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if response, status, err := getResponse(msg, invokerErr); err == nil {
|
|
||||||
c.SetStatusCode(status)
|
|
||||||
c.SetContentTypeBytes(utils.JsonContentType)
|
|
||||||
c.Response.Header.SetContentLength(len(response))
|
|
||||||
_, _ = c.Write(response)
|
|
||||||
return domain.Create().SetRequestBody(body).SetResponseBody(c.Response.Body()).SetError(invokerErr)
|
|
||||||
} else {
|
|
||||||
logHandlerError(log_code.TypeData.JsonContent, methodName, err)
|
|
||||||
utils.WriteError(c, errorMsgInternal, codes.Internal, nil)
|
|
||||||
return domain.Create().SetRequestBody(body).SetResponseBody(c.Response.Body()).SetError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/backend"
|
|
||||||
"github.com/integration-system/isp-lib/v2/config"
|
|
||||||
"github.com/integration-system/isp-lib/v2/isp"
|
|
||||||
s "github.com/integration-system/isp-lib/v2/streaming"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/log_code"
|
|
||||||
"isp-gate-service/utils"
|
|
||||||
"mime/multipart"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var sendMultipartData sendMultipartDataDesc
|
|
||||||
|
|
||||||
type sendMultipartDataDesc struct{}
|
|
||||||
|
|
||||||
func (h sendMultipartDataDesc) Complete(c *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient) domain.ProxyResponse {
|
|
||||||
cfg := config.GetRemote().(*conf.RemoteConfig).GrpcSetting
|
|
||||||
timeout := cfg.GetStreamInvokeTimeout()
|
|
||||||
|
|
||||||
stream, cancel, err := openStream(&c.Request.Header, method, timeout, client)
|
|
||||||
defer func() {
|
|
||||||
if cancel != nil {
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.SendMultipart, method, err)
|
|
||||||
utils.WriteError(c, errorMsgInternal, codes.Internal, nil)
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
form, err := c.MultipartForm()
|
|
||||||
defer func() {
|
|
||||||
if form != nil {
|
|
||||||
_ = form.RemoveAll()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.SendMultipart, method, err)
|
|
||||||
utils.WriteError(c, errorMsgInvalidArg, codes.InvalidArgument, nil)
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, proxyResp, ok := h.formResponse(c, stream, form, method)
|
|
||||||
err = stream.CloseSend()
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.SendMultipart, method, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
arrayBody := strings.Join(resp, ",")
|
|
||||||
_, err = c.WriteString("[" + arrayBody + "]")
|
|
||||||
if err != nil {
|
|
||||||
logHandlerError(log_code.TypeData.SendMultipart, method, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return proxyResp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h sendMultipartDataDesc) formResponse(c *fasthttp.RequestCtx, stream isp.BackendService_RequestStreamClient,
|
|
||||||
form *multipart.Form, method string) ([]string, domain.ProxyResponse, bool) {
|
|
||||||
formData := make(map[string]interface{}, len(form.Value))
|
|
||||||
for k, v := range form.Value {
|
|
||||||
if len(v) > 0 {
|
|
||||||
formData[k] = v[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
resp = make([]string, 0)
|
|
||||||
buffer = make([]byte, config.GetRemote().(*conf.RemoteConfig).GrpcSetting.GetTransferFileBufferSize())
|
|
||||||
proxyResp domain.ProxyResponse
|
|
||||||
ok = true
|
|
||||||
eof bool
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
for formDataName, files := range form.File {
|
|
||||||
if len(files) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
file := files[0]
|
|
||||||
fileName := file.Filename
|
|
||||||
contentType := file.Header.Get(headerKeyContentType)
|
|
||||||
contentLength := file.Size
|
|
||||||
bf := s.BeginFile{
|
|
||||||
FileName: fileName,
|
|
||||||
FormDataName: formDataName,
|
|
||||||
ContentType: contentType,
|
|
||||||
ContentLength: contentLength,
|
|
||||||
FormData: formData,
|
|
||||||
}
|
|
||||||
err = stream.Send(bf.ToMessage())
|
|
||||||
ok, eof, proxyResp = checkError(err, c, method)
|
|
||||||
if !ok || eof {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := file.Open()
|
|
||||||
ok, eof, proxyResp = checkError(err, c, method)
|
|
||||||
if !ok || eof {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, eof, proxyResp = h.transferFile(f, stream, buffer, c, method)
|
|
||||||
if !ok || eof {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, invokeErr := stream.Recv()
|
|
||||||
ok, eof, proxyResp = checkError(invokeErr, c, method)
|
|
||||||
if !ok || eof {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
response, _, err := getResponse(msg, invokeErr)
|
|
||||||
if err != nil {
|
|
||||||
ok = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
resp = append(resp, string(response))
|
|
||||||
}
|
|
||||||
return resp, proxyResp, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sendMultipartDataDesc) transferFile(f multipart.File, stream isp.BackendService_RequestStreamClient,
|
|
||||||
buffer []byte, ctx *fasthttp.RequestCtx, method string) (bool, bool, domain.ProxyResponse) {
|
|
||||||
var (
|
|
||||||
ok = true
|
|
||||||
eof bool
|
|
||||||
proxyResp domain.ProxyResponse
|
|
||||||
)
|
|
||||||
for {
|
|
||||||
n, err := f.Read(buffer)
|
|
||||||
if n > 0 {
|
|
||||||
err = stream.Send(&isp.Message{Body: &isp.Message_BytesBody{BytesBody: buffer[:n]}})
|
|
||||||
ok, eof, proxyResp = checkError(err, ctx, method)
|
|
||||||
if !ok || eof {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
ok, eof, proxyResp = checkError(err, ctx, method)
|
|
||||||
if ok && eof {
|
|
||||||
err = stream.Send(s.FileEnd())
|
|
||||||
ok, eof, proxyResp = checkError(err, ctx, method)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ok, eof, proxyResp
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package health_check
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
)
|
|
||||||
|
|
||||||
type healthCheckProxy struct {
|
|
||||||
skipAuth bool
|
|
||||||
skipExistCheck bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProxy(skipAuth, skipExistCheck bool) *healthCheckProxy {
|
|
||||||
return &healthCheckProxy{skipAuth: skipAuth, skipExistCheck: skipExistCheck}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *healthCheckProxy) Consumer(addressList []structure.AddressConfiguration) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *healthCheckProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
|
|
||||||
ctx.Response.SetBody(ctx.Request.Body())
|
|
||||||
ctx.Request.SetRequestURI(path)
|
|
||||||
return domain.Create()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *healthCheckProxy) SkipAuth() bool {
|
|
||||||
return p.skipAuth
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *healthCheckProxy) SkipExistCheck() bool {
|
|
||||||
return p.skipExistCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *healthCheckProxy) Close() {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -18,17 +18,17 @@ var (
|
|||||||
errNotInitialized = errors.New("http proxy not initialized")
|
errNotInitialized = errors.New("http proxy not initialized")
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpProxy struct {
|
type HttpProxy struct {
|
||||||
client *fasthttp.HostClient
|
client *fasthttp.HostClient
|
||||||
skipAuth bool
|
skipAuth bool
|
||||||
skipExistCheck bool
|
skipExistCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxy(skipAuth, skipExistCheck bool) *httpProxy {
|
func NewProxy(skipAuth, skipExistCheck bool) *HttpProxy {
|
||||||
return &httpProxy{client: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
|
return &HttpProxy{client: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) Consumer(addressList []structure.AddressConfiguration) bool {
|
func (p *HttpProxy) Consumer(addressList []structure.AddressConfiguration) bool {
|
||||||
if len(addressList) == 0 {
|
if len(addressList) == 0 {
|
||||||
p.client = nil
|
p.client = nil
|
||||||
return true
|
return true
|
||||||
@@ -44,7 +44,7 @@ func (p *httpProxy) Consumer(addressList []structure.AddressConfiguration) bool
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
|
func (p *HttpProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
|
||||||
client := p.client
|
client := p.client
|
||||||
if client == nil {
|
if client == nil {
|
||||||
log.Error(log_code.ErrorClientHttp, errNotInitialized)
|
log.Error(log_code.ErrorClientHttp, errNotInitialized)
|
||||||
@@ -73,14 +73,14 @@ func (p *httpProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.P
|
|||||||
SetError(err)
|
SetError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) SkipAuth() bool {
|
func (p *HttpProxy) SkipAuth() bool {
|
||||||
return p.skipAuth
|
return p.skipAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) SkipExistCheck() bool {
|
func (p *HttpProxy) SkipExistCheck() bool {
|
||||||
return p.skipExistCheck
|
return p.skipExistCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpProxy) Close() {
|
func (p *HttpProxy) Close() {
|
||||||
p.client = nil
|
p.client = nil
|
||||||
}
|
}
|
||||||
+11
-134
@@ -1,30 +1,17 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
"github.com/integration-system/isp-lib/v2/structure"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/domain"
|
"isp-gate-service/domain"
|
||||||
"isp-gate-service/proxy/grpc"
|
|
||||||
"isp-gate-service/proxy/health_check"
|
|
||||||
"isp-gate-service/proxy/http"
|
"isp-gate-service/proxy/http"
|
||||||
"isp-gate-service/proxy/websocket"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
store = make([]storeItem, 0)
|
RoutingProxy *http.HttpProxy
|
||||||
locationsStore = make([]storeItem, 0)
|
ApiPathPrefix string
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
httpProtocol = "http"
|
|
||||||
websocketProtocol = "websocket"
|
|
||||||
grpcProtocol = "grpc"
|
|
||||||
healthCheckProtocol = "healthсheck"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -35,134 +22,24 @@ type (
|
|||||||
SkipExistCheck() bool
|
SkipExistCheck() bool
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
storeItem struct {
|
|
||||||
pathPrefix string
|
|
||||||
paths []string // if pathPrefix is empty
|
|
||||||
proxy Proxy
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitProxies(locations []conf.Location) (map[string]func([]structure.AddressConfiguration) bool, error) {
|
func InitRoutingProxy(skipAuth bool, skipExistCheck bool) func(list []structure.AddressConfiguration) bool {
|
||||||
locationsByTargetModule := conf.GetLocationsByTargetModule(locations)
|
RoutingProxy = http.NewProxy(skipAuth, skipExistCheck)
|
||||||
requiredModules := make(map[string]func([]structure.AddressConfiguration) bool)
|
return func(list []structure.AddressConfiguration) bool {
|
||||||
|
RoutingProxy.Consumer(list)
|
||||||
for targetModule, locations := range locationsByTargetModule {
|
return true
|
||||||
consumerStorage := make([]func([]structure.AddressConfiguration) bool, len(locations))
|
|
||||||
for i, location := range locations {
|
|
||||||
if location.PathPrefix[0] != '/' {
|
|
||||||
return nil, errors.Errorf("path must begin with '/' in path '%s'", location.PathPrefix)
|
|
||||||
}
|
|
||||||
p, err := makeProxy(location.Protocol, location.SkipAuth, location.SkipExistCheck)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
store = append(store, storeItem{
|
|
||||||
pathPrefix: location.PathPrefix,
|
|
||||||
proxy: p,
|
|
||||||
})
|
|
||||||
consumerStorage[i] = p.Consumer
|
|
||||||
}
|
|
||||||
requiredModules[targetModule] = aggregateConsumers(consumerStorage...)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(store, func(i, j int) bool {
|
|
||||||
return store[i].pathPrefix > store[j].pathPrefix
|
|
||||||
})
|
|
||||||
locationsStore = store
|
|
||||||
return requiredModules, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitProxiesFromConfigs(configs structure.RoutingConfig) error {
|
|
||||||
store = locationsStore
|
|
||||||
for _, config := range configs { //nolint
|
|
||||||
ip := config.Address.IP
|
|
||||||
|
|
||||||
for protocol, info := range config.HandlersInfo {
|
|
||||||
p, err := makeProxy(protocol, info.SkipAuth, info.SkipExistCheck)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "bad dynamic config in service %s with protocol %s", config.ModuleName, protocol)
|
|
||||||
}
|
|
||||||
addressConfig := []structure.AddressConfiguration{{
|
|
||||||
Port: info.Port,
|
|
||||||
IP: ip,
|
|
||||||
}}
|
|
||||||
p.Consumer(addressConfig)
|
|
||||||
item := storeItem{
|
|
||||||
pathPrefix: "",
|
|
||||||
proxy: p,
|
|
||||||
paths: getPathsFromEndpoints(info.Endpoints),
|
|
||||||
}
|
|
||||||
store = append(store, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPathsFromEndpoints(endpoints []structure.EndpointDescriptor) []string {
|
|
||||||
paths := make([]string, len(endpoints)-1)
|
|
||||||
for i := range endpoints {
|
|
||||||
endpoint := endpoints[i]
|
|
||||||
paths = append(paths, endpoint.Path)
|
|
||||||
}
|
|
||||||
return paths
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeProxy(protocol string, skipAuth, skipExistCheck bool) (Proxy, error) {
|
|
||||||
var proxy Proxy
|
|
||||||
switch protocol {
|
|
||||||
case httpProtocol:
|
|
||||||
proxy = http.NewProxy(skipAuth, skipExistCheck)
|
|
||||||
case grpcProtocol:
|
|
||||||
proxy = grpc.NewProxy(skipAuth, skipExistCheck)
|
|
||||||
case healthCheckProtocol:
|
|
||||||
proxy = health_check.NewProxy(skipAuth, skipExistCheck)
|
|
||||||
case websocketProtocol:
|
|
||||||
proxy = websocket.NewProxy(skipAuth, skipExistCheck)
|
|
||||||
default:
|
|
||||||
return nil, errors.Errorf("unknown protocol '%s'", protocol)
|
|
||||||
}
|
|
||||||
|
|
||||||
return proxy, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Find(path string) (Proxy, string) {
|
|
||||||
for _, item := range store {
|
|
||||||
if item.pathPrefix != "" {
|
|
||||||
if strings.HasPrefix(path, item.pathPrefix) {
|
|
||||||
return item.proxy, getPathWithoutPrefix(path, item.pathPrefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, iPath := range item.paths {
|
|
||||||
if path == iPath {
|
|
||||||
return item.proxy, path
|
|
||||||
}
|
|
||||||
if path == "/"+iPath {
|
|
||||||
return item.proxy, path[1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func Close() {
|
|
||||||
for _, p := range store {
|
|
||||||
p.proxy.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPathWithoutPrefix(path, prefix string) string {
|
func GetPathWithoutApiPrefix(initialPath string) string {
|
||||||
s := strings.TrimPrefix(path, prefix)
|
s := strings.TrimPrefix(initialPath, ApiPathPrefix)
|
||||||
if len(s) > 0 && s[0] == '/' {
|
if len(s) > 0 && s[0] == '/' {
|
||||||
return s[1:]
|
return s[1:]
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func aggregateConsumers(consumers ...func([]structure.AddressConfiguration) bool) func([]structure.AddressConfiguration) bool {
|
func Close() {
|
||||||
return func(list []structure.AddressConfiguration) bool {
|
RoutingProxy.Close()
|
||||||
for _, consumer := range consumers {
|
|
||||||
consumer(list)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package proxy //nolint
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_getPathWithoutPrefix(t *testing.T) {
|
|
||||||
type args struct {
|
|
||||||
path string
|
|
||||||
prefix string
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want string
|
|
||||||
}{
|
|
||||||
{name: "#1", args: args{
|
|
||||||
path: "/api/some/11/22",
|
|
||||||
prefix: "/api/some",
|
|
||||||
}, want: "11/22"},
|
|
||||||
{name: "#2", args: args{
|
|
||||||
path: "/api/service/group/method",
|
|
||||||
prefix: "/api",
|
|
||||||
}, want: "service/group/method"},
|
|
||||||
}
|
|
||||||
for _, test := range tests {
|
|
||||||
tt := test
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
if got := getPathWithoutPrefix(tt.args.path, tt.args.prefix); got != tt.want {
|
|
||||||
t.Errorf("getPathWithoutPrefix() = %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package websocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
type RoundRobinAddrs struct {
|
|
||||||
mu *sync.Mutex
|
|
||||||
addrs []structure.AddressConfiguration
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *RoundRobinAddrs) Get() structure.AddressConfiguration {
|
|
||||||
u.mu.Lock()
|
|
||||||
u.index = (u.index + 1) % len(u.addrs)
|
|
||||||
addr := u.addrs[u.index]
|
|
||||||
u.mu.Unlock()
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRoundRobinAddrs(addrs []structure.AddressConfiguration) *RoundRobinAddrs {
|
|
||||||
return &RoundRobinAddrs{
|
|
||||||
addrs: addrs,
|
|
||||||
index: -1,
|
|
||||||
mu: new(sync.Mutex),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
package websocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"net/http/cookiejar"
|
|
||||||
"net/url"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/fasthttp/websocket"
|
|
||||||
"github.com/integration-system/isp-lib/v2/structure"
|
|
||||||
log "github.com/integration-system/isp-log"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"isp-gate-service/domain"
|
|
||||||
"isp-gate-service/log_code"
|
|
||||||
"isp-gate-service/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
writeBufSize = 4 << 10
|
|
||||||
readBufSize = 4 << 10
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errNoAddresses = errors.New("no available address")
|
|
||||||
pool = &sync.Pool{New: func() interface{} {
|
|
||||||
buf := make([]byte, readBufSize)
|
|
||||||
return &buf
|
|
||||||
}}
|
|
||||||
)
|
|
||||||
|
|
||||||
// used to filter client request headers
|
|
||||||
//
|
|
||||||
var forbiddenDuplicateHeaders = map[string]struct{}{
|
|
||||||
"Upgrade": {},
|
|
||||||
"Connection": {},
|
|
||||||
"Sec-Websocket-Key": {},
|
|
||||||
"Sec-Websocket-Version": {},
|
|
||||||
"Sec-Websocket-Extensions": {},
|
|
||||||
"Sec-Websocket-Protocol": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
var upgrader = websocket.FastHTTPUpgrader{
|
|
||||||
ReadBufferSize: readBufSize,
|
|
||||||
WriteBufferSize: writeBufSize,
|
|
||||||
CheckOrigin: func(ctx *fasthttp.RequestCtx) bool {
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
type websocketProxy struct {
|
|
||||||
addrs *RoundRobinAddrs
|
|
||||||
skipAuth bool
|
|
||||||
skipExistCheck bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProxy(skipAuth, skipExistCheck bool) *websocketProxy {
|
|
||||||
return &websocketProxy{addrs: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) Consumer(addressList []structure.AddressConfiguration) bool {
|
|
||||||
if len(addressList) == 0 {
|
|
||||||
p.addrs = nil
|
|
||||||
} else {
|
|
||||||
p.addrs = NewRoundRobinAddrs(addressList)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
|
|
||||||
addrs := p.addrs
|
|
||||||
if addrs == nil {
|
|
||||||
msg := errNoAddresses
|
|
||||||
log.Error(log_code.ErrorWebsocketProxy, msg)
|
|
||||||
utils.WriteError(ctx, msg.Error(), codes.Internal, nil)
|
|
||||||
return domain.Create().
|
|
||||||
SetRequestBody(ctx.Request.Body()).
|
|
||||||
SetResponseBody(ctx.Response.Body()).
|
|
||||||
SetError(errNoAddresses)
|
|
||||||
}
|
|
||||||
|
|
||||||
reqHeaders := fasthttp.RequestHeader{}
|
|
||||||
ctx.Request.Header.CopyTo(&reqHeaders)
|
|
||||||
reqHost := string(ctx.Request.URI().Host())
|
|
||||||
reqScheme := string(ctx.Request.URI().Scheme())
|
|
||||||
|
|
||||||
if addr, _, err := net.SplitHostPort(ctx.RemoteAddr().String()); err == nil {
|
|
||||||
reqHeaders.Add("X-Forwarded-For", addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := upgrader.Upgrade(ctx, func(incomingConn *websocket.Conn) {
|
|
||||||
outgoingDialer := websocket.Dialer{
|
|
||||||
ReadBufferSize: readBufSize,
|
|
||||||
WriteBufferSize: writeBufSize,
|
|
||||||
NetDial: net.Dial,
|
|
||||||
}
|
|
||||||
|
|
||||||
addr := addrs.Get()
|
|
||||||
uri := ctx.Request.URI()
|
|
||||||
uri.SetSchemeBytes([]byte("ws"))
|
|
||||||
uri.SetHost(addr.GetAddress())
|
|
||||||
uri.SetPath("/" + path)
|
|
||||||
header := http.Header{}
|
|
||||||
|
|
||||||
reqHeaders.VisitAll(func(key, value []byte) {
|
|
||||||
keyStr := string(key)
|
|
||||||
if _, forbidden := forbiddenDuplicateHeaders[keyStr]; !forbidden {
|
|
||||||
header.Add(keyStr, string(value))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
cookie := make([]*http.Cookie, 0)
|
|
||||||
reqHeaders.VisitAllCookie(func(key, value []byte) {
|
|
||||||
cookie = append(cookie, &http.Cookie{Domain: reqHost, Name: string(key), Value: string(value)})
|
|
||||||
})
|
|
||||||
cookies := &cookiejar.Jar{}
|
|
||||||
cookies.SetCookies(&url.URL{Host: reqHost, Scheme: reqScheme}, cookie)
|
|
||||||
outgoingDialer.Jar = cookies
|
|
||||||
|
|
||||||
//nolint
|
|
||||||
outgoingConn, _, err := outgoingDialer.Dial(uri.String(), header)
|
|
||||||
if err == nil {
|
|
||||||
go func() {
|
|
||||||
_ = p.proxyConn(outgoingConn, incomingConn)
|
|
||||||
}()
|
|
||||||
_ = p.proxyConn(incomingConn, outgoingConn)
|
|
||||||
} else {
|
|
||||||
log.Errorf(log_code.ErrorWebsocketProxy, "unable to connect to service %s: %v", uri.String(), err)
|
|
||||||
_ = incomingConn.Close()
|
|
||||||
_ = outgoingConn.Close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return domain.Create().SetError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) SkipAuth() bool {
|
|
||||||
return p.skipAuth
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) SkipExistCheck() bool {
|
|
||||||
return p.skipExistCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) Close() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *websocketProxy) proxyConn(from, to *websocket.Conn) error {
|
|
||||||
buf := pool.Get().(*[]byte)
|
|
||||||
defer func() {
|
|
||||||
_ = from.Close()
|
|
||||||
_ = to.Close()
|
|
||||||
pool.Put(buf)
|
|
||||||
}()
|
|
||||||
for {
|
|
||||||
msgType, reader, err := from.NextReader()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
writer, err := to.NextWriter(msgType)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.CopyBuffer(writer, reader, *buf); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := writer.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+10
-4
@@ -19,15 +19,15 @@ func InitRoutes(configs structure.RoutingConfig) {
|
|||||||
if backend.Address.IP == "" {
|
if backend.Address.IP == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if backend.HandlersInfo == nil {
|
if len(backend.HandlersInfo) == 0 {
|
||||||
if len(backend.Endpoints) == 0 || backend.Address.Port == "" {
|
if len(backend.Endpoints) == 0 || backend.Address.Port == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addEndpointsToMaps(backend.Endpoints, newAddressMap, newInnerAddressMap, newAuthUserAddressMap)
|
addEndpointsToMaps(backend.Endpoints, "", newAddressMap, newInnerAddressMap, newAuthUserAddressMap)
|
||||||
} else {
|
} else {
|
||||||
for _, info := range backend.HandlersInfo {
|
for _, info := range backend.HandlersInfo {
|
||||||
if info.Port != "" {
|
if info.Port != "" {
|
||||||
addEndpointsToMaps(info.Endpoints, newAddressMap, newInnerAddressMap, newAuthUserAddressMap)
|
addEndpointsToMaps(info.Endpoints, info.PathPrefix, newAddressMap, newInnerAddressMap, newAuthUserAddressMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,14 @@ func InitRoutes(configs structure.RoutingConfig) {
|
|||||||
AuthUserMethods = newAuthUserAddressMap
|
AuthUserMethods = newAuthUserAddressMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func addEndpointsToMaps(endpoints []structure.EndpointDescriptor, newAddressMap map[string]bool, newInnerAddressMap map[string]bool, newAuthUserAddressMap map[string]bool) { //nolint
|
func addEndpointsToMaps(endpoints []structure.EndpointDescriptor,
|
||||||
|
pathPrefix string, newAddressMap map[string]bool,
|
||||||
|
newInnerAddressMap map[string]bool,
|
||||||
|
newAuthUserAddressMap map[string]bool) {
|
||||||
for _, el := range endpoints {
|
for _, el := range endpoints {
|
||||||
|
if pathPrefix != "" {
|
||||||
|
el.Path = pathPrefix + "/" + el.Path
|
||||||
|
}
|
||||||
newAddressMap[el.Path] = true
|
newAddressMap[el.Path] = true
|
||||||
if el.Inner {
|
if el.Inner {
|
||||||
newInnerAddressMap[el.Path] = true
|
newInnerAddressMap[el.Path] = true
|
||||||
|
|||||||
Reference in new issue
Block a user