![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
gitlab.com/package-sh/couchdbutils
Package to manage couchbaseDB
go get gitlab.com/package-sh/couchdbutils
EpressRouterController is a function that creates a router for a given entity
The function will create the following routes:
Return all entities with pagination
/baseURL?currentPage=1&pageSize=10&whereQuery=field1==value1|field2<in>value2,value2&orderByQuery=-field1
|
=, !=, <, >, <=, >=, <in>, !<in>
==, !==, <<, <<=, >>=, <<in>>, !<<in>>
,
Return the entities that match the search
Return the entity with the given id
Create a new entity
Update the entity with the given id
Delete the entity with the given id
type UserEntity{
UserId string `json:"user_id"`
SessionId string `json:"user_session_id"`
Name string `json:"user_name"`
LastName string `json:"user_lastname"`
UserName string `json:"user_username"`
Password string `json:"user_password"`
}
We choose to not show the password attribut throw the API
type UserDTO{
UserId string `json:"user_id"`
SessionId string `json:"user_session_id"`
Name string `json:"user_name"`
LastName string `json:"user_lastname"`
UserName string `json:"user_username"`
}
//The cluster couchBase object
var Cluster *gocb.Cluster
cluster, err = gocb.Connect(
clusterIP,
gocb.ClusterOptions{
Username: clusterAdmin,
Password: pwdCluster,
},
)
// the user couchBase object
var userCollection *gocb.Collection
userCollection= Bucket.Scope(scope).Collection("userList"),
This function will This function is called when a user entity is create of update The goal of this function is to set the right information in the entite object
hydateEntites := func(r *http.Request, id string, newUser *entities.UserEntity, isUpdate bool) error {
// Check if the writing is an update or a new document
if !isUpdate {
// if is not update > then is a creation, we set the new id generated to the entity
neUser.UserId = id
}
// ====================== Check Validity of the entity - BEGIN ======================
// Check if the body is empty
if newUser == nil {
// if the body is empty, we return an error > then the entity be not saved
return couchdbUtils.NewError(400, "Body is required")
}
// ====================== Check Validity of the entity - END ======================
// If all is ok, we return nil > then the entity will be saved
return nil
}
This function is called when a Get is requested This function add mandarory where condition
getPreWhereQuery :=func(r *http.Request) []string {
mandatoryWhereConditionList := []string{}
userId := context.Get(r, "user")
userIdFormated := userId.(string)
//Here we want just all users of the session
mandatoryWhereConditionList = append( whereConditionList , "user_session_id = '"+userIdFormated+"'")
return whereConditionList
}
expressRouterConfig := couchdbUtils.RouterConfig[entities.UserEntity, entities.UserDto]{
Cluster: Cluster,
Router: router,
BaseURL: "/users",
// the name of the id attribute of the entity
IdKey: "user_id",
Collection: UserCollection,
AuthMiddleware: nil,
WithMiddleware: false,
HydrateEntities: hydateEntites,
// the method to not expose
BlackListMethod: []string{"PUT", "POST", "DELETE"},
GetPreWhereQueryGet: getPreWhereQuery,
}
couchdbUtils.ExpressRouterController[entities.UserEntity, entities.UserDto](expressRouterConfig)
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.