fix config reload and error response
This commit is contained in:
1 parent
cc5da31e59
commit
df31719324
7 files changed
+27
-14
No files matched your search
@@ -1,3 +1,6 @@
|
||||
## 2.5.1
|
||||
* fix code response when doesn't match user id
|
||||
* fix config reload
|
||||
## 2.5.0
|
||||
* add skip for check exist method
|
||||
* add handler for user methods
|
||||
|
||||
@@ -98,10 +98,16 @@ func Do(ctx *fasthttp.RequestCtx, path string) (int32, error) {
|
||||
}
|
||||
|
||||
permittedToCall := false
|
||||
verifiableKeys, permittedToCall, err = auth.verify.Identity(verifiableKeys, path)
|
||||
validUserId := true
|
||||
verifiableKeys, permittedToCall, validUserId, err = auth.verify.Identity(verifiableKeys, path)
|
||||
if err != nil {
|
||||
log.Error(log_code.ErrorAuthenticate, err)
|
||||
return 0, createError("internal Server error", codes.Internal)
|
||||
return 0, createError("internal server error", codes.Internal)
|
||||
}
|
||||
if !validUserId {
|
||||
msg := "doesn't match user id"
|
||||
log.Error(log_code.ErrorAuthenticate, msg)
|
||||
return 0, createError(msg, codes.PermissionDenied)
|
||||
}
|
||||
if permittedToCall {
|
||||
return 0, createError("forbidden", codes.PermissionDenied)
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/integration-system/go-cmp/cmp"
|
||||
"github.com/integration-system/isp-lib/bootstrap"
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"github.com/integration-system/isp-lib/config/schema"
|
||||
@@ -70,7 +71,9 @@ func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) {
|
||||
metric.InitHttpServer(remoteConfig.Metrics)
|
||||
service.Metrics.Init()
|
||||
|
||||
server.Http.Init(remoteConfig.HttpSetting.GetMaxRequestBodySize())
|
||||
if !cmp.Equal(remoteConfig.HttpSetting, oldRemoteConfig.HttpSetting) {
|
||||
server.Http.Init(remoteConfig.HttpSetting.GetMaxRequestBodySize())
|
||||
}
|
||||
}
|
||||
|
||||
func socketConfiguration(cfg interface{}) structure.SocketConfiguration {
|
||||
|
||||
@@ -47,6 +47,6 @@ func (cv *cacheableVerify) ApplicationToken(token string) (map[string]string, er
|
||||
}
|
||||
}
|
||||
|
||||
func (cv *cacheableVerify) Identity(identity map[string]string, uri string) (map[string]string, bool, error) {
|
||||
func (cv *cacheableVerify) Identity(identity map[string]string, uri string) (map[string]string, bool, bool, error) {
|
||||
return cv.rv.Identity(identity, uri)
|
||||
}
|
||||
@@ -53,12 +53,13 @@ func (v *runtimeVerify) ApplicationToken(token string) (map[string]string, error
|
||||
}
|
||||
}
|
||||
|
||||
func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]string, bool, error) {
|
||||
func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]string, bool, bool, error) {
|
||||
secondDbKey := fmt.Sprintf("%s|%s", t[utils.ApplicationIdHeader], uri)
|
||||
thirdDbKey := fmt.Sprintf("%s|%s", t[utils.UserTokenHeader], t[utils.DomainIdHeader])
|
||||
fourthDbKey := fmt.Sprintf("%s|%s", t[utils.UserIdHeader], uri)
|
||||
fifthDbKey := fmt.Sprintf("%s|%s", t[utils.DeviceTokenHeader], t[utils.DomainIdHeader])
|
||||
permittedToCall := false
|
||||
validUserId := true
|
||||
|
||||
if resp, err := rdClient.Client.Get().Pipelined(func(p rd.Pipeliner) error {
|
||||
if _, err := p.Select(int(redis.ApplicationPermissionDb)).Result(); v.notEmptyError(err) {
|
||||
@@ -91,36 +92,36 @@ func (v *runtimeVerify) Identity(t map[string]string, uri string) (map[string]st
|
||||
|
||||
return nil
|
||||
}); v.notEmptyError(err) {
|
||||
return t, false, err
|
||||
return t, false, false, err
|
||||
} else {
|
||||
// ===== NOT PERMITTED BY APPLICATION ID =====
|
||||
if msg, err := v.findStringCmd(resp, 1); err != nil {
|
||||
return t, false, err
|
||||
return t, false, false, err
|
||||
} else if msg == permittedToCallInfo {
|
||||
permittedToCall = true
|
||||
}
|
||||
// ===== CHECK USER TOKEN =====
|
||||
if msg, err := v.findStringCmd(resp, 3); err != nil {
|
||||
return t, false, err
|
||||
return t, false, false, err
|
||||
} else {
|
||||
if msg != t[utils.UserIdHeader] {
|
||||
return t, false, errors.Errorf("doesn't match user id")
|
||||
validUserId = false
|
||||
}
|
||||
}
|
||||
// ===== NOT PERMITTED BY USER ID =====
|
||||
if msg, err := v.findStringCmd(resp, 5); err != nil {
|
||||
return t, false, err
|
||||
return t, false, false, err
|
||||
} else if msg == permittedToCallInfo {
|
||||
permittedToCall = true
|
||||
}
|
||||
// ===== CHECK DEVICE TOKEN =====
|
||||
if msg, err := v.findStringCmd(resp, 7); err != nil {
|
||||
return t, false, err
|
||||
return t, false, false, err
|
||||
} else {
|
||||
t[utils.DeviceIdHeader] = msg
|
||||
}
|
||||
}
|
||||
return t, permittedToCall, nil
|
||||
return t, permittedToCall, validUserId, nil
|
||||
}
|
||||
|
||||
func (v *runtimeVerify) notEmptyError(err error) bool {
|
||||
|
||||
@@ -8,7 +8,7 @@ var Default = NewRuntimeVerify()
|
||||
|
||||
type Verify interface {
|
||||
ApplicationToken(string) (map[string]string, error)
|
||||
Identity(map[string]string, string) (map[string]string, bool, error)
|
||||
Identity(map[string]string, string) (map[string]string, bool, bool, error)
|
||||
}
|
||||
|
||||
func NewRuntimeVerify() Verify {
|
||||
|
||||
Reference in new issue
Block a user