From 39dbeda9d8cfaa3b841bde5605808ad81c4240d6 Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Mon, 30 May 2022 17:20:52 +0300 Subject: [PATCH] MSP-625 update config --- conf/config.yml | 5 +- conf/default_remote_config.json | 60 +--------------------- conf/local.go | 24 +++++++++ conf/local_config.go | 34 ------------- conf/remote.go | 25 +++++++++ conf/remote_config.go | 89 --------------------------------- 6 files changed, 53 insertions(+), 184 deletions(-) create mode 100644 conf/local.go delete mode 100644 conf/local_config.go create mode 100644 conf/remote.go delete mode 100644 conf/remote_config.go diff --git a/conf/config.yml b/conf/config.yml index 8938823..e82578f 100644 --- a/conf/config.yml +++ b/conf/config.yml @@ -1,14 +1,13 @@ configServiceAddress: ip: 127.0.0.1 port: 9001 -httpOuterAddress: +grpcOuterAddress: #ip: 127.0.0.1 port: 9003 -httpInnerAddress: +grpcInnerAddress: ip: 0.0.0.0 port: 9003 moduleName: isp-gate -instanceUuid: 9d89354b-c728-4b48-b002-a7d3b229f151 locations: - pathPrefix: /api protocol: grpc diff --git a/conf/default_remote_config.json b/conf/default_remote_config.json index 1cdb787..49f5cba 100644 --- a/conf/default_remote_config.json +++ b/conf/default_remote_config.json @@ -1,62 +1,6 @@ { - "database": { - "address": "{{ msp_pgsql_address }}", - "port": "{{ msp_pgsql_port }}", - "schema": "gate_service", - "database": "{{ msp_pgsql_name }}", - "username": "{{ msp_pgsql_user }}", - "password": "{{ msp_pgsql_password }}", - "createSchema": true - }, - "grpcSetting": { - "proxyGrpcErrorDetails": true, - "enableOriginalProtoErrors": false - }, - "httpSetting": { - "maxRequestBodySizeBytes": 0 - }, - "accountingSetting": { - "enable": false, - "snapshotTimeout": "15m", - "setting": [ - ], - "storing": { - "size": 10000, - "timeout": "10m" - } - }, - "journalSetting": { - "journal": { - "filename": "/var/log/isp-gate-service/runtime.log", - "maxSizeMb": 512, - "enable": false, - "compress": true - } - }, - "redis": { - "password": "{{ msp_redis_password }}", - "defaultDB": 0, - "address": { - "ip": "{{ msp_redis_address }}", - "port": "{{ msp_redis_port }}" - } - }, - "metrics": { - "gc": true, - "memory": true, - "address": { - "path": "/metrics", - "port": "9553", - "ip": "0.0.0.0" - } - }, + "logLevel": "debug", "tokensSetting": { - "applicationSecret": "{{ msp_app_secret }}", - "applicationVerify": false, "adminSecret": "{{ msp_admin_secret }}" - }, - "authCacheSetting": { - "enableCache": false, - "evictTimeout": "1m" } -} +} \ No newline at end of file diff --git a/conf/local.go b/conf/local.go new file mode 100644 index 0000000..8ea591f --- /dev/null +++ b/conf/local.go @@ -0,0 +1,24 @@ +package conf + +import ( + "github.com/integration-system/isp-kit/bootstrap" +) + +const ( + HttpProtocol = "http" + GrpcProtocol = "grpc" + WebsocketProtocol = "websocket" +) + +type Local struct { + *bootstrap.LocalConfig + Locations []Location +} + +type Location struct { + SkipAuth bool + SkipExistCheck bool + PathPrefix string `valid:"required"` + Protocol string `valid:"required,in(http|grpc|websocket)"` + TargetModule string `valid:"required"` +} diff --git a/conf/local_config.go b/conf/local_config.go deleted file mode 100644 index e89de94..0000000 --- a/conf/local_config.go +++ /dev/null @@ -1,34 +0,0 @@ -package conf - -import ( - "github.com/integration-system/isp-lib/v2/config" - "github.com/integration-system/isp-lib/v2/structure" -) - -type ( - Configuration struct { - config.CommonLocalConfig - InstanceUuid string `valid:"required~Required"` - HttpOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"httpOuterAddress"` - HttpInnerAddress structure.AddressConfiguration `valid:"required~Required" json:"httpInnerAddress"` - Locations []Location - } - - Location struct { - SkipAuth bool - SkipExistCheck bool - PathPrefix string `valid:"required~Required"` - Protocol string `valid:"required~Required"` - TargetModule string `valid:"required~Required"` - } -) - -func GetLocationsByTargetModule(locations []Location) map[string][]Location { - requiredModules := make(map[string][]Location) - - for _, loc := range locations { - requiredModules[loc.TargetModule] = append(requiredModules[loc.TargetModule], loc) - } - - return requiredModules -} diff --git a/conf/remote.go b/conf/remote.go new file mode 100644 index 0000000..a8d6fd1 --- /dev/null +++ b/conf/remote.go @@ -0,0 +1,25 @@ +package conf + +import ( + "reflect" + + "github.com/integration-system/isp-kit/log" + "github.com/integration-system/isp-kit/rc/schema" + "github.com/integration-system/jsonschema" +) + +func init() { + schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Type) { + t.Type = "string" + t.Enum = []interface{}{"debug", "info", "error", "fatal"} + }) +} + +type Remote struct { + LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"` + TokensSetting TokensSetting `schema:"Настройка секретов"` +} + +type TokensSetting struct { + AdminSecret string `schema:"Секрет для проверки токена администратора"` +} diff --git a/conf/remote_config.go b/conf/remote_config.go deleted file mode 100644 index 4c9865c..0000000 --- a/conf/remote_config.go +++ /dev/null @@ -1,89 +0,0 @@ -package conf - -import ( - "time" - - "github.com/integration-system/isp-lib/v2/structure" -) - -const ( - KB = int64(1024) - MB = int64(1 << 20) - - defaultSyncTimeout = 30 * time.Second - defaultStreamTimeout = 60 * time.Second - - defaultBufferSize = 4 * KB - defaultMaxRequestBodySize = 512 * MB - DefaultMaxResponseBodySize = 32 * MB -) - -type ( - RemoteConfig struct { - TokensSetting TokensSetting `schema:"Настройка секретов"` - HttpSetting HttpSetting `schema:"Настройка сервера"` - GrpcSetting GrpcSetting `schema:"Настройка grpc соединения"` - Metrics structure.MetricConfiguration `schema:"Настройка метрик"` - JournalSetting Journal `schema:"Настройка журалирования"` - Redis structure.RedisConfiguration `schema:"Настройка Redis" valid:"required~Required"` - } - - Journal struct { - Journal JorunalConfig `schema:"Настройка конфигурации"` - MethodsPatterns []string `schema:"Список методов для логирования,список строк вида: 'module/group/method'(* - для частичного совпадения). При обработке запроса, если вызываемый метод совпадает со строкой из списка, тела запроса и ответа записываются в лог"` - } - - JorunalConfig struct { - Enable bool `schema:"Включение/отключение журналирования"` - Filename string `schema:"Имя файла,путь до файла в который будут записываться логи"` - MaxSizeMb int `schema:"Максимальный размер файла,ограничение по размеру файла после достижения которого логи будут записываться в новый файл"` - Compress bool `schema:"Сжатие логов,архивирует файлы в gzip"` - } - - TokensSetting struct { - AdminSecret string `schema:"Секрет для проверки токена администратора"` - ApplicationSecret string `schema:"Секрет для проверки токена приложений"` - ApplicationVerify bool `schema:"Проверка подписи токена приложений"` - UserSecret string `schema:"Секрет для проверки токена пользователя"` - } - - HttpSetting struct { - MaxRequestBodySizeBytes int64 `schema:"Максимальный размер тела запроса,в байтайх, по умолчанию: 512 MB"` - } - - GrpcSetting struct { - EnableOriginalProtoErrors bool `schema:"Проксирование ошибок в протобаф,включение/отключение проксирования, по умолчанию отключено"` - ProxyGrpcErrorDetails bool `schema:"Проксирование первого элемента из details GRPC ошибки,включение/отключение проксирования, по умолчанию отключено"` - MultipartDataTransferBufferSizeBytes int64 `schema:"Размер буфера для передачи бинарных файлов,по умолчанию 4 KB"` - SyncInvokeMethodTimeoutMs int64 `schema:"Время ожидания вызова метода,значение в миллисекундах, по умолчанию: 30000"` - StreamInvokeMethodTimeoutMs int64 `schema:"Время ожидания передачи и обработки файла,значение в миллисекундах, по умолчанию: 60000"` - } -) - -func (cfg GrpcSetting) GetSyncInvokeTimeout() time.Duration { - if cfg.SyncInvokeMethodTimeoutMs <= 0 { - return defaultSyncTimeout - } - return time.Duration(cfg.SyncInvokeMethodTimeoutMs) * time.Millisecond -} - -func (cfg GrpcSetting) GetStreamInvokeTimeout() time.Duration { - if cfg.StreamInvokeMethodTimeoutMs <= 0 { - return defaultStreamTimeout - } - return time.Duration(cfg.StreamInvokeMethodTimeoutMs) * time.Millisecond -} - -func (cfg GrpcSetting) GetTransferFileBufferSize() int64 { - if cfg.MultipartDataTransferBufferSizeBytes <= 0 { - return defaultBufferSize - } - return cfg.MultipartDataTransferBufferSizeBytes -} - -func (cfg HttpSetting) GetMaxRequestBodySize() int64 { - if cfg.MaxRequestBodySizeBytes <= 0 { - return defaultMaxRequestBodySize - } - return cfg.MaxRequestBodySizeBytes -}