diff --git a/authmdl/sessionmdl/session.go b/authmdl/sessionmdl/session.go index 87523ed2b8975e229a81f500c21a5175bcc8b3aa..10bfc22fa525274b9ccbdaded87c32d55e405cb8 100644 --- a/authmdl/sessionmdl/session.go +++ b/authmdl/sessionmdl/session.go @@ -11,9 +11,6 @@ package sessionmdl import ( "errors" - "time" - - "coresls/servers/coresls/app/models" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/cachemdl" ) @@ -33,25 +30,6 @@ var ( ErrSessionValidationFailed = errors.New("session validation failed") ) -// InitUserSessionCache initializes the cache with provided configuration. Need to provide a cache type to use. -func InitUserSessionCache(chacheType int) { - cacheConfig := cachemdl.CacheConfig{ - Type: chacheType, - RedisCache: &cachemdl.RedisCache{ - Addr: "", // empty takes default redis address 6379 - DB: models.RedisDBSessionManager, - Prefix: models.ProjectID, - }, - FastCache: &cachemdl.FastCacheHelper{ - CleanupTime: 60 * time.Minute, - MaxEntries: 1000, - Expiration: -1, - }, - } - - store = cachemdl.GetCacheInstance(&cacheConfig) -} - // Init initializes sessions with provided cache. Subsequent calls will not have any effect after first initialization. func Init(cache cachemdl.Cacher) { if store != nil { diff --git a/cachemdl/cache.go b/cachemdl/cache.go index fff9c6acee17530ccd1a49611dd54ed6acdc6092..e28b970afebca584ff947ed18f899729179ab298 100644 --- a/cachemdl/cache.go +++ b/cachemdl/cache.go @@ -1,7 +1,6 @@ package cachemdl import ( - "errors" "time" ) @@ -12,11 +11,6 @@ const ( TypeRedisCache ) -var ( - // ErrInvalidCacheType indicates provided cache type is not supported - ErrInvalidCacheType = errors.New("invalid cache type provided") -) - // Cacher provides access to underlying cache, make sure all caches implement these methods. // // The return types of data can be different. Ex. In case of redis cache it is `string`. The caller needs to handle this with the help of Type() method. @@ -42,26 +36,3 @@ type Cacher interface { Type() int } - -// GetCacheInstance returns a cache instance, panics if invalid cache type is provided -func GetCacheInstance(cfg *CacheConfig) Cacher { - switch cfg.Type { - case TypeFastCache: - cfg.FastCache.Setup(cfg.FastCache.MaxEntries, cfg.FastCache.Expiration, cfg.FastCache.CleanupTime) - return cfg.FastCache - - case TypeRedisCache: - cfg.RedisCache.Setup(cfg.RedisCache.Addr, cfg.RedisCache.Password, cfg.RedisCache.Prefix, cfg.RedisCache.DB, cfg.RedisCache.Expiration) - return cfg.RedisCache - - default: - panic(ErrInvalidCacheType) - } -} - -// CacheConfig - -type CacheConfig struct { - Type int - FastCache *FastCacheHelper - RedisCache *RedisCache -} diff --git a/dalmdl/dalmdl.go b/dalmdl/dalmdl.go index 0b8917a5d3c46ac78f8529164146177640baac1e..a1416c0b0d73e556c8817ceeecb6d22bb37b51a8 100755 --- a/dalmdl/dalmdl.go +++ b/dalmdl/dalmdl.go @@ -1 +1,9 @@ package dalmdl + +const ( + MONGODB = "MONGO" + MYSQL = "MYSQL" + FDB = "FDB" + SQLSERVER = "SQLSERVER" + GraphDB = "GRAPHDB" +) diff --git a/routebuildermdl/routebuilder_fasthttp.go b/routebuildermdl/routebuilder_fasthttp.go index e7032ea7731b5b4f360e0c7a59b09f871633d73a..ad111f33af8e5d40f92ebb5bc308a9ad3275a48d 100644 --- a/routebuildermdl/routebuilder_fasthttp.go +++ b/routebuildermdl/routebuilder_fasthttp.go @@ -4,21 +4,19 @@ package routebuildermdl import ( "context" - "coresls/servers/coresls/app/modules/constantmdl" "strings" - "github.com/pquerna/ffjson/ffjson" - - routing "github.com/qiangxue/fasthttp-routing" - - "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/statemdl" - "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/jwtmdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/roleenforcemdl" + "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/dalmdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/servicebuildermdl" + "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/statemdl" + version "github.com/hashicorp/go-version" + "github.com/pquerna/ffjson/ffjson" + routing "github.com/qiangxue/fasthttp-routing" "github.com/tidwall/gjson" ) @@ -72,7 +70,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv var err error // database transaction rollback if transaction is enabled switch ab.DatabaseType { - case constantmdl.MYSQL: + case dalmdl.MYSQL: if ab.TXN != nil { loggermdl.LogError("MYSQL Transaction Rollbacked") err = ab.TXN.Rollback() @@ -82,7 +80,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv } } - case constantmdl.SQLSERVER: + case dalmdl.SQLSERVER: if ab.SQLServerTXN != nil { loggermdl.LogError("SQLSERVER Transaction Rollbacked") err = ab.SQLServerTXN.Rollback() @@ -92,7 +90,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv } } - case constantmdl.GraphDB: + case dalmdl.GraphDB: if ab.GraphDbTXN != nil { loggermdl.LogError("GRAPHDB Transaction Rollbacked") err = ab.GraphDbTXN.Discard(context.TODO()) @@ -116,7 +114,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv var err error switch ab.DatabaseType { - case constantmdl.MYSQL: + case dalmdl.MYSQL: if ab.TXN != nil { loggermdl.LogError("MYSQL Transaction Commit") err = ab.TXN.Commit() @@ -129,7 +127,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv } } - case constantmdl.SQLSERVER: + case dalmdl.SQLSERVER: if ab.SQLServerTXN != nil { loggermdl.LogError("SQLSERVER Transaction Commit") err = ab.SQLServerTXN.Commit() @@ -142,7 +140,7 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv } } - case constantmdl.GraphDB: + case dalmdl.GraphDB: if ab.SQLServerTXN != nil { loggermdl.LogError("GRAPHDB Transaction Commit") err = ab.GraphDbTXN.Commit(context.TODO()) diff --git a/routebuildermdl/routebuilder_gin.go b/routebuildermdl/routebuilder_gin.go index 693230e03bff197a228db581ca3271aa85080658..edc1877220fc8283a1037cdeaf8502bb9e07b922 100644 --- a/routebuildermdl/routebuilder_gin.go +++ b/routebuildermdl/routebuilder_gin.go @@ -4,19 +4,18 @@ package routebuildermdl import ( "context" - "coresls/servers/coresls/app/modules/constantmdl" "io/ioutil" "net/http" "strings" - "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/roleenforcemdl" - - "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/statemdl" - "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/jwtmdl" + "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/authmdl/roleenforcemdl" + "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/dalmdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/servicebuildermdl" + "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/statemdl" + "github.com/gin-gonic/gin" version "github.com/hashicorp/go-version" "github.com/tidwall/gjson" @@ -81,7 +80,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity var err error // database transaction rollback if transaction is enabled switch ab.DatabaseType { - case constantmdl.MYSQL: + case dalmdl.MYSQL: if ab.TXN != nil { loggermdl.LogError("MYSQL Transaction Rollbacked") err = ab.TXN.Rollback() @@ -91,7 +90,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity } } - case constantmdl.SQLSERVER: + case dalmdl.SQLSERVER: if ab.SQLServerTXN != nil { loggermdl.LogError("SQLSERVER Transaction Rollbacked") err = ab.SQLServerTXN.Rollback() @@ -101,7 +100,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity } } - case constantmdl.GraphDB: + case dalmdl.GraphDB: if ab.GraphDbTXN != nil { loggermdl.LogError("GRAPHDB Transaction Rollbacked") err = ab.GraphDbTXN.Discard(context.TODO()) @@ -125,7 +124,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity var err error switch ab.DatabaseType { - case constantmdl.MYSQL: + case dalmdl.MYSQL: if ab.TXN != nil { loggermdl.LogError("MYSQL Transaction Commit") err = ab.TXN.Commit() @@ -138,7 +137,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity } } - case constantmdl.SQLSERVER: + case dalmdl.SQLSERVER: if ab.SQLServerTXN != nil { loggermdl.LogError("SQLSERVER Transaction Commit") err = ab.SQLServerTXN.Commit() @@ -151,7 +150,7 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity } } - case constantmdl.GraphDB: + case dalmdl.GraphDB: if ab.SQLServerTXN != nil { loggermdl.LogError("GRAPHDB Transaction Commit") err = ab.GraphDbTXN.Commit(context.TODO()) diff --git a/sessionmanagermdl/sessionmanager.go b/sessionmanagermdl/sessionmanager.go index 937bb98783de4d47871059d4c8aad78ba4bb4f01..2a642d3d0f4b771f6cc4a0ef39fb87a0d789b088 100644 --- a/sessionmanagermdl/sessionmanager.go +++ b/sessionmanagermdl/sessionmanager.go @@ -1,7 +1,6 @@ package sessionmanagermdl import ( - "coresls/servers/coresls/app/models" "errors" "time" @@ -30,25 +29,6 @@ var store cachemdl.Cacher var ErrSessionNotFound = errors.New("SESSION_NOT_FOUND") var ErrInvalidDataType = errors.New("INVALID_DATA_Type") -// InitSessionManagerCache initializes the cache with provided configuration. Need to provide a cache type to use. -func InitSessionManagerCache(chacheType int) { - cacheConfig := cachemdl.CacheConfig{ - Type: chacheType, - RedisCache: &cachemdl.RedisCache{ - Addr: "", // empty takes default redis address 6379 - DB: models.RedisDBSessionManager, - Prefix: models.ProjectID, - }, - FastCache: &cachemdl.FastCacheHelper{ - CleanupTime: 60 * time.Minute, - MaxEntries: 1000, - Expiration: -1, - }, - } - - store = cachemdl.GetCacheInstance(&cacheConfig) -} - // Init initializes session manager with provided cache. Subsequent calls will not have any effect after first initialization. func Init(cache cachemdl.Cacher) { if store != nil {