Compare commits
462
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
503b6b5de6 | ||
|
|
6d4f4fe554 | ||
|
|
4e924575ce | ||
|
|
7abecf78ad | ||
|
|
657d430288 | ||
|
|
d2167d2f07 | ||
|
|
2fb58a7195 | ||
|
|
72f2d37920 | ||
|
|
1a1f764f75 | ||
|
|
fbf10c8722 | ||
|
|
227a2a069d | ||
|
|
cf4979560b | ||
|
|
7d936adaf0 | ||
|
|
a8af70f93c | ||
|
|
d6b8ed5f2d | ||
|
|
81e9195d79 | ||
|
|
c5626b5aca | ||
|
|
e0e3609185 | ||
|
|
6ec6987597 | ||
|
|
ac8a556442 | ||
|
|
5cb927d4dc | ||
|
|
587e369e08 | ||
|
|
87bfa22b52 | ||
|
|
cca6ce0ad1 | ||
|
|
f98ecd049e | ||
|
|
ff560441b2 | ||
|
|
81ece162cc | ||
|
|
48e5315986 | ||
|
|
da38b66d9a | ||
|
|
206e64f9e1 | ||
|
|
1b0651e42f | ||
|
|
215ccbd25b | ||
|
|
1b2b9c5817 | ||
|
|
23a4d94cff | ||
|
|
6186f7bdb5 | ||
|
|
2e0889491d | ||
|
|
3484276256 | ||
|
|
f13c1ced4f | ||
|
|
9d9353cf57 | ||
|
|
a185cb0878 | ||
|
|
41762113e7 | ||
|
|
7cca2eb773 | ||
|
|
eb6326c343 | ||
|
|
b67eb8137c | ||
|
|
8b672bdd30 | ||
|
|
1363935f66 | ||
|
|
77f3311401 | ||
|
|
c523d2347d | ||
|
|
7ff454d6d9 | ||
|
|
7b5ff23615 | ||
|
|
1bd032e5aa | ||
|
|
f160467e77 | ||
|
|
59875487ae | ||
|
|
b692728cc3 | ||
|
|
f5a5e7d8bb | ||
|
|
aae3c28225 | ||
|
|
d417e202e0 | ||
|
|
211b47d21e | ||
|
|
e623018b72 | ||
|
|
56548cbf4d | ||
|
|
e4869135b4 | ||
|
|
40e521462d | ||
|
|
c422de39b4 | ||
|
|
c0bb6fdc7e | ||
|
|
01b6263f29 | ||
|
|
30d731ebfa | ||
|
|
8a0dce574a | ||
|
|
e5e723811e | ||
|
|
56518b86f0 | ||
|
|
6acaf9c7ee | ||
|
|
2ddb3a3d1f | ||
|
|
29cdf42808 | ||
|
|
b2ffc15cfa | ||
|
|
7cb16f87e5 | ||
|
|
63c694e2a3 | ||
|
|
b7028f3c9e | ||
|
|
de80daad81 | ||
|
|
54a3ac5ed4 | ||
|
|
9e6846ac03 | ||
|
|
4f90477e73 | ||
|
|
8b92a460de | ||
|
|
68105a2179 | ||
|
|
1a274e79e5 | ||
|
|
690820b7c4 | ||
|
|
d4f5d7d66f | ||
|
|
e6c241f112 | ||
|
|
2b5ee66527 | ||
|
|
4ddc963481 | ||
|
|
16cdb18f43 | ||
|
|
e9c5c9b805 | ||
|
|
d447bb52bc | ||
|
|
102fa48a92 | ||
|
|
96f8e79d33 | ||
|
|
9b9b66c07c | ||
|
|
abfd06b407 | ||
|
|
325ededd86 | ||
|
|
069881f85f | ||
|
|
fa803e9cac | ||
|
|
a39036a051 | ||
|
|
c3e3ed9636 | ||
|
|
2d8e24ef2b | ||
|
|
566b601c85 | ||
|
|
181edb8823 | ||
|
|
d4a097a7a7 | ||
|
|
5f556dcde3 | ||
|
|
13db082fca | ||
|
|
bebd43dde2 | ||
|
|
b17e4b78aa | ||
|
|
dc61927345 | ||
|
|
5230e9ac42 | ||
|
|
f5bfe7d2ba | ||
|
|
0dfbe57af1 | ||
|
|
a4b6e5fd1d | ||
|
|
14f3c541e4 | ||
|
|
aa704effde | ||
|
|
9f485b5e57 | ||
|
|
52d8504089 | ||
|
|
26691b99de | ||
|
|
f45f62c4b1 | ||
|
|
66e6c4b9c4 | ||
|
|
61f11c0bda | ||
|
|
343f9d0cfa | ||
|
|
cd721daa81 | ||
|
|
e7bfd34e9e | ||
|
|
6491e79afd | ||
|
|
5fed5d7683 | ||
|
|
0c2bcc6cfe | ||
|
|
e56a2b829f | ||
|
|
944c7b7415 | ||
|
|
dbf094afd8 | ||
|
|
b7912dcd9f | ||
|
|
01f8dcdc36 | ||
|
|
dce66f423d | ||
|
|
4f8d2e9ae9 | ||
|
|
1c8ba2d700 | ||
|
|
16a0c66ab7 | ||
|
|
49d1bfaa3f | ||
|
|
c6685ddfb9 | ||
|
|
6a24a7bdd8 | ||
|
|
738146be5c | ||
|
|
357ce03935 | ||
|
|
ce4d8ec165 | ||
|
|
0793b8f90f | ||
|
|
d954b8d828 | ||
|
|
600b3d7808 | ||
|
|
9808e30cb9 | ||
|
|
7acd770e26 | ||
|
|
87af899a0d | ||
|
|
82ac257e91 | ||
|
|
3d22feec9c | ||
|
|
7b5fc0b416 | ||
|
|
576ef18526 | ||
|
|
03df79d7b3 | ||
|
|
136024c387 | ||
|
|
7cd5b507c4 | ||
|
|
02cc03e744 | ||
|
|
1999ea366b | ||
|
|
57e788e7dc | ||
|
|
93482f05d3 | ||
|
|
4898a95fc4 | ||
|
|
95f9e46f45 | ||
|
|
9ec52bd852 | ||
|
|
bf6ba426f6 | ||
|
|
744eaa2605 | ||
|
|
b21f96b8a5 | ||
|
|
45e6d9128b | ||
|
|
7f99b95cea | ||
|
|
ac8cbcef8a | ||
|
|
914e9e1226 | ||
|
|
d09e784ca8 | ||
|
|
875d3985bd | ||
|
|
f9b2632335 | ||
|
|
01159874b8 | ||
|
|
843c6d36c2 | ||
|
|
4480d932e1 | ||
|
|
54292a9597 | ||
|
|
27c825f705 | ||
|
|
0d0cf8f2a0 | ||
|
|
200f65a8ba | ||
|
|
d3624ee87e | ||
|
|
56d3e06e49 | ||
|
|
f6dbff900b | ||
|
|
6683d2dcd0 | ||
|
|
1f40e9d5d3 | ||
|
|
87690bbd12 | ||
|
|
e4892b737f | ||
|
|
f94672569b | ||
|
|
c390fe3948 | ||
|
|
8a83ba0b3a | ||
|
|
402c6c18cf | ||
|
|
0c62aa8b1b | ||
|
|
6ba1761634 | ||
|
|
ca5dc08fbd | ||
|
|
219d4ce382 | ||
|
|
3f88c01417 | ||
|
|
ac7f26f705 | ||
|
|
960ad5a253 | ||
|
|
365bddceda | ||
|
|
7069f43366 | ||
|
|
b938e2f81d | ||
|
|
011cdd022c | ||
|
|
5d2e6753a0 | ||
|
|
82a6d1959a | ||
|
|
c7295c6219 | ||
|
|
1f808ea387 | ||
|
|
9639b312b2 | ||
|
|
7039bf2cf7 | ||
|
|
2f74836b5c | ||
|
|
ed9ba371f7 | ||
|
|
0d430df928 | ||
|
|
037b3bebda | ||
|
|
1fa746c3e9 | ||
|
|
dfbc05cd7d | ||
|
|
0d60ec0798 | ||
|
|
2332737031 | ||
|
|
ae1bba7575 | ||
|
|
716428dd58 | ||
|
|
9e68e9662c | ||
|
|
3483b1f52b | ||
|
|
1d34dc6f2e | ||
|
|
5139158d7a | ||
|
|
3182cefbe2 | ||
|
|
bce6527dc7 | ||
|
|
d430e1e402 | ||
|
|
08c39a9b58 | ||
|
|
f78db86e39 | ||
|
|
02334b3617 | ||
|
|
cbbc03acb9 | ||
|
|
d298485722 | ||
|
|
390bd0423e | ||
|
|
35e9311cc7 | ||
|
|
0e51c54415 | ||
|
|
c650929476 | ||
|
|
2ab43de749 | ||
|
|
01027e6f29 | ||
|
|
2b329d5270 | ||
|
|
0910add54c | ||
|
|
b054257e06 | ||
|
|
614abce93f | ||
|
|
fa9a5b7633 | ||
|
|
9163d0749d | ||
|
|
57dff99bb5 | ||
|
|
8a269cd0e0 | ||
|
|
bb92f0628a | ||
|
|
8adec87573 | ||
|
|
1a1a200173 | ||
|
|
d4f8201bd5 | ||
|
|
2f714b32c8 | ||
|
|
9d400c4158 | ||
|
|
6283cc64a5 | ||
|
|
586752ac8c | ||
|
|
191e48d464 | ||
|
|
5a9fc1a59b | ||
|
|
4175a36bf8 | ||
|
|
203dbcb1bf | ||
|
|
f13e45762b | ||
|
|
aeb297065d | ||
|
|
1cb43ec54d | ||
|
|
4505292943 | ||
|
|
5bf5373056 | ||
|
|
8d2df6364b | ||
|
|
e2b2d05777 | ||
|
|
3c0e0386e1 | ||
|
|
773fbe7883 | ||
|
|
e663429dfe | ||
|
|
61f4d16ef8 | ||
|
|
ff7e47a64e | ||
|
|
d71dc62634 | ||
|
|
0367fa8ac7 | ||
|
|
14995e91dd | ||
|
|
e64a58e85a | ||
|
|
51d9cc0397 | ||
|
|
f9f127f6b9 | ||
|
|
a73b9c119e | ||
|
|
901f350adb | ||
|
|
0b08f532e1 | ||
|
|
2c29a2f0a3 | ||
|
|
71100e8c7b | ||
|
|
fd40a83e83 | ||
|
|
e7a165875d | ||
|
|
cd5e286fb0 | ||
|
|
9408f5d83f | ||
|
|
cd6b4729aa | ||
|
|
5d4729e0c7 | ||
|
|
4b0ff6f627 | ||
|
|
b415ce8acf | ||
|
|
9e205573ea | ||
|
|
6a8c628570 | ||
|
|
83668d944a | ||
|
|
a6c7ff3af3 | ||
|
|
5bda86fe46 | ||
|
|
46f447447b | ||
|
|
2ca358a4ea | ||
|
|
bd4b52e5cc | ||
|
|
ed77144fdf | ||
|
|
963d8a1dfe | ||
|
|
12908ef2dc | ||
|
|
a7e312b066 | ||
|
|
3a526a25cc | ||
|
|
363785db94 | ||
|
|
3999f9c514 | ||
|
|
f2928ddcf7 | ||
|
|
ba2aeaf556 | ||
|
|
1a63a616ee | ||
|
|
668cbb37d2 | ||
|
|
538e9a7aab | ||
|
|
c1dd4b1846 | ||
|
|
266f3cbc20 | ||
|
|
6940b30756 | ||
|
|
3f9d25c217 | ||
|
|
828ac1cd4f | ||
|
|
db3b6aa32f | ||
|
|
39a7899a98 | ||
|
|
39dbeda9d8 | ||
|
|
9307c80b2b | ||
|
|
d9605304d2 | ||
|
|
29ed65b193 | ||
|
|
ad57079fc6 | ||
|
|
6f511ddc53 | ||
|
|
b0f871d032 | ||
|
|
6a150402d2 | ||
|
|
626eda7990 | ||
|
|
d207e56e68 | ||
|
|
be6cce7bd1 | ||
|
|
f71e29f145 | ||
|
|
5157143904 | ||
|
|
0102206734 | ||
|
|
67d0512c6b | ||
|
|
0f002b5633 | ||
|
|
1fdc36d797 | ||
|
|
3fe2126eaa | ||
|
|
f82c264f95 | ||
|
|
104524855c | ||
|
|
468653eba8 | ||
|
|
d6e1356b2a | ||
|
|
97912e5d5a | ||
|
|
eeddba7858 | ||
|
|
63f14564b8 | ||
|
|
ed7a49ef04 | ||
|
|
7b5c6165f2 | ||
|
|
04a07377c1 | ||
|
|
24b22aa7f1 | ||
|
|
05bdf75e95 | ||
|
|
71e78d01e7 | ||
|
|
ed83722c76 | ||
|
|
43679853e7 | ||
|
|
13477fa8ca | ||
|
|
b25956d028 | ||
|
|
f2e9438605 | ||
|
|
0afe95786f | ||
|
|
814d8dc15a | ||
|
|
7db2eb84b5 | ||
|
|
77112d82f8 | ||
|
|
3125d7cd10 | ||
|
|
3608c729f7 | ||
|
|
248801bbf7 | ||
|
|
607ecf629c | ||
|
|
aa3bed6ff8 | ||
|
|
447d719a16 | ||
|
|
e6bdec3f1e | ||
|
|
2d45f210db | ||
|
|
2aff6210b5 | ||
|
|
8d8369b4cc | ||
|
|
b1c16e4901 | ||
|
|
48cbb5c25d | ||
|
|
037c5f3fcd | ||
|
|
8c732a15e2 | ||
|
|
896dd36025 | ||
|
|
f0b8407479 | ||
|
|
c31c6aaf81 | ||
|
|
478b1ce5d7 | ||
|
|
453aa44148 | ||
|
|
9cd697a40d | ||
|
|
97d971fe14 | ||
|
|
68259fa369 | ||
|
|
1794041802 | ||
|
|
72e6bbe6d7 | ||
|
|
665641c88b | ||
|
|
b8d0c8e6d0 | ||
|
|
9a9e941580 | ||
|
|
675a917c0c | ||
|
|
7e10fb5217 | ||
|
|
6d67d3a331 | ||
|
|
e2d45ecdd2 | ||
|
|
61ca62db75 | ||
|
|
e0ab3236d4 | ||
|
|
910fb81a0e | ||
|
|
f1c597bde9 | ||
|
|
f25ded3015 | ||
|
|
3f8e03eda4 | ||
|
|
50a7e32b48 | ||
|
|
df31719324 | ||
|
|
cc5da31e59 | ||
|
|
2d936e543c | ||
|
|
91a14f9f23 | ||
|
|
08c4fb9bee | ||
|
|
dbaa347162 | ||
|
|
78f1fe43b9 | ||
|
|
ab95347767 | ||
|
|
7dd989bac2 | ||
|
|
b9dc101141 | ||
|
|
b3452ef5f6 | ||
|
|
41357efef0 | ||
|
|
b0cac278d2 | ||
|
|
75abb294c0 | ||
|
|
3d02fa550d | ||
|
|
8a9accbdeb | ||
|
|
88bff98d25 | ||
|
|
bdb0c50a22 | ||
|
|
0cf2b61ce3 | ||
|
|
6ec99e8d1f | ||
|
|
a6c1fcb972 | ||
|
|
ed91071557 | ||
|
|
6e1770273e | ||
|
|
5a462ef158 | ||
|
|
a3415470f7 | ||
|
|
909a26eace | ||
|
|
1ffe9e4a62 | ||
|
|
909ff91b2b | ||
|
|
4c7e96813c | ||
|
|
244d8fbdc2 | ||
|
|
745a4ae1e2 | ||
|
|
38806190e7 | ||
|
|
3e593f759d | ||
|
|
0672da8e9c | ||
|
|
bc53089fce | ||
|
|
7a22e3558e | ||
|
|
3c801a4c09 | ||
|
|
b4541f6c1b | ||
|
|
7acc4ebbd6 | ||
|
|
1665cc78cf | ||
|
|
8dcb8eef68 | ||
|
|
37c08f4500 | ||
|
|
8af97e56d7 | ||
|
|
f9138cbbfe | ||
|
|
4d81fe7a26 | ||
|
|
3d2cee1ae8 | ||
|
|
9eb5a3030b | ||
|
|
bad913e339 | ||
|
|
0e3c14d099 | ||
|
|
23ede62f24 | ||
|
|
fc80638b76 | ||
|
|
8f57203d96 | ||
|
|
422bdb9831 | ||
|
|
8c68ffea8c | ||
|
|
f802b2000d | ||
|
|
1a46b678ef | ||
|
|
3d97f3789a | ||
|
|
2a81e83b2e | ||
|
|
1a8ed4e8ea | ||
|
|
e3c3b86b04 | ||
|
|
a9e03750ab | ||
|
|
0edf80ffed | ||
|
|
5b115440f1 | ||
|
|
4fdf7c0ca2 | ||
|
|
f3934e038e | ||
|
|
3461f20510 | ||
|
|
b6baa9e5e7 | ||
|
|
3a4931ca8c | ||
|
|
70f5ebeb4b | ||
|
|
b29f3c6dcd | ||
|
|
fe6f1f5e5a |
No files matched your search
@@ -15,7 +15,6 @@ linters:
|
|||||||
- nolintlint # Goland все равно форматирует с отступом
|
- nolintlint # Goland все равно форматирует с отступом
|
||||||
- perfsprint # мнимая производительность в угоду читаемости
|
- perfsprint # мнимая производительность в угоду читаемости
|
||||||
- tagalign # не всегда имеет смысл
|
- tagalign # не всегда имеет смысл
|
||||||
- testpackage
|
|
||||||
- varnamelen # очень индивидуально (db)
|
- varnamelen # очень индивидуально (db)
|
||||||
- wsl # расставление пробелов очень индивидуально
|
- wsl # расставление пробелов очень индивидуально
|
||||||
- wsl_v5 # расставление пробелов очень индивидуально
|
- wsl_v5 # расставление пробелов очень индивидуально
|
||||||
@@ -66,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,9 +1,3 @@
|
|||||||
### v5.12.0
|
|
||||||
* взаимодействие с `isp-admin-service` переведено с gRPC на HTTP
|
|
||||||
### v5.11.6
|
|
||||||
* Логирование запросов на незнакомые locations — `warn` `request to unknown location` при включённом `logging.requestLogEnable`
|
|
||||||
* Добавлена настройка `logging.skipLoggingPathPrefixes` — полное отключение логирования запросов для путей с префиксом из списка (лог запросов, `warn` об неизвестном эндпоинте, лог незнакомых locations)
|
|
||||||
* Исправлено `logging.skipBodyLoggingEndpointPrefixes`: значения с ведущим `/` теперь работают и для локаций без `SkipAuth`
|
|
||||||
### v5.11.5
|
### v5.11.5
|
||||||
* Обновлена версия go до версии 1.27
|
* Обновлена версия go до версии 1.27
|
||||||
* Обновлены правила для linter
|
* Обновлены правила для linter
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
+3
-11
@@ -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,
|
||||||
@@ -97,8 +96,6 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
skipBodyLoggingEndpointPrefixes = append(skipBodyLoggingEndpointPrefixes, strings.TrimPrefix(prefix, "/"))
|
skipBodyLoggingEndpointPrefixes = append(skipBodyLoggingEndpointPrefixes, strings.TrimPrefix(prefix, "/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
skipLogging := middleware.NewSkipLoggingPaths(config.Logging.SkipLoggingPathPrefixes)
|
|
||||||
|
|
||||||
mux := mux2.NewRouter()
|
mux := mux2.NewRouter()
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
var proxyFunc middleware.Handler
|
var proxyFunc middleware.Handler
|
||||||
@@ -139,8 +136,7 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
middleware.Logger(
|
middleware.Logger(
|
||||||
l.logger, config.Logging.RequestLogEnable,
|
l.logger, config.Logging.RequestLogEnable,
|
||||||
enableBodyLog,
|
enableBodyLog,
|
||||||
skipLogging,
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
skipBodyLoggingEndpointPrefixes,
|
|
||||||
config.Logging.EnableForceUnescapingUnicode,
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
),
|
),
|
||||||
middleware.RequestId(),
|
middleware.RequestId(),
|
||||||
@@ -164,7 +160,6 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
proxyFunc,
|
proxyFunc,
|
||||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable,
|
middleware.Logger(l.logger, config.Logging.RequestLogEnable,
|
||||||
enableBodyLog,
|
enableBodyLog,
|
||||||
skipLogging,
|
|
||||||
skipBodyLoggingEndpointPrefixes,
|
skipBodyLoggingEndpointPrefixes,
|
||||||
config.Logging.EnableForceUnescapingUnicode,
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
),
|
),
|
||||||
@@ -182,7 +177,6 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
PathPrefix: location.PathPrefix,
|
PathPrefix: location.PathPrefix,
|
||||||
ErrorOnUnknownEndpoint: errorOnUnknownEndpoint,
|
ErrorOnUnknownEndpoint: errorOnUnknownEndpoint,
|
||||||
WithLendingSlash: location.Protocol != conf.GrpcProtocol,
|
WithLendingSlash: location.Protocol != conf.GrpcProtocol,
|
||||||
SkipLogging: skipLogging,
|
|
||||||
},
|
},
|
||||||
l.routes,
|
l.routes,
|
||||||
l.logger,
|
l.logger,
|
||||||
@@ -190,7 +184,5 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha
|
|||||||
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
|
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.NotFoundHandler = middleware.UnknownLocation(l.logger, config.Logging.RequestLogEnable, skipLogging)
|
|
||||||
|
|
||||||
return mux, nil
|
return mux, nil
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,7 @@
|
|||||||
"requestLogEnable": true,
|
"requestLogEnable": true,
|
||||||
"bodyLogEnable": false,
|
"bodyLogEnable": false,
|
||||||
"skipBodyLoggingEndpointPrefixes": [],
|
"skipBodyLoggingEndpointPrefixes": [],
|
||||||
"enableForceUnescapingUnicode": false,
|
"enableForceUnescapingUnicode": false
|
||||||
"skipLoggingPathPrefixes": []
|
|
||||||
},
|
},
|
||||||
"caching": {
|
"caching": {
|
||||||
"authenticationDataInSec": 60,
|
"authenticationDataInSec": 60,
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ type Logging struct {
|
|||||||
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
||||||
SkipBodyLoggingEndpointPrefixes []string `schema:"Выключить логирование тел запросов и ответов для путей имеющих префикс из списка,'/' в начале игнорируется"`
|
SkipBodyLoggingEndpointPrefixes []string `schema:"Выключить логирование тел запросов и ответов для путей имеющих префикс из списка,'/' в начале игнорируется"`
|
||||||
EnableForceUnescapingUnicode bool `schema:"Включить перевод тел запроса из unicode в utf-8, должно быть включено логирование тел запросов и ответов"`
|
EnableForceUnescapingUnicode bool `schema:"Включить перевод тел запроса из unicode в utf-8, должно быть включено логирование тел запросов и ответов"`
|
||||||
SkipLoggingPathPrefixes []string `schema:"Полностью не логировать запросы к путям с префиксом из списка (сырой path, query не учитывается, '/' в начале игнорируется). Применяется к логу запросов, предупреждению о неизвестном эндпоинте и логу незнакомых locations"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Caching struct {
|
type Caching struct {
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
@@ -1,20 +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
|
||||||
go.uber.org/zap v1.28.0
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20261123191846-1e707ab9fbc2
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f
|
|
||||||
google.golang.org/grpc v1.85.0
|
google.golang.org/grpc v1.85.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,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
|
||||||
@@ -35,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
|
||||||
@@ -54,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
|
||||||
@@ -66,12 +64,13 @@ require (
|
|||||||
go.opentelemetry.io/proto/otlp v1.11.1 // indirect
|
go.opentelemetry.io/proto/otlp v1.11.1 // indirect
|
||||||
go.uber.org/atomic v1.12.0 // indirect
|
go.uber.org/atomic v1.12.0 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
|
go.uber.org/zap v1.28.0 // indirect
|
||||||
go.yaml.in/yaml/v3 v3.0.6 // indirect
|
go.yaml.in/yaml/v3 v3.0.6 // indirect
|
||||||
golang.org/x/crypto v0.59.0 // indirect
|
golang.org/x/crypto v0.59.0 // indirect
|
||||||
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
|
||||||
|
|||||||
@@ -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=
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ type EntryPointConfig struct {
|
|||||||
WithPrefix bool
|
WithPrefix bool
|
||||||
ErrorOnUnknownEndpoint bool
|
ErrorOnUnknownEndpoint bool
|
||||||
WithLendingSlash bool
|
WithLendingSlash bool
|
||||||
SkipLogging SkipLoggingPaths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EndpointResolver interface {
|
type EndpointResolver interface {
|
||||||
@@ -34,7 +33,6 @@ func Entrypoint(
|
|||||||
|
|
||||||
endpoint, err := entryPointResolver.ResolveEndpoint(req.Method, req.URL.Path, cfg)
|
endpoint, err := entryPointResolver.ResolveEndpoint(req.Method, req.URL.Path, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !cfg.SkipLogging.ShouldSkip(req.URL.Path) {
|
|
||||||
lookupPath, endpoint := entryPointResolver.GetPaths(req.URL.Path, cfg)
|
lookupPath, endpoint := entryPointResolver.GetPaths(req.URL.Path, cfg)
|
||||||
logger.Warn(
|
logger.Warn(
|
||||||
req.Context(),
|
req.Context(),
|
||||||
@@ -45,7 +43,6 @@ func Entrypoint(
|
|||||||
log.String("lookupPath", lookupPath),
|
log.String("lookupPath", lookupPath),
|
||||||
log.String("enpoint", endpoint),
|
log.String("enpoint", endpoint),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
http.Error(writer, err.Error(), http.StatusNotImplemented)
|
http.Error(writer, err.Error(), http.StatusNotImplemented)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -54,7 +58,6 @@ func Logger( // nolint:gocognit,funlen
|
|||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
enableRequestLogging bool,
|
enableRequestLogging bool,
|
||||||
enableBodyLogging bool,
|
enableBodyLogging bool,
|
||||||
skipLogging SkipLoggingPaths,
|
|
||||||
skipBodyLoggingEndpointPrefixes []string,
|
skipBodyLoggingEndpointPrefixes []string,
|
||||||
enableForceUnescapingUnicode bool,
|
enableForceUnescapingUnicode bool,
|
||||||
) Middleware {
|
) Middleware {
|
||||||
@@ -66,10 +69,6 @@ func Logger( // nolint:gocognit,funlen
|
|||||||
|
|
||||||
r := ctx.Request()
|
r := ctx.Request()
|
||||||
|
|
||||||
if skipLogging.ShouldSkip(r.URL.Path) {
|
|
||||||
return next.Handle(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint := ctx.EndpointMeta().NormalizedEndpoint
|
endpoint := ctx.EndpointMeta().NormalizedEndpoint
|
||||||
logBodyFromCurrenRequest := enableBodyLogging
|
logBodyFromCurrenRequest := enableBodyLogging
|
||||||
if logBodyFromCurrenRequest {
|
if logBodyFromCurrenRequest {
|
||||||
@@ -141,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")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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))
|
||||||
|
|||||||
@@ -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 // Chain по определению возвращает Handler-интерфейс
|
// nolint:ireturn, modernize
|
||||||
func Chain(root Handler, middlewares ...Middleware) Handler {
|
func Chain(root Handler, middlewares ...Middleware) Handler {
|
||||||
for _, m := range slices.Backward(middlewares) {
|
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||||
root = m(root)
|
root = middlewares[i](root)
|
||||||
}
|
}
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// SkipLoggingPaths — префиксы сырого request path, для которых
|
|
||||||
// полностью отключено логирование (строка лога, не только тела).
|
|
||||||
type SkipLoggingPaths struct {
|
|
||||||
prefixes []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSkipLoggingPaths нормализует значения конфы: обрезает ведущий '/',
|
|
||||||
// отбрасывает пустые.
|
|
||||||
func NewSkipLoggingPaths(rawPrefixes []string) SkipLoggingPaths {
|
|
||||||
prefixes := make([]string, 0, len(rawPrefixes))
|
|
||||||
for _, p := range rawPrefixes {
|
|
||||||
p = strings.TrimPrefix(p, "/")
|
|
||||||
if p != "" {
|
|
||||||
prefixes = append(prefixes, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SkipLoggingPaths{prefixes: prefixes}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShouldSkip — case-sensitive prefix-match. path — сырой r.URL.Path.
|
|
||||||
func (s SkipLoggingPaths) ShouldSkip(path string) bool {
|
|
||||||
path = strings.TrimPrefix(path, "/")
|
|
||||||
for _, p := range s.prefixes {
|
|
||||||
if strings.HasPrefix(path, p) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package middleware_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"isp-gate-service/middleware"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSkipLoggingPaths_ShouldSkip(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
prefixes []string
|
|
||||||
path string
|
|
||||||
wantSkip bool
|
|
||||||
}{
|
|
||||||
{name: "prefix without leading slash", prefixes: []string{"health"}, path: "/health", wantSkip: true},
|
|
||||||
{name: "prefix with leading slash is equivalent", prefixes: []string{"/health"}, path: "/health", wantSkip: true},
|
|
||||||
{name: "no match", prefixes: []string{"health"}, path: "/other", wantSkip: false},
|
|
||||||
{name: "empty value is discarded", prefixes: []string{""}, path: "/health", wantSkip: false},
|
|
||||||
{name: "root slash value is discarded", prefixes: []string{"/"}, path: "/health", wantSkip: false},
|
|
||||||
{name: "case sensitive", prefixes: []string{"Health"}, path: "/health/x", wantSkip: false},
|
|
||||||
{name: "plain prefix matches longer name", prefixes: []string{"health"}, path: "/healthz", wantSkip: true},
|
|
||||||
{name: "plain prefix matches nested path", prefixes: []string{"health"}, path: "/health/x", wantSkip: true},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
matcher := middleware.NewSkipLoggingPaths(test.prefixes)
|
|
||||||
require.Equal(t, test.wantSkip, matcher.ShouldSkip(test.path))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSkipLoggingPaths_ShouldSkip_EmptyList(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
matcher := middleware.NewSkipLoggingPaths(nil)
|
|
||||||
for _, path := range []string{"/", "/health", "/health/x", "/unknown"} {
|
|
||||||
require.False(t, matcher.ShouldSkip(path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UnknownLocation — catch-all для запросов, не попавших ни в один location.
|
|
||||||
// Warn пишется при включённом логировании запросов (как у log request).
|
|
||||||
func UnknownLocation(logger log.Logger, enableRequestLogging bool, skipLogging SkipLoggingPaths) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if enableRequestLogging && !skipLogging.ShouldSkip(r.URL.Path) {
|
|
||||||
logger.Warn(r.Context(), "request to unknown location",
|
|
||||||
log.String("httpMethod", r.Method),
|
|
||||||
log.String("path", r.URL.Path),
|
|
||||||
log.String("remoteAddr", r.RemoteAddr),
|
|
||||||
log.String("xForwardedFor", r.Header.Get("X-Forwarded-For")),
|
|
||||||
log.String("userAgent", r.Header.Get("User-Agent")),
|
|
||||||
log.Int("statusCode", http.StatusNotFound),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ответ идентичен текущему дефолтному NotFoundHandler gorilla/mux
|
|
||||||
http.Error(w, "404 page not found", http.StatusNotFound)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -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}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -46,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
@@ -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
|
||||||
}
|
}
|
||||||
@@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+31
-20
@@ -1,5 +1,4 @@
|
|||||||
// nolint:canonicalheader
|
package tests_test
|
||||||
package tests
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -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",
|
|
||||||
defaultWrapper.Endpoint(func(req entity.AuthenticateRequest) entity.AdminAuthenticateResponse {
|
|
||||||
return entity.AdminAuthenticateResponse{
|
return entity.AdminAuthenticateResponse{
|
||||||
Authenticated: true,
|
Authenticated: true,
|
||||||
ErrorReason: "",
|
ErrorReason: "",
|
||||||
AdminId: 1,
|
AdminId: 1,
|
||||||
}
|
}
|
||||||
}))
|
}).Mock("admin/secure/authorize", func(req entity.AdminAuthorizeRequest) entity.AdminAuthorizeResponse {
|
||||||
adminMux.POST("/admin/secure/authorize",
|
|
||||||
defaultWrapper.Endpoint(func(req entity.AdminAuthorizeRequest) entity.AdminAuthorizeResponse {
|
|
||||||
if req.Permission == "ok_permission" {
|
if req.Permission == "ok_permission" {
|
||||||
return entity.AdminAuthorizeResponse{Authorized: true}
|
return entity.AdminAuthorizeResponse{Authorized: true}
|
||||||
}
|
}
|
||||||
return entity.AdminAuthorizeResponse{Authorized: false}
|
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
@@ -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 {
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/log"
|
|
||||||
"go.uber.org/zap/zapcore"
|
|
||||||
)
|
|
||||||
|
|
||||||
type capturedLogEntry struct {
|
|
||||||
level zapcore.Level
|
|
||||||
message string
|
|
||||||
fields map[string]any
|
|
||||||
}
|
|
||||||
|
|
||||||
// logCapture ловит лог-записи в память. Zap-hook поля не получает,
|
|
||||||
// поэтому логгер реализован напрямую через интерфейс log.Logger.
|
|
||||||
type logCapture struct {
|
|
||||||
mu sync.Mutex
|
|
||||||
entries []capturedLogEntry
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) Error(_ context.Context, message any, fields ...log.Field) {
|
|
||||||
c.log(zapcore.ErrorLevel, message, fields...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) Warn(_ context.Context, message any, fields ...log.Field) {
|
|
||||||
c.log(zapcore.WarnLevel, message, fields...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) Info(_ context.Context, message any, fields ...log.Field) {
|
|
||||||
c.log(zapcore.InfoLevel, message, fields...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) Debug(_ context.Context, message any, fields ...log.Field) {
|
|
||||||
c.log(zapcore.DebugLevel, message, fields...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) log(level zapcore.Level, message any, fields ...log.Field) {
|
|
||||||
encoder := zapcore.NewMapObjectEncoder()
|
|
||||||
for _, field := range fields {
|
|
||||||
field.AddTo(encoder)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
c.entries = append(c.entries, capturedLogEntry{
|
|
||||||
level: level,
|
|
||||||
message: captureMessage(message),
|
|
||||||
fields: encoder.Fields,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *logCapture) entriesWithMessage(message string) []capturedLogEntry {
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
|
|
||||||
found := make([]capturedLogEntry, 0, len(c.entries))
|
|
||||||
for _, entry := range c.entries {
|
|
||||||
if entry.message == message {
|
|
||||||
found = append(found, entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found
|
|
||||||
}
|
|
||||||
|
|
||||||
func captureMessage(message any) string {
|
|
||||||
if msg, ok := message.(string); ok {
|
|
||||||
return msg
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%v", message)
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"isp-gate-service/assembly"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/entity"
|
|
||||||
"isp-gate-service/routes"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
"github.com/txix-open/isp-kit/cluster"
|
|
||||||
"github.com/txix-open/isp-kit/grpc/client"
|
|
||||||
"github.com/txix-open/isp-kit/http/httpcli"
|
|
||||||
"github.com/txix-open/isp-kit/http/httpclix"
|
|
||||||
"github.com/txix-open/isp-kit/lb"
|
|
||||||
"github.com/txix-open/isp-kit/log"
|
|
||||||
"github.com/txix-open/isp-kit/test"
|
|
||||||
"github.com/txix-open/isp-kit/test/grpct"
|
|
||||||
"github.com/txix-open/isp-kit/test/httpt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SkipBodyLoggingTestSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regression: skipBodyLoggingEndpointPrefixes с ведущим '/' должны
|
|
||||||
// работать и в non-skipAuth цепочках — лог-строка пишется, тела нет.
|
|
||||||
func (s *SkipBodyLoggingTestSuite) Test_KnownEndpoint_BodySkip_StrippedPrefix() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
config, systemCli, adminCli := s.authDependencies(test)
|
|
||||||
|
|
||||||
targetService := httpt.NewMock(test)
|
|
||||||
targetService.POST("/endpoint", func(ctx context.Context, httpReq *http.Request, req request) response {
|
|
||||||
return response{Id: req.Id}
|
|
||||||
})
|
|
||||||
targetUrl, err := url.Parse(targetService.BaseURL())
|
|
||||||
require.NoError(err)
|
|
||||||
targetHosts := map[string]*lb.RoundRobin{"target": lb.NewRoundRobin([]string{targetUrl.Host})}
|
|
||||||
|
|
||||||
routes := routes.NewRoutes(test.Logger())
|
|
||||||
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
|
||||||
Endpoints: []cluster.EndpointDescriptor{{Path: "/endpoint"}},
|
|
||||||
}})
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
locator := assembly.NewLocator(capture, nil, targetHosts, routes, systemCli, adminCli, nil, nil, nil)
|
|
||||||
locations := []conf.Location{{
|
|
||||||
SkipAuth: false,
|
|
||||||
PathPrefix: "/api",
|
|
||||||
Protocol: "http",
|
|
||||||
TargetModule: "target",
|
|
||||||
}}
|
|
||||||
handler, err := locator.Handler(config, locations)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Post(srv.URL+"/api/endpoint").
|
|
||||||
Header("x-application-token", "token").
|
|
||||||
Header("x-auth-admin", "mock-token").
|
|
||||||
JsonRequestBody(request{Id: "test"}).
|
|
||||||
Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusOK, resp.StatusCode())
|
|
||||||
|
|
||||||
// ровно одна лог-строка на запрос — без тел
|
|
||||||
require.Len(capture.entries, 1)
|
|
||||||
entries := capture.entriesWithMessage("log request")
|
|
||||||
require.Len(entries, 1)
|
|
||||||
require.NotContains(entries[0].fields, "request")
|
|
||||||
require.NotContains(entries[0].fields, "response")
|
|
||||||
}
|
|
||||||
|
|
||||||
// nolint:ireturn
|
|
||||||
func (s *SkipBodyLoggingTestSuite) authDependencies(test *test.Test) (conf.Remote, *client.Client, *httpclix.ClientBalancer) {
|
|
||||||
config := conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
|
||||||
Logging: conf.Logging{
|
|
||||||
LogLevel: log.DebugLevel,
|
|
||||||
RequestLogEnable: true,
|
|
||||||
BodyLogEnable: true,
|
|
||||||
SkipBodyLoggingEndpointPrefixes: []string{"/endpoint"},
|
|
||||||
},
|
|
||||||
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
systemService, systemCli := grpct.NewMock(test)
|
|
||||||
systemService.Mock("system/secure/authenticate", func() entity.AuthenticateResponse {
|
|
||||||
return entity.AuthenticateResponse{
|
|
||||||
Authenticated: true,
|
|
||||||
ErrorReason: "",
|
|
||||||
AuthData: &entity.AppAuthData{
|
|
||||||
ApplicationId: 4,
|
|
||||||
AppName: "test",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}).Mock("system/secure/authorize", func() entity.AuthorizeResponse {
|
|
||||||
return entity.AuthorizeResponse{Authorized: true}
|
|
||||||
})
|
|
||||||
|
|
||||||
adminService := httpt.NewMock(test)
|
|
||||||
adminService.Mock(http.MethodPost, "/admin/secure/authenticate", func(req entity.AdminAuthorizeRequest) entity.AdminAuthenticateResponse {
|
|
||||||
return entity.AdminAuthenticateResponse{
|
|
||||||
Authenticated: true,
|
|
||||||
ErrorReason: "",
|
|
||||||
AdminId: 1,
|
|
||||||
}
|
|
||||||
}).Mock(http.MethodPost, "/admin/secure/authorize", func(req entity.AdminAuthorizeRequest) entity.AdminAuthorizeResponse {
|
|
||||||
return entity.AdminAuthorizeResponse{Authorized: true}
|
|
||||||
})
|
|
||||||
adminCli := httpclix.NewClientBalancer([]string{adminService.BaseURL()})
|
|
||||||
|
|
||||||
return config, systemCli, adminCli
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSkipBodyLoggingTestSuite(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
suite.Run(t, new(SkipBodyLoggingTestSuite))
|
|
||||||
}
|
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"net/url"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"isp-gate-service/assembly"
|
|
||||||
"isp-gate-service/conf"
|
|
||||||
"isp-gate-service/routes"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
"github.com/txix-open/isp-kit/cluster"
|
|
||||||
"github.com/txix-open/isp-kit/http/httpcli"
|
|
||||||
"github.com/txix-open/isp-kit/lb"
|
|
||||||
"github.com/txix-open/isp-kit/test"
|
|
||||||
"github.com/txix-open/isp-kit/test/httpt"
|
|
||||||
"go.uber.org/zap/zapcore"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UnknownLocationsLoggingTestSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_UnknownPath_LogsWarn() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
locator := assembly.NewLocator(capture, nil, nil, routes.NewRoutes(test.Logger()), nil, nil, nil, nil, nil)
|
|
||||||
handler, err := locator.Handler(conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1},
|
|
||||||
Logging: conf.Logging{RequestLogEnable: true},
|
|
||||||
}, nil)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Get(srv.URL + "/unknown/path").Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusNotFound, resp.StatusCode())
|
|
||||||
body, err := resp.BodyCopy()
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues("404 page not found\n", string(body))
|
|
||||||
|
|
||||||
// ровно одна лог-строка на запрос, и это warn о незнакомой location
|
|
||||||
require.Len(capture.entries, 1)
|
|
||||||
entries := capture.entriesWithMessage("request to unknown location")
|
|
||||||
require.Len(entries, 1)
|
|
||||||
require.EqualValues(zapcore.WarnLevel, entries[0].level)
|
|
||||||
require.EqualValues(http.MethodGet, entries[0].fields["httpMethod"])
|
|
||||||
require.EqualValues("/unknown/path", entries[0].fields["path"])
|
|
||||||
require.EqualValues(http.StatusNotFound, entries[0].fields["statusCode"])
|
|
||||||
require.NotEmpty(entries[0].fields["remoteAddr"])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_UnknownPath_SuppressionSkipsWarn() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
config := conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1},
|
|
||||||
Logging: conf.Logging{
|
|
||||||
RequestLogEnable: true,
|
|
||||||
SkipLoggingPathPrefixes: []string{"/unknown"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
locator := assembly.NewLocator(capture, nil, nil, routes.NewRoutes(test.Logger()), nil, nil, nil, nil, nil)
|
|
||||||
handler, err := locator.Handler(config, nil)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Get(srv.URL + "/unknown/path").Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusNotFound, resp.StatusCode())
|
|
||||||
|
|
||||||
// запрос полностью не логируется
|
|
||||||
require.Empty(capture.entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn о незнакомой location привязан к requestLogEnable как обычный лог запросов:
|
|
||||||
// при выключенном флаге запрос не логируется, но ответ 404 — без изменений.
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_UnknownPath_RequestLoggingDisabled_NoWarn() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
locator := assembly.NewLocator(capture, nil, nil, routes.NewRoutes(test.Logger()), nil, nil, nil, nil, nil)
|
|
||||||
handler, err := locator.Handler(conf.Remote{Http: conf.Http{MaxRequestBodySizeInMb: 1}}, nil)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Get(srv.URL + "/unknown/path").Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusNotFound, resp.StatusCode())
|
|
||||||
body, err := resp.BodyCopy()
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues("404 page not found\n", string(body))
|
|
||||||
|
|
||||||
require.Empty(capture.entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_UnknownEndpoint_LogsWarn() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
routes := routes.NewRoutes(test.Logger())
|
|
||||||
err := routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
|
||||||
Endpoints: []cluster.EndpointDescriptor{{Path: "endpoint"}},
|
|
||||||
}})
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
config := conf.Remote{Http: conf.Http{MaxRequestBodySizeInMb: 1}}
|
|
||||||
locator := assembly.NewLocator(capture, nil, nil, routes, nil, nil, nil, nil, nil)
|
|
||||||
locations := []conf.Location{{
|
|
||||||
SkipAuth: false,
|
|
||||||
PathPrefix: "/api",
|
|
||||||
Protocol: "grpc",
|
|
||||||
TargetModule: "target",
|
|
||||||
}}
|
|
||||||
handler, err := locator.Handler(config, locations)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Post(srv.URL + "/api/nope").Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusNotImplemented, resp.StatusCode())
|
|
||||||
|
|
||||||
// ровно одна лог-строка на запрос — warn о неизвестном эндпоинте
|
|
||||||
require.Len(capture.entries, 1)
|
|
||||||
entries := capture.entriesWithMessage("call unknown method")
|
|
||||||
require.Len(entries, 1)
|
|
||||||
require.EqualValues(zapcore.WarnLevel, entries[0].level)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_UnknownEndpoint_SuppressionSkipsWarn() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
routes := routes.NewRoutes(test.Logger())
|
|
||||||
err := routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
|
||||||
Endpoints: []cluster.EndpointDescriptor{{Path: "endpoint"}},
|
|
||||||
}})
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
config := conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1},
|
|
||||||
Logging: conf.Logging{SkipLoggingPathPrefixes: []string{"/api/nope"}},
|
|
||||||
}
|
|
||||||
locator := assembly.NewLocator(capture, nil, nil, routes, nil, nil, nil, nil, nil)
|
|
||||||
locations := []conf.Location{{
|
|
||||||
SkipAuth: false,
|
|
||||||
PathPrefix: "/api",
|
|
||||||
Protocol: "grpc",
|
|
||||||
TargetModule: "target",
|
|
||||||
}}
|
|
||||||
handler, err := locator.Handler(config, locations)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Post(srv.URL + "/api/nope").Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusNotImplemented, resp.StatusCode())
|
|
||||||
|
|
||||||
require.Empty(capture.entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_KnownEndpoint_LogsRequest() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
targetService := httpt.NewMock(test)
|
|
||||||
targetService.POST("/endpoint", func(ctx context.Context, httpReq *http.Request, req request) response {
|
|
||||||
return response{Id: req.Id}
|
|
||||||
})
|
|
||||||
targetUrl, err := url.Parse(targetService.BaseURL())
|
|
||||||
require.NoError(err)
|
|
||||||
targetHosts := map[string]*lb.RoundRobin{"target": lb.NewRoundRobin([]string{targetUrl.Host})}
|
|
||||||
|
|
||||||
routes := routes.NewRoutes(test.Logger())
|
|
||||||
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
|
||||||
Endpoints: []cluster.EndpointDescriptor{{Path: "/endpoint"}},
|
|
||||||
}})
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
config := conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
|
||||||
Logging: conf.Logging{RequestLogEnable: true},
|
|
||||||
}
|
|
||||||
locator := assembly.NewLocator(capture, nil, targetHosts, routes, nil, nil, nil, nil, nil)
|
|
||||||
locations := []conf.Location{{
|
|
||||||
SkipAuth: true,
|
|
||||||
PathPrefix: "/api",
|
|
||||||
Protocol: "http",
|
|
||||||
TargetModule: "target",
|
|
||||||
}}
|
|
||||||
handler, err := locator.Handler(config, locations)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Post(srv.URL + "/api/endpoint").
|
|
||||||
JsonRequestBody(request{Id: "test"}).
|
|
||||||
Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusOK, resp.StatusCode())
|
|
||||||
|
|
||||||
// ровно одна лог-строка на запрос — log request
|
|
||||||
require.Len(capture.entries, 1)
|
|
||||||
entries := capture.entriesWithMessage("log request")
|
|
||||||
require.Len(entries, 1)
|
|
||||||
require.EqualValues("/api/endpoint", entries[0].fields["path"])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UnknownLocationsLoggingTestSuite) Test_KnownEndpoint_SuppressionSkipsRequestLog() {
|
|
||||||
test, require := test.New(s.T())
|
|
||||||
capture := &logCapture{}
|
|
||||||
|
|
||||||
targetService := httpt.NewMock(test)
|
|
||||||
targetService.POST("/endpoint", func(ctx context.Context, httpReq *http.Request, req request) response {
|
|
||||||
return response{Id: req.Id}
|
|
||||||
})
|
|
||||||
targetUrl, err := url.Parse(targetService.BaseURL())
|
|
||||||
require.NoError(err)
|
|
||||||
targetHosts := map[string]*lb.RoundRobin{"target": lb.NewRoundRobin([]string{targetUrl.Host})}
|
|
||||||
|
|
||||||
routes := routes.NewRoutes(test.Logger())
|
|
||||||
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
|
||||||
Endpoints: []cluster.EndpointDescriptor{{Path: "/endpoint"}},
|
|
||||||
}})
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
config := conf.Remote{
|
|
||||||
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
|
||||||
Logging: conf.Logging{
|
|
||||||
RequestLogEnable: true,
|
|
||||||
SkipLoggingPathPrefixes: []string{"/api/endpoint"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
locator := assembly.NewLocator(capture, nil, targetHosts, routes, nil, nil, nil, nil, nil)
|
|
||||||
locations := []conf.Location{{
|
|
||||||
SkipAuth: true,
|
|
||||||
PathPrefix: "/api",
|
|
||||||
Protocol: "http",
|
|
||||||
TargetModule: "target",
|
|
||||||
}}
|
|
||||||
handler, err := locator.Handler(config, locations)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
srv := httptest.NewServer(handler)
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
resp, err := httpcli.New().Post(srv.URL + "/api/endpoint").
|
|
||||||
JsonRequestBody(request{Id: "test"}).
|
|
||||||
Do(s.T().Context())
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(http.StatusOK, resp.StatusCode())
|
|
||||||
|
|
||||||
require.Empty(capture.entries)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUnknownLocationsLoggingTestSuite(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
suite.Run(t, new(UnknownLocationsLoggingTestSuite))
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user