MSP-634 remove redis
This commit is contained in:
1 parent
82a2d8d98f
commit
894781c727
13 files changed
+25
-367
No files matched your search
+2
-17
@@ -10,17 +10,14 @@ import (
|
||||
"github.com/integration-system/isp-kit/dbx"
|
||||
"github.com/integration-system/isp-kit/grpc"
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
rd "github.com/integration-system/isp-lib/v2/redis"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/migrations"
|
||||
"isp-system-service/redis"
|
||||
)
|
||||
|
||||
type Assembly struct {
|
||||
boot *bootstrap.Bootstrap
|
||||
db *dbrx.Client
|
||||
redis *rd.RxClient
|
||||
server *grpc.Server
|
||||
logger *log.Adapter
|
||||
instanceUuid string
|
||||
@@ -36,17 +33,9 @@ func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||
return nil, errors.WithMessage(err, "read local config")
|
||||
}
|
||||
|
||||
redisCli := rd.NewRxClient(
|
||||
rd.WithInitHandler(func(c *rd.Client, err error) {
|
||||
if err != nil {
|
||||
boot.App.Logger().Fatal(c.Context(), "redis init", log.Any("err", err))
|
||||
}
|
||||
}))
|
||||
|
||||
return &Assembly{
|
||||
boot: boot,
|
||||
db: dbCli,
|
||||
redis: redisCli,
|
||||
server: server,
|
||||
logger: boot.App.Logger(),
|
||||
instanceUuid: localConfig.InstanceUuid,
|
||||
@@ -63,10 +52,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
||||
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade remote config"))
|
||||
}
|
||||
|
||||
a.redis.ReceiveConfiguration(newCfg.Redis)
|
||||
redisCli := redis.NewClient(a.instanceUuid, a.redis)
|
||||
|
||||
migrations.Initialize.SetParams(redisCli, a.boot.MigrationsDir, newCfg.Database.Schema)
|
||||
migrations.Initialize.SetParams(a.boot.MigrationsDir, newCfg.Database.Schema)
|
||||
|
||||
a.logger.SetLevel(newCfg.LogLevel)
|
||||
|
||||
@@ -75,7 +61,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
||||
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade db client"), log.Any("config", newCfg.Database))
|
||||
}
|
||||
|
||||
locator := NewLocator(a.db, redisCli, a.logger)
|
||||
locator := NewLocator(a.db, a.logger)
|
||||
handler := locator.Handler(newCfg)
|
||||
a.server.Upgrade(handler)
|
||||
|
||||
@@ -102,7 +88,6 @@ func (a *Assembly) Closers() []app.Closer {
|
||||
a.server.Shutdown()
|
||||
return nil
|
||||
}),
|
||||
a.redis,
|
||||
a.db,
|
||||
}
|
||||
}
|
||||
+4
-7
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/controller"
|
||||
"isp-system-service/redis"
|
||||
"isp-system-service/repository"
|
||||
"isp-system-service/routes"
|
||||
"isp-system-service/service"
|
||||
@@ -21,14 +20,12 @@ type DB interface {
|
||||
|
||||
type Locator struct {
|
||||
db DB
|
||||
redis redis.Client
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewLocator(db DB, redisCli redis.Client, logger log.Logger) Locator {
|
||||
func NewLocator(db DB, logger log.Logger) Locator {
|
||||
return Locator{
|
||||
db: db,
|
||||
redis: redisCli,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -41,13 +38,13 @@ func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
|
||||
serviceRep := repository.NewService(l.db)
|
||||
tokenRep := repository.NewToken(l.db)
|
||||
|
||||
accessListService := service.NewAccessList(l.redis, txManager, accessListRep, applicationRep)
|
||||
applicationService := service.NewApplication(l.redis, txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
||||
accessListService := service.NewAccessList(txManager, accessListRep, applicationRep)
|
||||
applicationService := service.NewApplication(txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
||||
domainService := service.NewDomain(domainRep)
|
||||
serviceService := service.NewService(domainRep, serviceRep)
|
||||
|
||||
jwtService := service.NewJwt(cfg.ApplicationSecret)
|
||||
tokenService := service.NewToken(l.redis, cfg.DefaultTokenExpireTime, jwtService, applicationService, txManager,
|
||||
tokenService := service.NewToken(cfg.DefaultTokenExpireTime, jwtService, applicationService, txManager,
|
||||
applicationRep, domainRep, serviceRep, tokenRep,
|
||||
)
|
||||
|
||||
|
||||
@@ -8,13 +8,5 @@
|
||||
"host": "{{ msp_pgsql_address }}",
|
||||
"port": 5432
|
||||
},
|
||||
"redis": {
|
||||
"address": {
|
||||
"ip": "{{ msp_redis_address }}",
|
||||
"port": "{{ msp_redis_port }}"
|
||||
},
|
||||
"defaultDB": 0,
|
||||
"password": "{{ msp_redis_password }}"
|
||||
},
|
||||
"applicationSecret": "{{ msp_app_secret }}"
|
||||
}
|
||||
+4
-6
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/integration-system/isp-kit/dbx"
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
"github.com/integration-system/isp-kit/rc/schema"
|
||||
"github.com/integration-system/isp-lib/v2/structure"
|
||||
"github.com/integration-system/jsonschema"
|
||||
)
|
||||
|
||||
@@ -18,9 +17,8 @@ func init() {
|
||||
}
|
||||
|
||||
type Remote struct {
|
||||
Database dbx.Config `schema:"Настройка базы данных"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
Redis structure.RedisConfiguration `schema:"Настройка Redis" valid:"required~Required"`
|
||||
DefaultTokenExpireTime int `schema:"Время жизни токена по умолчанию,время жизни токена в миллисекундах с момента его создания. если = -1 - время жизни неограниченно"`
|
||||
ApplicationSecret string `schema:"Ключ для подписи application токенов" valid:"required~Required"`
|
||||
Database dbx.Config `schema:"Настройка базы данных"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
DefaultTokenExpireTime int `schema:"Время жизни токена по умолчанию,время жизни токена в миллисекундах с момента его создания. если = -1 - время жизни неограниченно"`
|
||||
ApplicationSecret string `schema:"Ключ для подписи application токенов" valid:"required~Required"`
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package entity
|
||||
|
||||
type RedisSetToken struct {
|
||||
Token string
|
||||
ExpireTime int
|
||||
DomainIdentity int
|
||||
ServiceIdentity int
|
||||
ApplicationIdentity int
|
||||
}
|
||||
|
||||
type RedisApplicationPermission struct {
|
||||
AppId int
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
@@ -3,25 +3,32 @@ module isp-system-service
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.3
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/integration-system/isp-kit v1.10.0
|
||||
github.com/integration-system/isp-lib/v2 v2.10.0
|
||||
github.com/integration-system/jsonschema v1.0.1
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pressly/goose v2.7.0+incompatible
|
||||
google.golang.org/grpc v1.48.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.1.0 // indirect
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||
github.com/go-openapi/spec v0.20.5 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/iancoleman/strcase v0.2.0 // indirect
|
||||
github.com/integration-system/bellows v1.0.1 // indirect
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f // indirect
|
||||
github.com/integration-system/isp-etp-go/v2 v2.1.3 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.12.1 // indirect
|
||||
@@ -39,6 +46,7 @@ require (
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
@@ -57,9 +65,6 @@ require (
|
||||
github.com/spf13/viper v1.12.0 // indirect
|
||||
github.com/subosito/gotenv v1.4.0 // indirect
|
||||
github.com/swaggo/swag v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v0.19.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
@@ -68,6 +73,7 @@ require (
|
||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
||||
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.10 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220713161829-9c7dac0a6568 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.6 // indirect
|
||||
@@ -76,18 +82,3 @@ require (
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
nhooyr.io/websocket v1.8.7 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.1.0 // indirect
|
||||
github.com/Masterminds/squirrel v1.5.3
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/go-openapi/spec v0.20.5 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-redis/redis/v8 v8.8.2
|
||||
github.com/integration-system/isp-lib/v2 v2.10.0
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/pressly/goose v2.7.0+incompatible
|
||||
golang.org/x/tools v0.1.10 // indirect
|
||||
google.golang.org/grpc v1.48.0
|
||||
)
|
||||
@@ -139,7 +139,6 @@ github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6ps
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
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/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
|
||||
@@ -210,7 +209,6 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPgjj221I1QHci2A=
|
||||
github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
||||
github.com/go-redis/redis/v8 v8.8.2 h1:O/NcHqobw7SEptA0yA6up6spZVFtwE06SXM8rgLtsP8=
|
||||
github.com/go-redis/redis/v8 v8.8.2/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y=
|
||||
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
@@ -362,7 +360,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
|
||||
github.com/integration-system/bellows v1.0.1 h1:7g1lhD/6EcvsSo9iuiFqw98XGS78Sko6kUKPzfte/SY=
|
||||
github.com/integration-system/bellows v1.0.1/go.mod h1:qHPg1ptN3AHHr0f/wvoicfA2LOCprOyrbXnIa5QIRe0=
|
||||
github.com/integration-system/bgjob v1.2.0/go.mod h1:KYaolHZc3OYhtY+lPN71M0y+1DJXEzRanaya1MU0KvU=
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f h1:52UOJguw5yqe1y2JjmyVxGcZf3kv2BQeUodR363MkiQ=
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f/go.mod h1:w+dmaWojuIwNujSYg6qt1wKHhSdorLOivCEl/XuLzbM=
|
||||
github.com/integration-system/gowsdl v1.0.0/go.mod h1:ZwTCE+Av5aQLnPj2/3PIop6mzCs1FY7jXrcWDvSjrBA=
|
||||
github.com/integration-system/grmq v1.1.1 h1:qd3n0rvNsJCO6V8qdRRttBGIJ7gwOAerEInWcqJudsw=
|
||||
@@ -535,17 +532,14 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
|
||||
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
@@ -710,13 +704,9 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng=
|
||||
go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg=
|
||||
go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg=
|
||||
go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc=
|
||||
go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q=
|
||||
go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA=
|
||||
go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc=
|
||||
go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
@@ -1284,7 +1274,6 @@ gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
|
||||
gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -11,7 +10,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pressly/goose"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,14 +27,9 @@ func init() {
|
||||
goose.AddMigration(Initialize.Up, Initialize.Down)
|
||||
}
|
||||
|
||||
type IRedis interface {
|
||||
SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error
|
||||
}
|
||||
|
||||
var Initialize = &initializeMigration{}
|
||||
|
||||
type initializeMigration struct {
|
||||
redis IRedis
|
||||
migrationDir string
|
||||
schema string
|
||||
}
|
||||
@@ -47,8 +40,7 @@ type identity struct {
|
||||
serviceId int
|
||||
}
|
||||
|
||||
func (i *initializeMigration) SetParams(redis IRedis, migrationDir string, schema string) {
|
||||
i.redis = redis
|
||||
func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
||||
i.migrationDir = migrationDir
|
||||
i.schema = schema
|
||||
}
|
||||
@@ -132,17 +124,6 @@ func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithSer
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert token")
|
||||
}
|
||||
|
||||
err = i.redis.SetApplicationToken(context.Background(), entity.RedisSetToken{
|
||||
Token: t.Token,
|
||||
ExpireTime: t.ExpireTime,
|
||||
DomainIdentity: domainId,
|
||||
ServiceIdentity: serviceId,
|
||||
ApplicationIdentity: appId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "redis set token")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-164
@@ -1,164 +0,0 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
rd "github.com/go-redis/redis/v8"
|
||||
"github.com/integration-system/isp-lib/v2/redis"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
systemIdentityFieldInDb = "1"
|
||||
domainIdentityFieldInDb = "2"
|
||||
serviceIdentityFieldInDb = "3"
|
||||
applicationIdentityFieldInDb = "4"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
instanceUuid string
|
||||
cli *redis.RxClient
|
||||
}
|
||||
|
||||
func NewClient(instanceUuid string, cli *redis.RxClient) Client {
|
||||
return Client{
|
||||
cli: cli,
|
||||
instanceUuid: instanceUuid,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Client) SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error {
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(pipeline rd.Pipeliner) error {
|
||||
idMap := map[string]interface{}{
|
||||
systemIdentityFieldInDb: domain.DefaultSystemId,
|
||||
domainIdentityFieldInDb: req.DomainIdentity,
|
||||
serviceIdentityFieldInDb: req.ServiceIdentity,
|
||||
applicationIdentityFieldInDb: req.ApplicationIdentity,
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s|%s", req.Token, r.instanceUuid)
|
||||
stat := pipeline.HMSet(ctx, key, idMap)
|
||||
err := stat.Err()
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "pipeline hmset")
|
||||
}
|
||||
|
||||
if req.ExpireTime > 0 {
|
||||
err = pipeline.Expire(ctx, req.Token, time.Duration(req.ExpireTime)*time.Millisecond).Err()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline expire token")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) UpdateApplicationPermission(ctx context.Context, req entity.RedisApplicationPermission) error {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeline rd.Pipeliner) error {
|
||||
key := fmt.Sprintf("%d|%s", req.AppId, req.Method)
|
||||
_, err := pipeline.Set(ctx, key, req.Value, 0).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline set")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) UpdateApplicationPermissionList(ctx context.Context, removed []string, added []interface{}) error {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeline rd.Pipeliner) error {
|
||||
if len(removed) > 0 {
|
||||
_, err := pipeline.Del(ctx, removed...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
}
|
||||
|
||||
if len(added) > 0 {
|
||||
_, err := pipeline.MSet(ctx, added...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline mset")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) DeleteApplication(ctx context.Context, appTokens []string, applicationPermissionList []string) error {
|
||||
keys := make([]string, len(appTokens))
|
||||
for i, token := range appTokens {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, r.instanceUuid)
|
||||
}
|
||||
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(pipeline rd.Pipeliner) error {
|
||||
if len(appTokens) > 0 {
|
||||
_, err := pipeline.Del(ctx, keys...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
}
|
||||
|
||||
if len(applicationPermissionList) > 0 {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeliner rd.Pipeliner) error {
|
||||
_, err := pipeliner.Del(ctx, applicationPermissionList...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) DeleteToken(ctx context.Context, tokens []string) error {
|
||||
keys := make([]string, len(tokens))
|
||||
for i, token := range tokens {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, r.instanceUuid)
|
||||
}
|
||||
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(ctx, keys...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "del keys")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+1
-32
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
@@ -33,26 +32,18 @@ type IAccessListTxRunner interface {
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetListTx) error) error
|
||||
}
|
||||
|
||||
type IAccessListRedis interface {
|
||||
UpdateApplicationPermission(ctx context.Context, req entity.RedisApplicationPermission) error
|
||||
UpdateApplicationPermissionList(ctx context.Context, removed []string, added []interface{}) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
redis IAccessListRedis
|
||||
tx IAccessListTxRunner
|
||||
accessListRep IAccessListAccessListRep
|
||||
applicationRep IAccessListApplicationRep
|
||||
}
|
||||
|
||||
func NewAccessList(
|
||||
redis IAccessListRedis,
|
||||
tx IAccessListTxRunner,
|
||||
accessListRep IAccessListAccessListRep,
|
||||
applicationRep IAccessListApplicationRep,
|
||||
) AccessList {
|
||||
return AccessList{
|
||||
redis: redis,
|
||||
tx: tx,
|
||||
accessListRep: accessListRep,
|
||||
applicationRep: applicationRep,
|
||||
@@ -98,15 +89,6 @@ func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneR
|
||||
return errors.WithMessagef(err, "upsert access list")
|
||||
}
|
||||
|
||||
err = s.redis.UpdateApplicationPermission(ctx, entity.RedisApplicationPermission{
|
||||
AppId: request.AppId,
|
||||
Method: request.Method,
|
||||
Value: request.Value,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "redis update application permission")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -125,9 +107,8 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx IAccessListSetListTx) error {
|
||||
oldAccessList := make([]entity.AccessList, 0)
|
||||
if req.RemoveOld {
|
||||
oldAccessList, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
_, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete access list by app_id")
|
||||
}
|
||||
@@ -135,7 +116,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
|
||||
newAccessList := make([]entity.AccessList, len(req.Methods))
|
||||
updateMethods := make([]string, len(req.Methods))
|
||||
redisMsetRequest := make([]interface{}, 0)
|
||||
for i, m := range req.Methods {
|
||||
updateMethods[i] = m.Method
|
||||
newAccessList[i] = entity.AccessList{
|
||||
@@ -143,12 +123,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
Method: m.Method,
|
||||
Value: m.Value,
|
||||
}
|
||||
redisMsetRequest = append(redisMsetRequest, fmt.Sprintf("%d|%s", req.AppId, m.Method), m.Value)
|
||||
}
|
||||
|
||||
redisDelRequest := make([]string, len(oldAccessList))
|
||||
for i, access := range oldAccessList {
|
||||
redisDelRequest[i] = fmt.Sprintf("%d|%s", req.AppId, access.Method)
|
||||
}
|
||||
|
||||
if len(newAccessList) > 0 {
|
||||
@@ -163,11 +137,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
}
|
||||
|
||||
err = s.redis.UpdateApplicationPermissionList(ctx, redisDelRequest, redisMsetRequest)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis update application permission list")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
@@ -32,8 +31,6 @@ type IApplicationDomainRep interface {
|
||||
}
|
||||
|
||||
type IApplicationDeleteTx interface {
|
||||
GetAccessListByAppIdList(ctx context.Context, appIdList []int) ([]entity.AccessList, error)
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
DeleteApplicationByIdList(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
@@ -41,12 +38,7 @@ type IApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx IApplicationDeleteTx) error) error
|
||||
}
|
||||
|
||||
type IApplicationRedis interface {
|
||||
DeleteApplication(ctx context.Context, appTokens []string, applicationPermissionList []string) error
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
redis IApplicationRedis
|
||||
tx IApplicationTxRunner
|
||||
applicationRep IApplicationApplicationRep
|
||||
domainRep IApplicationDomainRep
|
||||
@@ -55,7 +47,6 @@ type Application struct {
|
||||
}
|
||||
|
||||
func NewApplication(
|
||||
redis IApplicationRedis,
|
||||
tx IApplicationTxRunner,
|
||||
applicationRep IApplicationApplicationRep,
|
||||
domainRep IApplicationDomainRep,
|
||||
@@ -63,7 +54,6 @@ func NewApplication(
|
||||
tokenRep IApplicationTokenRep,
|
||||
) Application {
|
||||
return Application{
|
||||
redis: redis,
|
||||
tx: tx,
|
||||
applicationRep: applicationRep,
|
||||
domainRep: domainRep,
|
||||
@@ -240,36 +230,11 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
func (s Application) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
count := 0
|
||||
err := s.tx.ApplicationDeleteTx(ctx, func(ctx context.Context, tx IApplicationDeleteTx) error {
|
||||
accessList, err := tx.GetAccessListByAppIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get access list by app_id list")
|
||||
}
|
||||
|
||||
permissionDeleteList := make([]string, 0)
|
||||
for _, access := range accessList {
|
||||
permissionDeleteList = append(permissionDeleteList, fmt.Sprintf("%d|%s", access.AppId, access.Method))
|
||||
}
|
||||
|
||||
tokens, err := tx.GetTokenByAppIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get token by app_id list")
|
||||
}
|
||||
|
||||
tokenIdList := make([]string, len(tokens))
|
||||
for i, t := range tokens {
|
||||
tokenIdList[i] = t.Token
|
||||
}
|
||||
|
||||
deletedApp, err := tx.DeleteApplicationByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete application by id list")
|
||||
}
|
||||
|
||||
err = s.redis.DeleteApplication(ctx, tokenIdList, permissionDeleteList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis delete application")
|
||||
}
|
||||
|
||||
count = deletedApp
|
||||
return nil
|
||||
})
|
||||
|
||||
+2
-26
@@ -45,13 +45,7 @@ type ITokenTxRunner interface {
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx ITokenRevokeTx) error) error
|
||||
}
|
||||
|
||||
type ITokenRedis interface {
|
||||
SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error
|
||||
DeleteToken(ctx context.Context, tokens []string) error
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
redisRep ITokenRedis
|
||||
defaultExpireTime int
|
||||
jwt ITokenJwt
|
||||
appEnrich ITokenAppEnrich
|
||||
@@ -63,7 +57,6 @@ type Token struct {
|
||||
}
|
||||
|
||||
func NewToken(
|
||||
redisRep ITokenRedis,
|
||||
defaultExpireTime int,
|
||||
jwtGenerate ITokenJwt,
|
||||
appEnrich ITokenAppEnrich,
|
||||
@@ -74,7 +67,6 @@ func NewToken(
|
||||
tokenRep ITokenTokenRep,
|
||||
) Token {
|
||||
return Token{
|
||||
redisRep: redisRep,
|
||||
defaultExpireTime: defaultExpireTime,
|
||||
appEnrich: appEnrich,
|
||||
jwt: jwtGenerate,
|
||||
@@ -111,7 +103,7 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
return nil, errors.WithMessagef(err, "get service by id")
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
_, err = s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get domain by id")
|
||||
}
|
||||
@@ -127,22 +119,11 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
}
|
||||
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx ITokenCreateTx) error {
|
||||
tokenEntity, err := tx.SaveToken(ctx, token, req.AppId, expTime)
|
||||
_, err = tx.SaveToken(ctx, token, req.AppId, expTime)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx save token")
|
||||
}
|
||||
|
||||
err = s.redisRep.SetApplicationToken(ctx, entity.RedisSetToken{
|
||||
Token: tokenEntity.Token,
|
||||
ExpireTime: tokenEntity.ExpireTime,
|
||||
DomainIdentity: domainEntity.Id,
|
||||
ServiceIdentity: serviceEntity.Id,
|
||||
ApplicationIdentity: applicationEntity.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis set token")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -202,11 +183,6 @@ func (s Token) revokeTokens(ctx context.Context, tokens []string) (*domain.Delet
|
||||
return errors.WithMessagef(err, "tx delete token")
|
||||
}
|
||||
|
||||
err = s.redisRep.DeleteToken(ctx, tokens)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis delete token")
|
||||
}
|
||||
|
||||
count = deleted
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -45,20 +45,14 @@ func (m Manager) AccessListSetListTx(ctx context.Context, msgTx func(ctx context
|
||||
}
|
||||
|
||||
type applicationDeleteTx struct {
|
||||
repository.AccessList
|
||||
repository.Application
|
||||
repository.Token
|
||||
}
|
||||
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IApplicationDeleteTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
accessListRep := repository.NewAccessList(tx)
|
||||
applicationRep := repository.NewApplication(tx)
|
||||
tokenRep := repository.NewToken(tx)
|
||||
return msgTx(ctx, applicationDeleteTx{
|
||||
AccessList: accessListRep,
|
||||
Application: applicationRep,
|
||||
Token: tokenRep,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user