Compare commits

..
47 Commits
Author SHA1 Message Date
txix 6750784d6b 2026-11-25 17:38:41: merge [main:34e3ef7687c1506c4d688719cc57c11df2f68a5b]; 2026-11-25 17:38:41 +03:00
txix 45ae8cdd89 2026-09-11 11:33:36: merge [main:4e924575ceb7011a063532a69d7d70bdcbe380ed]; 2026-09-11 11:33:36 +03:00
txix 295513e91c 2026-09-10 14:03:06: merge [main:7abecf78adc18de750bedc3f5130c12e2cbdeab7]; 2026-09-10 14:03:06 +03:00
txix 36699fdc72 2026-08-28 15:17:49: merge [main:657d4302881986193395aa831b36df6fd0798d4d];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-08-28 15:17:49 +03:00
txix a269de8e17 2026-07-27 16:33:30: merge [main:227a2a069d1922a94e2a88af2863dac3035f705d];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-07-27 16:33:30 +03:00
txix 15cb2cadf2 2026-07-07 10:21:49: merge [main:7d936adaf0486f3328902461e9a32ae3539e9e64];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-07-07 10:21:49 +03:00
txix 76f88fd593 2026-05-12 13:56:16: merge [main:81e9195d79a530c26a2640652f946389f536842f];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-05-12 13:56:16 +03:00
txix 9ff0057014 2026-04-20 12:28:32: merge [main:ac8a556442b323a61053fc1f978ce68455350ad0];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-04-20 12:28:32 +03:00
txix 71a1f0a04e 2026-04-08 18:36:43: merge [main:cca6ce0ad1fef44571b4a61f1aca34f2e41ce5cd];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-04-08 18:36:43 +03:00
txix 394bbc82e2 2026-04-06 15:36:37: merge [main:48e53159863d08bc31c4e926d73c0bb4341128ae];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-04-06 15:36:37 +03:00
txix 7de248e63c 2026-03-31 16:58:42: merge [main:8b672bdd308ebb53d48d75a6a5bfbdb7ea8d7ddd];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-03-31 16:58:43 +03:00
txix 011a1d7048 2026-03-24 17:42:31: merge [main:c523d2347d1bdc87bceae397a11ecfc8776ff8aa];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-03-24 17:42:31 +03:00
txix f3fb9cff75 2026-03-18 17:07:55: merge [main:1bd032e5aa9a3d83735ea3fb30aeab719d917b82];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-03-18 17:07:55 +03:00
txix c7bd042239 2026-03-10 10:38:58: merge [main:aae3c282252c73901b8e48b1412f48217b1a6195];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-03-10 10:38:58 +03:00
txix 202fa7035e 2026-01-27 15:11:45: merge [main:30d731ebfa46bcfb3fa1c39f4580293dc546acc0];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-01-27 15:11:45 +03:00
txix 602a2a1ac4 2026-01-27 13:25:45: merge [main:e5e723811e7a9dc57a6ff5d1c067c07c23a97210];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-01-27 13:25:45 +03:00
txix 6a3abf67a2 2026-01-23 13:09:31: merge [main:63c694e2a33c8c0b025f62619d2814f536915e49];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-01-23 13:09:31 +03:00
txix 2f88738f78 2026-01-23 12:57:58: merge [main:4f90477e73bbbbbfe9cdb168b87e0ea201679912];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-01-23 12:57:58 +03:00
txix a637d56ea7 2026-01-14 11:52:30: merge [main:1a274e79e588612933ce36c33b236a91fc74db9a];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2026-01-14 11:52:30 +03:00
txix a841cd082b 2025-12-26 09:37:14: merge [main:2b5ee66527f48ea4e6111148c0ba3c23611d6772];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-12-26 09:37:14 +03:00
txix 9b18fe7351 2025-11-26 13:43:01: merge [main:e9c5c9b80517122ca122933c111070bf470e31c1];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-11-26 13:43:01 +03:00
txix f3c801e4a4 2025-11-26 10:05:59: merge [main:96f8e79d3384c01bf52552f94afdf4ed662997e5];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-11-26 10:05:59 +03:00
txix ee13991d87 2025-10-03 15:15:07: merge [main:c3e3ed9636c6987e89feaf39503dda74462fcfde];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-10-03 15:15:07 +03:00
txix d4846359e4 2025-10-02 16:02:08: merge [main:13db082fcac220b28433a207845ceb3bef8bd07d];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-10-02 16:02:08 +03:00
txix 13cf0075f6 2025-09-17 18:07:26: merge [main:f5bfe7d2ba0d7a2f391f4ffaff6fffc1686ba3c7];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-09-17 18:07:26 +03:00
txix 135e551473 2025-08-21 15:04:13: merge [main:a4b6e5fd1d9685c751c5988518e9f8dd62a8e519]; 2025-08-21 15:04:13 +03:00
txix 689f730a3e 2025-07-09 12:35:19: merge [main:9f485b5e57937029be52e58137ef79ad5c3ca524];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-07-09 12:35:19 +03:00
txix a30582fa38 2025-07-03 12:26:31: merge [main:66e6c4b9c432b19b644d033703545d38aba3b847];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-07-03 12:26:31 +03:00
txix 5b1ce14467 2025-07-01 16:40:11: merge [main:61f11c0bda72fe35f473f8302edfaf86f151c0ad];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-07-01 16:40:11 +03:00
txix 264b438cdb 2025-07-01 13:32:55: merge [main:6491e79afd06cd665731c89f8ab2cd373351c1b4]; 2025-07-01 13:32:55 +03:00
txix f699aefa58 2025-05-27 14:32:05: merge [master:01f8dcdc36fb3f9867a65ffb7379ad25c85cd988];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-05-27 14:32:05 +03:00
txix 8d40e76637 2025-05-13 13:05:46: merge [master:49d1bfaa3f027c5465de7a0c0d46a9bab0588e19]; 2025-05-13 13:05:46 +03:00
txix e2b4becfd6 2025-04-29 14:57:30: merge [master:357ce03935a551e8be5766b349a621104998de83]; 2025-04-29 14:57:30 +03:00
txix e4ef2d8645 2025-04-23 12:39:56: merge [master:82ac257e917aa3f9ab915b911afbd28c0f52f88e]; 2025-04-23 12:39:56 +03:00
txix bfc28503d5 2025-04-18 12:46:39: merge [master:7b5fc0b41640a6b6648e6391777fa08099997af1]; 2025-04-18 12:46:39 +03:00
txix d759f883f4 2025-04-18 12:26:12: merge [master:576ef18526fa6f0685f8ab997cae0d31a4ebce90]; 2025-04-18 12:26:13 +03:00
txix 64373fdf3c 2025-04-03 17:31:43: merge [master:03df79d7b37febb99439347c2da79707bf437498]; 2025-04-03 17:31:43 +03:00
txix 1dd566593e 2024-12-27 17:46:16: merge [master:4898a95fc423e3ae55135d3023a1b78fb18edebc]; 2024-12-27 17:46:16 +03:00
txix 560c1f22c4 2024-12-27 12:28:18: merge [master:9ec52bd8525d6120bfebe62b6da4eb172a000ee8]; 2024-12-27 12:28:18 +03:00
txix 171b85f627 2024-12-27 12:14:12: merge [master:bf6ba426f66d82ef1e76da30674890898919501b]; 2024-12-27 12:14:12 +03:00
txix 734b83b2b8 2024-12-11 12:34:04: merge [master:744eaa2605c9d3eb73b2db76661b2d0a6949d4d9]; 2024-12-11 12:34:04 +03:00
txix bdeb2c0753 2024-12-03 13:02:16: merge [master:b21f96b8a5ec988002a89bd9d1f51e90c01a2d21]; 2024-12-03 13:02:16 +03:00
txix 97c44fb3bd 2024-10-11 14:58:36: merge [master:7f99b95ceaaed865d2833070a0397cf191949b8e]; 2024-10-11 14:58:36 +03:00
txix 6db18c1495 2024-07-01 10:56:14: merge [master:f9b2632335c35844013af97443dacebb9fc385c5]; 2024-07-01 10:56:14 +03:00
txix cd985ff5a3 2024-03-26 12:20:05: merge [master:27c825f7051ccbb42344a2d66c50192e2b3b5889]; 2024-03-26 12:20:05 +03:00
txix 2eed857503 2024-03-22 15:21:57: merge [master:d3624ee87e4530490024ae4023a1c69643689e95]; 2024-03-22 15:21:57 +03:00
txix 2b91caece0 2024-01-22 17:22:41: merge [master:56d3e06e49d7a75f142424293788a4f3b6245430]; 2024-01-22 17:22:41 +03:00
20 changed files with 143 additions and 129 deletions

No files matched your search

-10
View File
@@ -65,16 +65,6 @@ linters:
- unqueryvet - unqueryvet
- prealloc - prealloc
path: ".*_test\\.go$" path: ".*_test\\.go$"
- linters:
- wrapcheck
path: middleware #отсутствует необходимость оборачивать ошибки
- linters:
- gochecknoglobals
- mnd
path: proxy
- linters:
- wrapcheck
path: httperrors #отсутствует необходимость оборачивать ошибки
- linters: - linters:
- goconst - goconst
path: "tests/" # компонентные тесты: фикстуры и моки не выносим в константы path: "tests/" # компонентные тесты: фикстуры и моки не выносим в константы
+1 -1
View File
@@ -1 +1 @@
5.12.0 5.11.5
+4 -2
View File
@@ -1,5 +1,7 @@
### v5.12.0 ### v5.11.5
* взаимодействие с `isp-admin-service` переведено с gRPC на HTTP * Обновлена версия go до версии 1.27
* Обновлены правила для linter
* Обновлены зависимости
### v5.11.4 ### v5.11.4
* добавлена возможность через переменную окружения `adminServiceName` переопределить название сервиса `msp-admin-service` * добавлена возможность через переменную окружения `adminServiceName` переопределить название сервиса `msp-admin-service`
### v5.11.3 ### v5.11.3
+6 -4
View File
@@ -14,7 +14,6 @@ import (
"github.com/txix-open/isp-kit/errors" "github.com/txix-open/isp-kit/errors"
"github.com/txix-open/isp-kit/grpc/client" "github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/http" "github.com/txix-open/isp-kit/http"
"github.com/txix-open/isp-kit/http/httpclix"
"github.com/txix-open/isp-kit/lb" "github.com/txix-open/isp-kit/lb"
"github.com/txix-open/isp-kit/log" "github.com/txix-open/isp-kit/log"
) )
@@ -31,7 +30,7 @@ type Assembly struct {
logger *log.Adapter logger *log.Adapter
routes *routes.Routes routes *routes.Routes
systemCli *client.Client systemCli *client.Client
adminCli *httpclix.ClientBalancer adminCli *client.Client
lockerCli *client.Client lockerCli *client.Client
routerLb *lb.RoundRobin routerLb *lb.RoundRobin
@@ -73,7 +72,10 @@ func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "create system cli") return nil, errors.WithMessage(err, "create system cli")
} }
adminCli := httpclix.DefaultWithBalancer(nil) adminCli, err := client.Default()
if err != nil {
return nil, errors.WithMessage(err, "create admin cli")
}
lockerCli, err := client.Default() lockerCli, err := client.Default()
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "create isp-lock-service client") return nil, errors.WithMessage(err, "create isp-lock-service client")
@@ -171,7 +173,7 @@ func (a *Assembly) Closers() []app.Closer {
for _, cliCloser := range a.grpcClientByModuleName { for _, cliCloser := range a.grpcClientByModuleName {
closers = append(closers, cliCloser) closers = append(closers, cliCloser)
} }
closers = append(closers, a.systemCli, a.lockerCli) closers = append(closers, a.systemCli, a.adminCli, a.lockerCli)
return closers return closers
} }
+2 -3
View File
@@ -5,7 +5,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/txix-open/isp-kit/http/httpclix"
"github.com/txix-open/isp-kit/metrics" "github.com/txix-open/isp-kit/metrics"
"github.com/txix-open/isp-kit/metrics/http_metrics" "github.com/txix-open/isp-kit/metrics/http_metrics"
@@ -30,7 +29,7 @@ type Locator struct {
httpHostManagerByModuleName map[string]*lb.RoundRobin httpHostManagerByModuleName map[string]*lb.RoundRobin
routes *routes.Routes routes *routes.Routes
systemCli *client.Client systemCli *client.Client
adminCli *httpclix.ClientBalancer adminCli *client.Client
lockerCli *client.Client lockerCli *client.Client
routerLb *lb.RoundRobin routerLb *lb.RoundRobin
usersAuthCache *cache.Cache usersAuthCache *cache.Cache
@@ -42,7 +41,7 @@ func NewLocator(
httpHostManagerByModuleName map[string]*lb.RoundRobin, httpHostManagerByModuleName map[string]*lb.RoundRobin,
routes *routes.Routes, routes *routes.Routes,
systemCli *client.Client, systemCli *client.Client,
adminCli *httpclix.ClientBalancer, adminCli *client.Client,
lockerCli *client.Client, lockerCli *client.Client,
routerLb *lb.RoundRobin, routerLb *lb.RoundRobin,
usersAuthCache *cache.Cache, usersAuthCache *cache.Cache,
+3
View File
@@ -8,6 +8,9 @@ type AuthenticateAppResponse struct {
type AppAuthData struct { type AppAuthData struct {
AppName string AppName string
SystemId int
DomainId int
ServiceId int
ApplicationId int ApplicationId int
} }
+3
View File
@@ -2,5 +2,8 @@ package entity
type AppAuthData struct { type AppAuthData struct {
AppName string AppName string
SystemId int
DomainId int
ServiceId int
ApplicationId int ApplicationId int
} }
+6 -7
View File
@@ -1,19 +1,19 @@
module isp-gate-service module isp-gate-service
go 1.27 go 1.27.0
require ( require (
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1 github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3 github.com/gorilla/websocket v1.5.3
github.com/julienschmidt/httprouter v1.3.0 github.com/julienschmidt/httprouter v1.3.0
github.com/redis/go-redis/v9 v9.18.0 github.com/redis/go-redis/v9 v9.24.0
github.com/stretchr/testify v1.12.1 github.com/stretchr/testify v1.12.1
github.com/tomakado/websocketproxy v0.1.0 github.com/tomakado/websocketproxy v0.1.0
github.com/txix-open/etp/v3 v3.2.0 github.com/txix-open/etp/v3 v3.2.0
github.com/txix-open/isp-kit v1.76.0 github.com/txix-open/isp-kit v1.76.0
github.com/txix-open/jsonschema v1.3.0 github.com/txix-open/jsonschema v1.3.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f google.golang.org/genproto/googleapis/rpc v0.0.0-20261123191846-1e707ab9fbc2
google.golang.org/grpc v1.85.0 google.golang.org/grpc v1.85.0
) )
@@ -24,7 +24,6 @@ require (
github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coder/websocket v1.8.15 // indirect github.com/coder/websocket v1.8.15 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.16 // indirect github.com/gabriel-vasile/mimetype v1.4.16 // indirect
github.com/getsentry/sentry-go v0.50.0 // indirect github.com/getsentry/sentry-go v0.50.0 // indirect
github.com/go-faker/faker/v4 v4.12.0 // indirect github.com/go-faker/faker/v4 v4.12.0 // indirect
@@ -34,7 +33,7 @@ require (
github.com/go-playground/universal-translator v0.18.2 // indirect github.com/go-playground/universal-translator v0.18.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.34.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.34.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.20.4 // indirect github.com/klauspost/compress v1.20.5 // indirect
github.com/leodido/go-urn v1.5.0 // indirect github.com/leodido/go-urn v1.5.0 // indirect
github.com/mailru/easyjson v0.9.2 // indirect github.com/mailru/easyjson v0.9.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -53,7 +52,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0 // indirect
go.opentelemetry.io/otel v1.47.0 // indirect go.opentelemetry.io/otel v1.47.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect
@@ -71,7 +70,7 @@ require (
golang.org/x/net v0.63.0 // indirect golang.org/x/net v0.63.0 // indirect
golang.org/x/sys v0.50.0 // indirect golang.org/x/sys v0.50.0 // indirect
golang.org/x/text v0.44.0 // indirect golang.org/x/text v0.44.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f // indirect google.golang.org/genproto/googleapis/api v0.0.0-20261123191846-1e707ab9fbc2 // indirect
google.golang.org/protobuf v1.36.12 // indirect google.golang.org/protobuf v1.36.12 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
+14 -16
View File
@@ -18,8 +18,6 @@ github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNU
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg= github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
github.com/gabriel-vasile/mimetype v1.4.16 h1:5izNFuvA37st1dDRAcA7TtmngBmRgiIPDmTtiEvjx1E= github.com/gabriel-vasile/mimetype v1.4.16 h1:5izNFuvA37st1dDRAcA7TtmngBmRgiIPDmTtiEvjx1E=
@@ -58,10 +56,10 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI= github.com/klauspost/compress v1.20.5 h1:rJj5VjH4xQxbnLphg6eqUcDxRFCw1jpMdDY9qXlrwSs=
github.com/klauspost/compress v1.20.4/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/klauspost/compress v1.20.5/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.4.0 h1:S6Hrbc7+ywsr0r+RLapfGBHfyefhCTwEh3A0tV913Dw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.4.0/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -98,8 +96,8 @@ github.com/prometheus/procfs v0.23.0 h1:ad+S6FTkzwaMgacKLM5h6bNKExS+DMH0YiUwXItH
github.com/prometheus/procfs v0.23.0/go.mod h1:3AVXO0FqLafyYFU/V/IQRZlC8Rgqz8Dm/x6pKLK+RIk= github.com/prometheus/procfs v0.23.0/go.mod h1:3AVXO0FqLafyYFU/V/IQRZlC8Rgqz8Dm/x6pKLK+RIk=
github.com/rabbitmq/amqp091-go v1.17.0 h1:6KmTqrnJq93cGIE3Q3UnXgsqw6NtLu8MNfFoIbfBAIQ= github.com/rabbitmq/amqp091-go v1.17.0 h1:6KmTqrnJq93cGIE3Q3UnXgsqw6NtLu8MNfFoIbfBAIQ=
github.com/rabbitmq/amqp091-go v1.17.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= github.com/rabbitmq/amqp091-go v1.17.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs= github.com/redis/go-redis/v9 v9.24.0 h1:X1AnQHWaSfMeggDQm7UFad1YwJmoZxVm5XkaP0kr6nQ=
github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0= github.com/redis/go-redis/v9 v9.24.0/go.mod h1:ted97kpLnB4S2KJkTkw+7GzRjgkFnU909IIrksu+ut4=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -138,10 +136,10 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.2 h1:ErNn7NW2t1F9CFBLb9iyPMyLRbcEd07l5m/StCe9AEE=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/auto/sdk v1.2.2/go.mod h1:Ca3X8ec6gdTYjAirla//dnp05ECtQPfN4Ut74OJLVsQ=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0 h1:jva1c3z2ZFEQ5sTvnLG2tBALNehO+QvdXKQii6eKRoo= go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0 h1:jva1c3z2ZFEQ5sTvnLG2tBALNehO+QvdXKQii6eKRoo=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0/go.mod h1:3pjFS5EnOVfjvYO6/NMdtJFHFQR+8uiGtrZ965nZP4w= go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.72.0/go.mod h1:3pjFS5EnOVfjvYO6/NMdtJFHFQR+8uiGtrZ965nZP4w=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 h1:LxwW/9ctSCv+QkE/cLR7M91ZIkXNMqJtEMi1vCw9U8s= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.72.0 h1:LxwW/9ctSCv+QkE/cLR7M91ZIkXNMqJtEMi1vCw9U8s=
@@ -188,10 +186,10 @@ golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo=
golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY= golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f h1:7CbYDSDM5xqpq8v2tNm+Q057COf1lvA0gorVk+304tY= google.golang.org/genproto/googleapis/api v0.0.0-20261123191846-1e707ab9fbc2 h1:TVEW5ciB4lPlyo3RBDd2JTlUY0vAzMkPlU/qAzC+rqU=
google.golang.org/genproto/googleapis/api v0.0.0-20261118221215-c8830f628b3f/go.mod h1:CPxXEEQ1S9iJmInAF/8MNc8tKWnya8I8Kni9Zh2hV0M= google.golang.org/genproto/googleapis/api v0.0.0-20261123191846-1e707ab9fbc2/go.mod h1:3q/FqMoaJXT/mbOLAkZaCXuOEpmvBNwYXqdJKeN0gD0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f h1:aDW6Vb2T1K0xbAgW+ED8iz39WlgjjX/OKiNh6tXv/+g= google.golang.org/genproto/googleapis/rpc v0.0.0-20261123191846-1e707ab9fbc2 h1:FCWn4wv5of/ooWpbWDIeOXqI3+h2MGnV7SvvcJ8f+bQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= google.golang.org/genproto/googleapis/rpc v0.0.0-20261123191846-1e707ab9fbc2/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc=
google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw= google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw=
google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ= google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
+6 -1
View File
@@ -3,6 +3,7 @@ package httperrors
import ( import (
"net/http" "net/http"
"github.com/txix-open/isp-kit/errors"
"github.com/txix-open/isp-kit/json" "github.com/txix-open/isp-kit/json"
) )
@@ -33,7 +34,11 @@ func (e *HttpError) WriteError(w http.ResponseWriter) error {
"errorMessage": e.userMessage, "errorMessage": e.userMessage,
"details": e.details, "details": e.details,
} }
return json.NewEncoder(w).Encode(data) err := json.NewEncoder(w).Encode(data)
if err != nil {
return errors.WithMessage(err, "json encode error")
}
return nil
} }
func (e *HttpError) WithDetails(details ...any) { func (e *HttpError) WithDetails(details ...any) {
+6 -2
View File
@@ -35,7 +35,11 @@ func (w *writerWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if !ok { if !ok {
return nil, nil, errors.New("writerWrapper: upstream writer doesn't implement Hijack") return nil, nil, errors.New("writerWrapper: upstream writer doesn't implement Hijack")
} }
return upstream.Hijack() conn, rw, err := upstream.Hijack()
if err != nil {
return nil, nil, errors.WithMessage(err, "hijack error")
}
return conn, rw, nil
} }
func (w *writerWrapper) StatusCode() int { func (w *writerWrapper) StatusCode() int {
@@ -136,7 +140,7 @@ func Logger( // nolint:gocognit,funlen
logger.Debug(ctx.Context(), "log request", fields...) logger.Debug(ctx.Context(), "log request", fields...)
} }
return err return errors.WithMessage(err, "logger middleware error")
}) })
} }
} }
+4 -2
View File
@@ -1,9 +1,11 @@
package middleware package middleware
import ( import (
"isp-gate-service/request"
"time" "time"
"isp-gate-service/request"
"github.com/txix-open/isp-kit/errors"
"github.com/txix-open/isp-kit/metrics/http_metrics" "github.com/txix-open/isp-kit/metrics/http_metrics"
) )
@@ -20,7 +22,7 @@ func Metrics(storage *http_metrics.ServerStorage) Middleware {
start := time.Now() start := time.Now()
err := next.Handle(ctx) err := next.Handle(ctx)
if err != nil { if err != nil {
return err return errors.WithMessage(err, "metrics middleware error")
} }
storage.ObserveDuration(r.Method, pathSchema, time.Since(start)) storage.ObserveDuration(r.Method, pathSchema, time.Since(start))
+3 -5
View File
@@ -1,8 +1,6 @@
package middleware package middleware
import ( import (
"slices"
"isp-gate-service/request" "isp-gate-service/request"
) )
@@ -18,10 +16,10 @@ func (f HandlerFunc) Handle(ctx *request.Context) error {
type Middleware func(next Handler) Handler type Middleware func(next Handler) Handler
// nolint:ireturn // nolint:ireturn, modernize
func Chain(root Handler, middlewares ...Middleware) Handler { func Chain(root Handler, middlewares ...Middleware) Handler {
for _, middleware := range slices.Backward(middlewares) { for i := len(middlewares) - 1; i >= 0; i-- {
root = middleware(root) root = middlewares[i](root)
} }
return root return root
} }
+5
View File
@@ -33,6 +33,7 @@ func init() {
} }
var ( var (
// nolint: gochecknoglobals
codeMap = map[int]codes.Code{ codeMap = map[int]codes.Code{
http.StatusOK: codes.OK, http.StatusOK: codes.OK,
http.StatusRequestTimeout: codes.Canceled, http.StatusRequestTimeout: codes.Canceled,
@@ -48,6 +49,7 @@ var (
http.StatusInternalServerError: codes.Internal, http.StatusInternalServerError: codes.Internal,
http.StatusServiceUnavailable: codes.Unavailable, http.StatusServiceUnavailable: codes.Unavailable,
} }
// nolint: gochecknoglobals
inverseCodeMap = map[codes.Code]int{} inverseCodeMap = map[codes.Code]int{}
) )
@@ -164,6 +166,9 @@ func (p Grpc) writeMetadata(ctx *request.Context) metadata.MD {
appAuthData, err := ctx.GetAuthData() appAuthData, err := ctx.GetAuthData()
if err == nil { if err == nil {
md[grpc.SystemIdHeader] = []string{strconv.Itoa(appAuthData.SystemId)}
md[grpc.DomainIdHeader] = []string{strconv.Itoa(appAuthData.DomainId)}
md[grpc.ServiceIdHeader] = []string{strconv.Itoa(appAuthData.ServiceId)}
md[grpc.ApplicationIdHeader] = []string{strconv.Itoa(appAuthData.ApplicationId)} md[grpc.ApplicationIdHeader] = []string{strconv.Itoa(appAuthData.ApplicationId)}
encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName)) encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName))
md[grpc.ApplicationNameHeader] = []string{encodedAppName} md[grpc.ApplicationNameHeader] = []string{encodedAppName}
+4
View File
@@ -21,6 +21,7 @@ import (
) )
var ( var (
// nolint: gochecknoglobals, mnd
httpTransport = &http.Transport{ httpTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
DialContext: defaultTransportDialContext(&net.Dialer{ DialContext: defaultTransportDialContext(&net.Dialer{
@@ -110,6 +111,9 @@ func setHttpHeaders(ctx *request.Context, header http.Header, skipAuth bool) {
appAuthData, err := ctx.GetAuthData() appAuthData, err := ctx.GetAuthData()
if err == nil { if err == nil {
header.Set(grpc.SystemIdHeader, strconv.Itoa(appAuthData.SystemId))
header.Set(grpc.DomainIdHeader, strconv.Itoa(appAuthData.DomainId))
header.Set(grpc.ServiceIdHeader, strconv.Itoa(appAuthData.ServiceId))
header.Set(grpc.ApplicationIdHeader, strconv.Itoa(appAuthData.ApplicationId)) header.Set(grpc.ApplicationIdHeader, strconv.Itoa(appAuthData.ApplicationId))
encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName)) encodedAppName := base64.StdEncoding.EncodeToString([]byte(appAuthData.AppName))
header.Set(grpc.ApplicationNameHeader, encodedAppName) //nolint:canonicalheader header.Set(grpc.ApplicationNameHeader, encodedAppName) //nolint:canonicalheader
+4 -2
View File
@@ -6,11 +6,12 @@ import (
"net/url" "net/url"
"time" "time"
"isp-gate-service/httperrors"
"isp-gate-service/request"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/tomakado/websocketproxy" "github.com/tomakado/websocketproxy"
"github.com/txix-open/isp-kit/errors" "github.com/txix-open/isp-kit/errors"
"isp-gate-service/httperrors"
"isp-gate-service/request"
) )
type Ws struct { type Ws struct {
@@ -45,6 +46,7 @@ func (ws Ws) Handle(ctx *request.Context) error {
proxy.Director = func(incoming *http.Request, out http.Header) { proxy.Director = func(incoming *http.Request, out http.Header) {
setHttpHeaders(ctx, out, ws.skipAuth) setHttpHeaders(ctx, out, ws.skipAuth)
} }
// nolint: mnd
proxy.Upgrader = &websocket.Upgrader{ proxy.Upgrader = &websocket.Upgrader{
HandshakeTimeout: 5 * time.Second, HandshakeTimeout: 5 * time.Second,
ReadBufferSize: 1024, ReadBufferSize: 1024,
+9 -16
View File
@@ -7,8 +7,7 @@ import (
"isp-gate-service/entity" "isp-gate-service/entity"
"github.com/txix-open/isp-kit/errors" "github.com/txix-open/isp-kit/errors"
"github.com/txix-open/isp-kit/http/httpclix" "github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/metrics/http_metrics"
) )
const ( const (
@@ -17,39 +16,33 @@ const (
) )
type Admin struct { type Admin struct {
cli *httpclix.ClientBalancer cli *client.Client
} }
func NewAdmin(cli *httpclix.ClientBalancer) Admin { func NewAdmin(cli *client.Client) Admin {
return Admin{cli: cli} return Admin{cli: cli}
} }
func (r Admin) Authenticate(ctx context.Context, token string) (*entity.AdminAuthenticateResponse, error) { func (r Admin) Authenticate(ctx context.Context, token string) (*entity.AdminAuthenticateResponse, error) {
ctx = http_metrics.ClientEndpointToContext(ctx, adminAuthenticate)
resp := entity.AdminAuthenticateResponse{} resp := entity.AdminAuthenticateResponse{}
err := r.cli.Post(adminAuthenticate). err := r.cli.Invoke(adminAuthenticate).
JsonRequestBody(entity.AuthenticateRequest{Token: token}). JsonRequestBody(entity.AuthenticateRequest{Token: token}).
JsonResponseBody(&resp). JsonResponseBody(&resp).
StatusCodeToError(). Do(ctx)
DoWithoutResponse(ctx)
if err != nil { if err != nil {
return nil, errors.WithMessagef(err, "http client invoke %s", adminAuthenticate) return nil, errors.WithMessagef(err, "grpc client invoke %s", adminAuthenticate)
} }
return &resp, nil return &resp, nil
} }
func (r Admin) Authorize(ctx context.Context, adminId int, permission string) (bool, error) { func (r Admin) Authorize(ctx context.Context, adminId int, permission string) (bool, error) {
ctx = http_metrics.ClientEndpointToContext(ctx, adminAuthorize)
resp := entity.AdminAuthorizeResponse{} resp := entity.AdminAuthorizeResponse{}
err := r.cli.Post(adminAuthorize). err := r.cli.Invoke(adminAuthorize).
JsonRequestBody(entity.AdminAuthorizeRequest{AdminId: adminId, Permission: permission}). JsonRequestBody(entity.AdminAuthorizeRequest{AdminId: adminId, Permission: permission}).
JsonResponseBody(&resp). JsonResponseBody(&resp).
StatusCodeToError(). Do(ctx)
DoWithoutResponse(ctx)
if err != nil { if err != nil {
return false, errors.WithMessagef(err, "http client invoke %s", adminAuthorize) return false, errors.WithMessagef(err, "grpc client invoke: %s", adminAuthorize)
} }
return resp.Authorized, nil return resp.Authorized, nil
} }
+3
View File
@@ -74,6 +74,9 @@ func (Authentication) convertAuthData(authData *entity.AppAuthData) *domain.AppA
return &domain.AppAuthData{ return &domain.AppAuthData{
AppName: authData.AppName, AppName: authData.AppName,
SystemId: authData.SystemId,
DomainId: authData.DomainId,
ServiceId: authData.ServiceId,
ApplicationId: authData.ApplicationId, ApplicationId: authData.ApplicationId,
} }
} }
+39 -28
View File
@@ -1,4 +1,3 @@
// nolint:canonicalheader
package tests_test package tests_test
import ( import (
@@ -24,7 +23,6 @@ import (
"github.com/txix-open/isp-kit/http/endpoint" "github.com/txix-open/isp-kit/http/endpoint"
"github.com/txix-open/isp-kit/http/endpoint/httplog" "github.com/txix-open/isp-kit/http/endpoint/httplog"
"github.com/txix-open/isp-kit/http/httpcli" "github.com/txix-open/isp-kit/http/httpcli"
"github.com/txix-open/isp-kit/http/httpclix"
"github.com/txix-open/isp-kit/http/router" "github.com/txix-open/isp-kit/http/router"
"github.com/txix-open/isp-kit/test/fake" "github.com/txix-open/isp-kit/test/fake"
@@ -60,9 +58,18 @@ func (s *HappyPathTestSuite) TestGrpcProxy() {
requestId := requestid.Next() requestId := requestid.Next()
targetService, targetCli := grpct.NewMock(test) targetService, targetCli := grpct.NewMock(test)
targetService.Mock("endpoint", func(ctx context.Context, authData grpc.AuthData, req request) response { targetService.Mock("endpoint", func(ctx context.Context, authData grpc.AuthData, req request) response {
systemId, err := authData.SystemId()
require.NoError(err)
domainId, err := authData.DomainId()
require.NoError(err)
serviceId, err := authData.ServiceId()
require.NoError(err)
applicationId, err := authData.ApplicationId() applicationId, err := authData.ApplicationId()
require.NoError(err) require.NoError(err)
require.EqualValues(requestId, requestid.FromContext(ctx)) require.EqualValues(requestId, requestid.FromContext(ctx))
require.EqualValues(1, systemId)
require.EqualValues(2, domainId)
require.EqualValues(3, serviceId)
require.EqualValues(4, applicationId) require.EqualValues(4, applicationId)
adminId, err := grpc.StringFromMd("x-admin-id", metadata.MD(authData)) adminId, err := grpc.StringFromMd("x-admin-id", metadata.MD(authData))
@@ -231,7 +238,7 @@ type wsEventHandlerMock struct {
func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.Event) []byte { func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.Event) []byte {
headers := conn.HttpRequest().Header headers := conn.HttpRequest().Header
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id")) ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id")) // nolint: canonicalheader
assertHeaders(s.require, s.requestId, ctx, headers) assertHeaders(s.require, s.requestId, ctx, headers)
require.EqualValues(s.t, "data", event.Data) require.EqualValues(s.t, "data", event.Data)
return []byte("world") return []byte("world")
@@ -572,7 +579,7 @@ func (s *HappyPathTestSuite) TestUserAuthorization_SkipAppAuth() { // nolint:fun
} }
// nolint:ireturn // nolint:ireturn
func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *client.Client, *httpclix.ClientBalancer) { func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *client.Client, *client.Client) {
config := conf.Remote{ config := conf.Remote{
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15}, Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true, Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true,
@@ -589,6 +596,9 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *
Authenticated: true, Authenticated: true,
ErrorReason: "", ErrorReason: "",
AuthData: &entity.AppAuthData{ AuthData: &entity.AppAuthData{
SystemId: 1,
DomainId: 2,
ServiceId: 3,
ApplicationId: 4, ApplicationId: 4,
AppName: "test", AppName: "test",
}, },
@@ -597,27 +607,19 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *
return entity.AuthorizeResponse{Authorized: true} return entity.AuthorizeResponse{Authorized: true}
}) })
adminMux := router.New() adminService, adminCli := grpct.NewMock(test)
defaultWrapper := endpoint.DefaultWrapper(test.Logger(), httplog.Noop()) adminService.Mock("admin/secure/authenticate", func(req entity.AdminAuthorizeRequest) entity.AdminAuthenticateResponse {
adminMux.POST("/admin/secure/authenticate", return entity.AdminAuthenticateResponse{
defaultWrapper.Endpoint(func(req entity.AuthenticateRequest) entity.AdminAuthenticateResponse { Authenticated: true,
return entity.AdminAuthenticateResponse{ ErrorReason: "",
Authenticated: true, AdminId: 1,
ErrorReason: "", }
AdminId: 1, }).Mock("admin/secure/authorize", func(req entity.AdminAuthorizeRequest) entity.AdminAuthorizeResponse {
} if req.Permission == "ok_permission" {
})) return entity.AdminAuthorizeResponse{Authorized: true}
adminMux.POST("/admin/secure/authorize", }
defaultWrapper.Endpoint(func(req entity.AdminAuthorizeRequest) entity.AdminAuthorizeResponse { return entity.AdminAuthorizeResponse{Authorized: false}
if req.Permission == "ok_permission" { })
return entity.AdminAuthorizeResponse{Authorized: true}
}
return entity.AdminAuthorizeResponse{Authorized: false}
}))
adminMock := httptest.NewServer(adminMux)
adminUrl, err := url.Parse(adminMock.URL)
require.New(s.T()).NoError(err)
adminCli := httpclix.NewClientBalancer([]string{adminUrl.Host})
return config, systemCli, adminCli return config, systemCli, adminCli
} }
@@ -628,14 +630,23 @@ func TestHappyPathTestSuite(t *testing.T) {
} }
func assertHeaders(require *require.Assertions, requestId string, ctx context.Context, headers http.Header) { func assertHeaders(require *require.Assertions, requestId string, ctx context.Context, headers http.Header) {
applicationId, err := strconv.Atoi(headers.Get("x-application-identity")) systemId, err := strconv.Atoi(headers.Get("x-system-identity")) // nolint: canonicalheader
require.NoError(err)
domainId, err := strconv.Atoi(headers.Get("x-domain-identity")) // nolint: canonicalheader
require.NoError(err)
serviceId, err := strconv.Atoi(headers.Get("x-service-identity")) // nolint: canonicalheader
require.NoError(err)
applicationId, err := strconv.Atoi(headers.Get("x-application-identity")) // nolint: canonicalheader
require.NoError(err) require.NoError(err)
require.EqualValues(requestId, requestid.FromContext(ctx)) require.EqualValues(requestId, requestid.FromContext(ctx))
require.EqualValues(1, systemId)
require.EqualValues(2, domainId)
require.EqualValues(3, serviceId)
require.EqualValues(4, applicationId) require.EqualValues(4, applicationId)
expectedAppName := base64.StdEncoding.EncodeToString([]byte("test")) expectedAppName := base64.StdEncoding.EncodeToString([]byte("test"))
require.EqualValues(expectedAppName, headers.Get("x-application-name")) require.EqualValues(expectedAppName, headers.Get("x-application-name")) // nolint: canonicalheader
adminId, err := strconv.Atoi(headers.Get("x-admin-id")) adminId, err := strconv.Atoi(headers.Get("x-admin-id")) // nolint: canonicalheader
require.NoError(err) require.NoError(err)
require.EqualValues(1, adminId) require.EqualValues(1, adminId)
} }
+21 -30
View File
@@ -4,11 +4,10 @@ import (
"context" "context"
"net" "net"
"net/http" "net/http"
"net/http/httptest"
"net/url"
"isp-gate-service/assembly" "isp-gate-service/assembly"
"isp-gate-service/conf" "isp-gate-service/conf"
"isp-gate-service/domain"
"isp-gate-service/entity" "isp-gate-service/entity"
"isp-gate-service/routes" "isp-gate-service/routes"
@@ -18,10 +17,6 @@ import (
"github.com/txix-open/isp-kit/grpc/client" "github.com/txix-open/isp-kit/grpc/client"
endpoint2 "github.com/txix-open/isp-kit/grpc/endpoint" endpoint2 "github.com/txix-open/isp-kit/grpc/endpoint"
"github.com/txix-open/isp-kit/grpc/isp" "github.com/txix-open/isp-kit/grpc/isp"
"github.com/txix-open/isp-kit/http/endpoint"
"github.com/txix-open/isp-kit/http/endpoint/httplog"
"github.com/txix-open/isp-kit/http/httpclix"
"github.com/txix-open/isp-kit/http/router"
"github.com/txix-open/isp-kit/log" "github.com/txix-open/isp-kit/log"
) )
@@ -60,12 +55,15 @@ func main() {
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 5000}}, Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 5000}},
} }
systemService, systemCli := NewMock(logger) systemService, systemCli, _ := NewMock(logger)
systemService.Mock("system/secure/authenticate", func() entity.AuthenticateResponse { systemService.Mock("system/secure/authenticate", func() entity.AuthenticateResponse {
return entity.AuthenticateResponse{ return entity.AuthenticateResponse{
Authenticated: true, Authenticated: true,
ErrorReason: "", ErrorReason: "",
AuthData: &entity.AppAuthData{ AuthData: &entity.AppAuthData{
SystemId: 1,
DomainId: 1,
ServiceId: 1,
ApplicationId: 1, ApplicationId: 1,
}, },
} }
@@ -73,9 +71,16 @@ func main() {
return entity.AuthorizeResponse{Authorized: true} return entity.AuthorizeResponse{Authorized: true}
}) })
adminCli := NewAdminMock(logger) adminService, _, adminCli := NewMock(logger)
adminService.Mock("admin/secure/authenticate", func() domain.AdminAuthenticateResponse {
return domain.AdminAuthenticateResponse{
Authenticated: true,
ErrorReason: "",
AdminId: 1,
}
})
targetService, targetCli := NewMock(logger) targetService, targetCli, _ := NewMock(logger)
targetService.Mock("endpoint", func(req request) response { targetService.Mock("endpoint", func(req request) response {
return response{Id: req.Id} return response{Id: req.Id}
}) })
@@ -97,33 +102,19 @@ func main() {
srv.ListenAndServe() srv.ListenAndServe()
} }
func NewAdminMock(logger log.Logger) *httpclix.ClientBalancer { func TestServer(service isp.BackendServiceServer) (*grpc.Server, *client.Client, *client.Client) {
mux := router.New()
wrapper := endpoint.DefaultWrapper(logger, httplog.Noop())
mux.POST("/admin/secure/authenticate",
wrapper.Endpoint(func() entity.AdminAuthenticateResponse {
return entity.AdminAuthenticateResponse{
Authenticated: true,
ErrorReason: "",
AdminId: 1,
}
}))
mock := httptest.NewServer(mux)
u, _ := url.Parse(mock.URL)
return httpclix.NewClientBalancer([]string{u.Host})
}
func TestServer(service isp.BackendServiceServer) (*grpc.Server, *client.Client) {
listener, _ := net.Listen("tcp", "127.0.0.1:") // nolint:noctx listener, _ := net.Listen("tcp", "127.0.0.1:") // nolint:noctx
srv := grpc.NewServer() srv := grpc.NewServer()
sysCli, _ := client.Default() sysCli, _ := client.Default()
adminCli, _ := client.Default()
srv.Upgrade(service) srv.Upgrade(service)
go func() { go func() {
_ = srv.Serve(listener) _ = srv.Serve(listener)
}() }()
sysCli.Upgrade([]string{listener.Addr().String()}) sysCli.Upgrade([]string{listener.Addr().String()})
return srv, sysCli adminCli.Upgrade([]string{listener.Addr().String()})
return srv, sysCli, adminCli
} }
type MockServer struct { type MockServer struct {
@@ -132,13 +123,13 @@ type MockServer struct {
mockEndpoints map[string]any mockEndpoints map[string]any
} }
func NewMock(logger log.Logger) (*MockServer, *client.Client) { func NewMock(logger log.Logger) (*MockServer, *client.Client, *client.Client) {
srv, syscli := TestServer(grpc.NewMux()) srv, syscli, admincli := TestServer(grpc.NewMux())
return &MockServer{ return &MockServer{
srv: srv, srv: srv,
logger: logger, logger: logger,
mockEndpoints: make(map[string]any), mockEndpoints: make(map[string]any),
}, syscli }, syscli, admincli
} }
func (m *MockServer) Mock(endpoint string, handler any) *MockServer { func (m *MockServer) Mock(endpoint string, handler any) *MockServer {