2025-11-26 10:05:59: merge [main:96f8e79d3384c01bf52552f94afdf4ed662997e5];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s

This commit is contained in:
txix committed 2025-11-26 10:05:59 +03:00
1 parent ee13991d87
commit f3c801e4a4
7 files changed
+42 -8

No files matched your search

+1 -1
View File
@@ -1 +1 @@
5.4.1
5.5.0
+2
View File
@@ -1,3 +1,5 @@
### v5.5.0
* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения
### v5.4.1
* Оптимизация очистки тела запроса от экранирования unicode символов для корректного логирования
### v5.4.0
+1
View File
@@ -1,6 +1,7 @@
package domain
type AuthData struct {
AppName string
SystemId int
DomainId int
ServiceId int
+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.57.1
github.com/txix-open/isp-kit v1.62.0
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
+4 -2
View File
@@ -31,6 +31,8 @@ github.com/getsentry/sentry-go v0.35.2 h1:jKuujpRwa8FFRYMIwwZpu83Xh0voll9bmvyc63
github.com/getsentry/sentry-go v0.35.2/go.mod h1:mdL49ixwT2yi57k5eh7mpnDyPybixPzlzEJFu0Z76QA=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-faker/faker/v4 v4.6.1 h1:xUyVpAjEtB04l6XFY0V/29oR332rOSPWV4lU8RwDt4k=
github.com/go-faker/faker/v4 v4.6.1/go.mod h1:arSdxNCSt7mOhdk8tEolvHeIJ7eX4OX80wXjKKvkKBY=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -123,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.57.1 h1:EltTEs9VZT8eqUrrRt5EqWAPdXFvw1XL2/EDN8xfdUU=
github.com/txix-open/isp-kit v1.57.1/go.mod h1:Mbprn7ExedjRg4yUPa9xShYx1oMJIU+a19x6ksVubaw=
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/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=
+32 -4
View File
@@ -21,7 +21,10 @@ type Authenticator interface {
func Authenticate(authenticator Authenticator) Middleware {
return func(next Handler) Handler {
return HandlerFunc(func(ctx *request.Context) error {
token := ctx.Param(applicationTokenHeader)
token, appName, err := extractToken(ctx)
if err != nil {
return err
}
if token == "" {
return httperrors.New(
http.StatusUnauthorized,
@@ -32,18 +35,43 @@ func Authenticate(authenticator Authenticator) Middleware {
resp, err := authenticator.Authenticate(ctx.Context(), token)
if err != nil {
return errors.WithMessagef(err, "authenticate: authenticate")
return errors.WithMessage(err, "authenticate: authenticator error")
}
if !resp.Authenticated {
return httperrors.New(
http.StatusUnauthorized,
"invalid application token",
errors.WithMessage(errors.New(resp.ErrorReason), "authenticate: authenticate"),
errors.Errorf("authenticate: %s", resp.ErrorReason),
)
}
ctx.Authenticate(request.AuthData(*resp.AuthData))
if appName != "" && resp.AuthData.AppName != appName {
return httperrors.New(
http.StatusUnauthorized,
"invalid application token",
errors.New("authenticate: application name mismatch"),
)
}
ctx.Authenticate(request.AuthData(*resp.AuthData))
return next.Handle(ctx)
})
}
}
func extractToken(ctx *request.Context) (string, string, error) {
appName, token, ok := ctx.Request().BasicAuth()
if !ok {
return ctx.Param(applicationTokenHeader), "", nil
}
if appName == "" {
return "", "", httperrors.New(
http.StatusUnauthorized,
"application name required",
errors.New("authenticate: application name required on basic auth"),
)
}
return token, appName, nil
}
+1
View File
@@ -13,6 +13,7 @@ var (
)
type AuthData struct {
AppName string
SystemId int
DomainId int
ServiceId int