1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-08 19:29:17 +08:00
Burak Sekili 3042d6b40b
MF-1489 - Add API for deleting policies (#1491)
* MF-1489 - Add API for deleting policies

Signed-off-by: Burak Sekili <buraksekili@gmail.com>

* update request and decoder naming

Signed-off-by: Burak Sekili <buraksekili@gmail.com>

* update swagger doc summary for the endpoint

Signed-off-by: Burak Sekili <buraksekili@gmail.com>

Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2021-11-08 14:45:38 +01:00

60 lines
1.0 KiB
Go

package policies
import (
"github.com/mainflux/mainflux/auth"
"github.com/mainflux/mainflux/things"
)
// Action represents an enum for the policies used in the Mainflux.
type Action int
const (
Create Action = iota
Read
Write
Delete
Access
Member
Unknown
)
var actions = map[string]Action{
"create": Create,
"read": Read,
"write": Write,
"delete": Delete,
"access": Access,
"member": Member,
}
type policiesReq struct {
token string
SubjectIDs []string `json:"subjects"`
Policies []string `json:"policies"`
Object string `json:"object"`
}
func (req policiesReq) validate() error {
if req.token == "" {
return auth.ErrUnauthorizedAccess
}
if len(req.SubjectIDs) == 0 || len(req.Policies) == 0 || req.Object == "" {
return auth.ErrMalformedEntity
}
for _, policy := range req.Policies {
if _, ok := actions[policy]; !ok {
return auth.ErrMalformedEntity
}
}
for _, subject := range req.SubjectIDs {
if subject == "" {
return things.ErrMalformedEntity
}
}
return nil
}