Commit 98711636 authored by Roshan Patil's avatar Roshan Patil
Browse files

Global Config + Casbin Roleenforcer for SLS

parent dcdf98e1
Branches
Tags
1 merge request!61Global Config + Casbin Roleenforcer for SLS
Showing with 64 additions and 0 deletions
......@@ -59,6 +59,21 @@ func LoadRoleConfiguration(csvFilePath string) {
})
}
// RegisterUser - RegisterUser register use
func RegisterUser(group, URL string, isAllowed bool) {
roleObject, ok := roleManagementConfig[URL]
if ok {
roleObject = assignURL(group, isAllowed, roleObject)
} else {
roleObject = URLGroupMapping{
Allowed: make(map[string]bool),
NotAllowed: make(map[string]bool),
}
roleObject = assignURL(group, isAllowed, roleObject)
}
roleManagementConfig[URL] = roleObject
}
func registerUser(group, URL string, isAllowed bool) {
roleObject, ok := roleManagementConfig[URL]
if ok {
......
......@@ -61,3 +61,5 @@ const (
const MIME = "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
const COUNTRYCODE = "91"
const MQLRequestData = "MQLRequestData"
......@@ -9,6 +9,8 @@ import (
"sync"
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/constantmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/validationmdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
......@@ -18,11 +20,15 @@ import (
"github.com/tidwall/gjson"
)
var globalConfig map[string]string
var once sync.Once
var ruleCache map[string]conditions.Expr
var mutex = &sync.Mutex{}
func init() {
ruleCache = make(map[string]conditions.Expr)
globalConfig = make(map[string]string)
}
// LoadData is a method sign for loader methods
......@@ -35,6 +41,16 @@ type FinalStepProcessOutput = func(ab *AbstractBusinessLogicHolder) (*interface{
type AbstractBusinessLogicHolder struct {
localServiceData map[string]interface{}
pricipalObject Principal
globalConfigData map[string]string
}
// SetGlobalConfig - SetGlobalConfig
func SetGlobalConfig(configs map[string]string) {
once.Do(func() {
if configs != nil {
globalConfig = configs
}
})
}
// GetDataString will give you string
......@@ -94,6 +110,22 @@ func (ab *AbstractBusinessLogicHolder) GetDataResultset(key string) (*gjson.Resu
return value, true
}
func (ab *AbstractBusinessLogicHolder) GetMQLRequestData() (*gjson.Result, bool) {
//check in map
temp, found := ab.localServiceData[constantmdl.MQLRequestData]
if errormdl.CheckBool(!found) {
loggermdl.LogWarn("MQL Request Data not Found")
return &gjson.Result{}, false
}
// cast it
value, ok := temp.(*gjson.Result)
if errormdl.CheckBool1(!ok) {
return &gjson.Result{}, false
}
return value, true
}
// GetDataBool will give you int
func (ab *AbstractBusinessLogicHolder) GetDataBool(key string) (bool, bool) {
//check in map
......@@ -120,9 +152,19 @@ func (ab *AbstractBusinessLogicHolder) GetCustomData(key string) (interface{}, b
return temp, true
}
// GetGlobalConfigString - return string value for global config key
func (ab *AbstractBusinessLogicHolder) GetGlobalConfigString(key string) (string, bool) {
value, found := ab.globalConfigData[key]
if errormdl.CheckBool(!found) {
return "", false
}
return value, true
}
// New will create memory for your data
func (ab *AbstractBusinessLogicHolder) New(principalObject *Principal) *AbstractBusinessLogicHolder {
ab.localServiceData = make(map[string]interface{})
ab.globalConfigData = globalConfig
ab.pricipalObject = *principalObject
return ab
}
......@@ -132,6 +174,11 @@ func (ab *AbstractBusinessLogicHolder) SetResultset(key string, obj *gjson.Resul
ab.localServiceData[key] = obj
}
// SetMQLRequestData - set value
func (ab *AbstractBusinessLogicHolder) SetMQLRequestData(obj *gjson.Result) {
ab.localServiceData[constantmdl.MQLRequestData] = obj
}
// SetByteData will set byte data as gjson.Result
func (ab *AbstractBusinessLogicHolder) SetByteData(key string, obj []byte) {
rs := gjson.ParseBytes(obj)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment