mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-04 22:17:59 +08:00

* MF-1443 - add policies Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * fix users create Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Add Policies for sharing a Thing (#1463) * MF-1454 - Add policies for sharing a Thing Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Add a test case for sharing thing and update mock of AddPolicy Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update ShareThing parameter naming Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Policy Removal (#1466) * Add DeletePolicy gRPC endpoint in auth package Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update default admin creation Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Add policy addition endpoint (#1479) * NOISSUE - Add policy addition endpoint Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update name of the method Signed-off-by: Burak Sekili <buraksekili@gmail.com> remove build tag Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Add tests for AddPolicies (#1480) * NOISSUE - Add tests for adding policy and update authz check Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Add more tests and update request body validation Signed-off-by: Burak Sekili <buraksekili@gmail.com> * Update test case structure and utilize mock prefix for test ids Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * MF-1454 - Add initial policies for Group access control (#1467) Signed-off-by: Burak Sekili <buraksekili@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Resolve PR comments Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Co-authored-by: Author: Burak Sekili <buraksekili@gmail.com>
180 lines
3.3 KiB
Go
180 lines
3.3 KiB
Go
package groups
|
|
|
|
import (
|
|
"github.com/mainflux/mainflux/auth"
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
)
|
|
|
|
type createGroupReq struct {
|
|
token string
|
|
Name string `json:"name,omitempty"`
|
|
ParentID string `json:"parent_id,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req createGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
if len(req.Name) > maxNameSize || req.Name == "" {
|
|
return errors.Wrap(auth.ErrMalformedEntity, auth.ErrBadGroupName)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateGroupReq struct {
|
|
token string
|
|
id string
|
|
Name string `json:"name,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listGroupsReq struct {
|
|
token string
|
|
id string
|
|
level uint64
|
|
// - `true` - result is JSON tree representing groups hierarchy,
|
|
// - `false` - result is JSON array of groups.
|
|
tree bool
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listGroupsReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.level > auth.MaxLevel || req.level < auth.MinLevel {
|
|
return auth.ErrMaxLevelExceeded
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listMembersReq struct {
|
|
token string
|
|
id string
|
|
groupType string
|
|
offset uint64
|
|
limit uint64
|
|
tree bool
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listMembersReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listMembershipsReq struct {
|
|
token string
|
|
id string
|
|
offset uint64
|
|
limit uint64
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listMembershipsReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type assignReq struct {
|
|
token string
|
|
groupID string
|
|
Type string `json:"type,omitempty"`
|
|
Members []string `json:"members"`
|
|
}
|
|
|
|
func (req assignReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.Type == "" || req.groupID == "" || len(req.Members) == 0 {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type shareGroupAccessReq struct {
|
|
token string
|
|
userGroupID string
|
|
ThingGroupID string `json:"thing_group_id"`
|
|
}
|
|
|
|
func (req shareGroupAccessReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.ThingGroupID == "" || req.userGroupID == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type unassignReq struct {
|
|
assignReq
|
|
}
|
|
|
|
func (req unassignReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.groupID == "" || len(req.Members) == 0 {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type groupReq struct {
|
|
token string
|
|
id string
|
|
}
|
|
|
|
func (req groupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|