mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-11 00:09:37 +00:00
3aa83d4480
* chore(security,refactor): extract sanitization and improve code quality
- [x] Extract sanitization functions to dedicated sanitization.go module
- [x] Add comprehensive golangci-lint v2 configuration with security rules
- [x] Replace interface{} with any type throughout codebase
- [x] Add admin API authentication security warning
- [x] Extract WebSocket and stats streaming constants
- [x] Add best-effort error handling comments for resource cleanup
- [x] Expand sensitive field patterns for improved PII redaction
- [x] Simplify safety checks and remove redundant nil validations
- [x] Improve test coverage for password field redaction patterns
* refactor: replace interface{} with any type alias
- [x] Replace all `map[string]interface{}` with `map[string]any`
- [x] Replace all `interface{}` with `any` in function signatures and type definitions
- [x] Update sync.Pool New function returns from `interface{}` to `any`
- [x] Add package documentation comments to 8 package files
- [x] Update type assertions and casts to work with `any` type
105 lines
2.3 KiB
Go
105 lines
2.3 KiB
Go
package libpack_cache_redis
|
|
|
|
import (
|
|
"time"
|
|
|
|
libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging"
|
|
)
|
|
|
|
// CacheWrapper wraps RedisConfig to implement the CacheClient interface
|
|
// without returning errors, for backward compatibility
|
|
type CacheWrapper struct {
|
|
redis *RedisConfig
|
|
logger *libpack_logger.Logger
|
|
}
|
|
|
|
// NewCacheWrapper creates a new cache wrapper
|
|
func NewCacheWrapper(config *RedisConfig, logger *libpack_logger.Logger) *CacheWrapper {
|
|
if logger == nil {
|
|
logger = &libpack_logger.Logger{}
|
|
}
|
|
return &CacheWrapper{
|
|
redis: config,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
// Set stores a value with the given TTL
|
|
func (w *CacheWrapper) Set(key string, value []byte, ttl time.Duration) {
|
|
if err := w.redis.Set(key, value, ttl); err != nil {
|
|
w.logger.Error(&libpack_logger.LogMessage{
|
|
Message: "Redis set error",
|
|
Pairs: map[string]any{
|
|
"error": err.Error(),
|
|
"key": key,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// Get retrieves a value
|
|
func (w *CacheWrapper) Get(key string) ([]byte, bool) {
|
|
value, found, err := w.redis.Get(key)
|
|
if err != nil {
|
|
w.logger.Error(&libpack_logger.LogMessage{
|
|
Message: "Redis get error",
|
|
Pairs: map[string]any{
|
|
"error": err.Error(),
|
|
"key": key,
|
|
},
|
|
})
|
|
return nil, false
|
|
}
|
|
return value, found
|
|
}
|
|
|
|
// Delete removes a key
|
|
func (w *CacheWrapper) Delete(key string) {
|
|
if err := w.redis.Delete(key); err != nil {
|
|
w.logger.Error(&libpack_logger.LogMessage{
|
|
Message: "Redis delete error",
|
|
Pairs: map[string]any{
|
|
"error": err.Error(),
|
|
"key": key,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// Clear removes all keys
|
|
func (w *CacheWrapper) Clear() {
|
|
if err := w.redis.Clear(); err != nil {
|
|
w.logger.Error(&libpack_logger.LogMessage{
|
|
Message: "Redis clear error",
|
|
Pairs: map[string]any{
|
|
"error": err.Error(),
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// CountQueries returns the number of queries
|
|
func (w *CacheWrapper) CountQueries() int64 {
|
|
count, err := w.redis.CountQueries()
|
|
if err != nil {
|
|
w.logger.Error(&libpack_logger.LogMessage{
|
|
Message: "Redis count queries error",
|
|
Pairs: map[string]any{
|
|
"error": err.Error(),
|
|
},
|
|
})
|
|
return 0
|
|
}
|
|
return count
|
|
}
|
|
|
|
// GetMemoryUsage returns 0 for Redis (not applicable)
|
|
func (w *CacheWrapper) GetMemoryUsage() int64 {
|
|
return 0
|
|
}
|
|
|
|
// GetMaxMemorySize returns 0 for Redis (not applicable)
|
|
func (w *CacheWrapper) GetMaxMemorySize() int64 {
|
|
return 0
|
|
}
|