2020-12-29 23:02:35 +01:00
|
|
|
// Copyright (c) Mainflux
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mainflux/mainflux/auth"
|
2022-03-03 17:13:46 +01:00
|
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
2020-12-29 23:02:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type identityReq struct {
|
|
|
|
token string
|
|
|
|
kind uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req identityReq) validate() error {
|
|
|
|
if req.token == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrBearerToken
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
2021-12-24 14:53:06 +01:00
|
|
|
if req.kind != auth.LoginKey &&
|
2020-12-29 23:02:35 +01:00
|
|
|
req.kind != auth.APIKey &&
|
|
|
|
req.kind != auth.RecoveryKey {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrInvalidAuthKey
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type issueReq struct {
|
|
|
|
id string
|
|
|
|
email string
|
|
|
|
keyType uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req issueReq) validate() error {
|
|
|
|
if req.email == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingEmail
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
2021-12-24 14:53:06 +01:00
|
|
|
if req.keyType != auth.LoginKey &&
|
2020-12-29 23:02:35 +01:00
|
|
|
req.keyType != auth.APIKey &&
|
|
|
|
req.keyType != auth.RecoveryKey {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrInvalidAuthKey
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type assignReq struct {
|
2021-03-04 10:29:03 +01:00
|
|
|
token string
|
|
|
|
groupID string
|
|
|
|
memberID string
|
|
|
|
groupType string
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req assignReq) validate() error {
|
|
|
|
if req.token == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrBearerToken
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
if req.groupID == "" || req.memberID == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingID
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type membersReq struct {
|
2021-03-04 10:29:03 +01:00
|
|
|
token string
|
|
|
|
groupID string
|
|
|
|
offset uint64
|
|
|
|
limit uint64
|
|
|
|
memberType string
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req membersReq) validate() error {
|
|
|
|
if req.token == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrBearerToken
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
if req.groupID == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingID
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
2021-03-04 10:29:03 +01:00
|
|
|
if req.memberType == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingMemberType
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// authReq represents authorization request. It contains:
|
|
|
|
// 1. subject - an action invoker
|
|
|
|
// 2. object - an entity over which action will be executed
|
|
|
|
// 3. action - type of action that will be executed (read/write)
|
|
|
|
type authReq struct {
|
2021-10-27 00:38:28 +02:00
|
|
|
Sub string
|
|
|
|
Obj string
|
|
|
|
Act string
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req authReq) validate() error {
|
|
|
|
if req.Sub == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingPolicySub
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if req.Obj == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingPolicyObj
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if req.Act == "" {
|
2022-03-03 17:13:46 +01:00
|
|
|
return apiutil.ErrMissingPolicyAct
|
2020-12-29 23:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-27 00:38:28 +02:00
|
|
|
|
2022-03-03 17:13:46 +01:00
|
|
|
type policyReq struct {
|
2021-10-27 00:38:28 +02:00
|
|
|
Sub string
|
|
|
|
Obj string
|
|
|
|
Act string
|
|
|
|
}
|
|
|
|
|
2022-03-03 17:13:46 +01:00
|
|
|
func (req policyReq) validate() error {
|
|
|
|
if req.Sub == "" {
|
|
|
|
return apiutil.ErrMissingPolicySub
|
2021-10-27 00:38:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-03 17:13:46 +01:00
|
|
|
if req.Obj == "" {
|
|
|
|
return apiutil.ErrMissingPolicyObj
|
|
|
|
}
|
2021-10-27 00:38:28 +02:00
|
|
|
|
2022-03-03 17:13:46 +01:00
|
|
|
if req.Act == "" {
|
|
|
|
return apiutil.ErrMissingPolicyAct
|
2021-10-27 00:38:28 +02:00
|
|
|
}
|
2022-03-03 17:13:46 +01:00
|
|
|
|
2021-10-27 00:38:28 +02:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-19 16:32:38 +03:00
|
|
|
|
|
|
|
type listPoliciesReq struct {
|
|
|
|
Sub string
|
|
|
|
Obj string
|
|
|
|
Act string
|
|
|
|
}
|