Compare commits

..
2 Commits
Author SHA1 Message Date
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
7 changed files with 59 additions and 9 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
5.5.0
5.6.0
+4
View File
@@ -1,3 +1,7 @@
### v5.6.0
* Добавлена поддержка метрик для http запросов
### v5.5.1
* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения
### v5.5.0
* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения
### v5.4.1
+6
View File
@@ -1,6 +1,8 @@
package assembly
import (
"github.com/txix-open/isp-kit/metrics"
"github.com/txix-open/isp-kit/metrics/http_metrics"
"net/http"
"time"
@@ -94,6 +96,8 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
forwardReqIdByAppId[setting.ApplicationId] = setting.ForwardRequestId
}
metricsStorage := http_metrics.NewServerStorage(metrics.DefaultRegistry)
handler := middleware.Chain(
proxyFunc,
middleware.Logger(
@@ -110,6 +114,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
middleware.Throttling(throttlingService),
middleware.DailyLimit(dailyLimitService),
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
middleware.Metrics(metricsStorage),
)
if location.SkipAuth {
handler = middleware.Chain(
@@ -121,6 +126,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
),
middleware.ErrorHandler(l.logger),
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
middleware.Metrics(metricsStorage),
)
}
entrypoint := middleware.Entrypoint(
+1 -1
View File
@@ -10,7 +10,7 @@ require (
github.com/redis/go-redis/v9 v9.11.0
github.com/stretchr/testify v1.11.1
github.com/tomakado/websocketproxy v0.1.0
github.com/txix-open/isp-kit v1.62.0
github.com/txix-open/isp-kit v1.63.3
github.com/txix-open/jsonschema v1.3.0
golang.org/x/net v0.44.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090
+2 -2
View File
@@ -125,8 +125,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM=
github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
github.com/txix-open/isp-kit v1.62.0 h1:SfY8x5/3yYEicr5phGTJBaUwFvgktSIsD/NubrKYbg4=
github.com/txix-open/isp-kit v1.62.0/go.mod h1:hyCFmWF0qoVY2loTLyHJx8QPZJuULntG0JfthqFCdsA=
github.com/txix-open/isp-kit v1.63.3 h1:UJLgR4z8sYXUX6r1sl6Ww1aijPx6b7ieMeB+elZoViM=
github.com/txix-open/isp-kit v1.63.3/go.mod h1:rwqKqB3PyZxaoep6iH1PKL89LS9nzRklA6+S4II72M4=
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
+14 -5
View File
@@ -4,10 +4,11 @@ import (
"context"
"net/http"
"github.com/pkg/errors"
"isp-gate-service/domain"
"isp-gate-service/httperrors"
"isp-gate-service/request"
"github.com/pkg/errors"
)
const (
@@ -61,17 +62,25 @@ func Authenticate(authenticator Authenticator) Middleware {
}
func extractToken(ctx *request.Context) (string, string, error) {
appName, token, ok := ctx.Request().BasicAuth()
if !ok {
return ctx.Param(applicationTokenHeader), "", nil
var (
appName string
token string
ok bool
)
token = ctx.Param(applicationTokenHeader)
if token != "" {
return token, "", nil
}
if appName == "" {
appName, token, ok = ctx.Request().BasicAuth()
if ok && appName == "" {
return "", "", httperrors.New(
http.StatusUnauthorized,
"application name required",
errors.New("authenticate: application name required on basic auth"),
)
}
return token, appName, nil
}
+31
View File
@@ -0,0 +1,31 @@
package middleware
import (
"isp-gate-service/request"
"time"
"github.com/txix-open/isp-kit/metrics/http_metrics"
)
func Metrics(storage *http_metrics.ServerStorage) Middleware {
return func(next Handler) Handler {
return HandlerFunc(func(ctx *request.Context) error {
endpoint := ctx.Endpoint()
if endpoint == "" {
return next.Handle(ctx)
}
r := ctx.Request()
start := time.Now()
err := next.Handle(ctx)
if err != nil {
return err
}
storage.ObserveDuration(r.Method, endpoint, time.Since(start))
return nil
})
}
}