
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
github.com/happay/cms-utils-go/v3
This repository contains a collection of utility functions for Go (Golang) development. The utility functions provided in this package are designed to simplify common tasks and enhance the development process. It includes features such as accessing a Redis cluster client with authentication and various other helpful utilities.
go get github.com/happay/cms-utils-go/{version}@{tag}
go mod tidy
Please make sure we update the exiting import
import github.com/happay/cms-utils-go
with major version 2 in order to use redis-cluster client with auth mode and various other helpful utilities.
import github.com/happay/cms-utils-go/v2
Note: Since the latest version 2 support upgreded version of redis v9, to support this following changes will be required in exiting code:
go get github.com/redis/go-redis/v9
Then
func SetRedisKey(key string, data string, exp time.Duration) error {
return redisClient.Set(redisClient.Context(), key, data, exp).Err()
}
Now
func (r *RedisClient) SetRedisKey(ctx context.Context, key, data string, exp time.Duration) error {
return r.Set(ctx, key, data, exp).Err()
}
package main
import (
"context"
"fmt"
"time"
"github.com/happay/cms-utils-go/v2/connector"
"github.com/redis/go-redis/v9"
)
func main() {
// Initialize a Redis client using the utility provided in this package
ctx := context.Background()
redisClient := connector.GetRedisConnectionWithAuth(ctx)
// Set a Redis key with data and expiration time
key := "myKey"
data := "myData"
expiration := 10 * time.Second
err := redisClient.SetRedisKey(ctx, key, data, expiration)
if err != nil {
fmt.Println("Failed to set Redis key:", err)
} else {
fmt.Println("Redis key set successfully.")
}
}
To enable tracing we need to follow the below step or given piece of code.
Configure the datadog config, where will define the below varibales,
package main
import (
"os"
"../api"
"../common"
"../constant"
"github.com/happay/cms-utils-go/v2/tracing"
)
func main() {
ddConfig := &tracing.DataDogTracerConfig{
ServiceName: constant.APP_NAME,
Env: os.Getenv("APP_ENV"),
Host: os.Getenv("DD_AGENT_HOST"),
Port: os.Getenv("DD_DOGSTATSD_PORT"),
}
ddProvider := tracing.DataDogProvider{
TracerConfig: ddConfig,
}
ddProvider.NewTracerProvider()
defer func() {
if err := ddProvider.TracerProvider.Shutdown(); err != nil {
common.GetLogger().Error("Error shutting down tracer provider: ", err)
}
}()
ddProvider.InitTracing()
api.StartServices()
}
In above pieace of code, first we define the DataDogTracerConfig, to initialise the datadog agent. InitTracing will set the tracer provider as global tracer and set the propogator which will help us to allow the distributed tracing (cross-cutting concern).
Once we set the tracer, we can start with incoming requirest tracing. Adding TracingMiddleware
as middleware to instrumented service we can trace the incoming requests.
package main
import (
"github.com/gin-gonic/gin"
utilsMiddleware "github.com/happay/cms-utils-go/v2/middleware"
)
func main(){
r := gin.Default()
r.Use(utilsMiddleware.TracingMiddleware("my-service-name"))
r.Run()
}
To create a span with global tracer provider
import (
"github.com/happay/cms-utils-go/v2/tracing"
)
func HttpCall(ctx context.Context) {
_, span := tracing.StartSpanWithGlobalTracer(ctx, "HttpCall")
// Do something
}
To create a span with expicilty pass the tracer provider
import (
"github.com/happay/cms-utils-go/v2/tracing"
...
)
var DDProvider tracing.DataDogProvider
func init() {
ddConfig := &tracing.DataDogTracerConfig{
ServiceName: AppName,
Env: os.Getenv("APP_ENV"),
Version: "v1",
Host: os.Getenv("DD_AGENT_HOST"),
Port: os.Getenv("DD_DOGSTATSD_PORT"),
}
DDProvider = tracing.DataDogProvider{
TracerConfig: ddConfig,
}
}
func main() {
DDProvider.NewTracerProvider()
defer func() {
if err := DDProvider.TracerProvider.Shutdown(); err != nil {
common.Errorf("Error shutting down tracer provider: %v", err)
}
common.Infof("tracer provider shutting down gracefully")
}()
DDProvider.InitTracing()
// Start your service
}
func HttpCall(ctx context.Context) {
_, span := DDProvider.StartSpan(ctx, "HttpCall")
// Do something
}
In above code, on init function we set the ddprovider value and in main function the value get set as tracer provider, which we can use as global variable.
To connect with mysql connection
type Mysql struct {
Host string `json:"host"`
Port string `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
MaxOpenConnections string `json:"maxOpenConnections"`
MaxIdleConnections string `json:"maxIdleConnections"`
}
use above Mysql map to pass mysqlConfig
db = connector.GetMySqlConn(mysqlConfig, "mysql")
Function MakeHttpRequest
provides the http call to network, which take http path, http method and HttpOption
optional parmaters.
func WithQueryParam(queryParams map[string]string) HttpOption
This will take all the Query params in map[string]string
func WithRequestBody(requestBody PropertyMap) HttpOption
This will set request body to http request
func WithHeader(header map[string]string) HttpOption
This will set header to http request, if http request accept the headers
func WithTimeoutInSec(timeout int64) HttpOption
Sets the timeout if required.
insecureSkipVerify = true
func WithCertificate(publicKey, privateKey, caCert []byte, insecureSkipVerify bool) HttpOption
NOTE: PropertyMap is type PropertyMap map[string]interface{}
e.g.
response, err := util.MakeHttpRequest(
http.MethodPost,
path,
util.WithHeader(reqData.Headers),
util.WithRequestBody(util.PropertyMap(reqData.RequestBody),util.WithCertificate(serverSslCert, serverSslKey, ntsPublicKey, true)),
)
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.