mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-28 13:48:49 +08:00

* MF-1348 - Add go-kit transport level logging Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix merge Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix remark Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix go test flags Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use httputil errors in things and http service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix SDK tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use httputil errors in certs and provision service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use httputil errors in consumers service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * General renaming and add ErrMissingToken Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename httputil -> apiutil and use errors in users servive Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use apiutil errors in auth, bootstrap, readers, things and twins Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace errors.Contain by comparison Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix remarks Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Simplify validateID Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Simplify validateID Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Simplify and rename ExtractAuthToken -> ExtractBearerToken Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix readers Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix auth key test and remarks Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve comment Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Simplify validateUUID check Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
139 lines
2.3 KiB
Go
139 lines
2.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package grpc
|
|
|
|
import (
|
|
"github.com/mainflux/mainflux/auth"
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
|
)
|
|
|
|
type identityReq struct {
|
|
token string
|
|
kind uint32
|
|
}
|
|
|
|
func (req identityReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
if req.kind != auth.LoginKey &&
|
|
req.kind != auth.APIKey &&
|
|
req.kind != auth.RecoveryKey {
|
|
return apiutil.ErrInvalidAuthKey
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type issueReq struct {
|
|
id string
|
|
email string
|
|
keyType uint32
|
|
}
|
|
|
|
func (req issueReq) validate() error {
|
|
if req.email == "" {
|
|
return apiutil.ErrMissingEmail
|
|
}
|
|
if req.keyType != auth.LoginKey &&
|
|
req.keyType != auth.APIKey &&
|
|
req.keyType != auth.RecoveryKey {
|
|
return apiutil.ErrInvalidAuthKey
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type assignReq struct {
|
|
token string
|
|
groupID string
|
|
memberID string
|
|
groupType string
|
|
}
|
|
|
|
func (req assignReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
if req.groupID == "" || req.memberID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type membersReq struct {
|
|
token string
|
|
groupID string
|
|
offset uint64
|
|
limit uint64
|
|
memberType string
|
|
}
|
|
|
|
func (req membersReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
if req.groupID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
if req.memberType == "" {
|
|
return apiutil.ErrMissingMemberType
|
|
}
|
|
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 {
|
|
Sub string
|
|
Obj string
|
|
Act string
|
|
}
|
|
|
|
func (req authReq) validate() error {
|
|
if req.Sub == "" {
|
|
return apiutil.ErrMissingPolicySub
|
|
}
|
|
|
|
if req.Obj == "" {
|
|
return apiutil.ErrMissingPolicyObj
|
|
}
|
|
|
|
if req.Act == "" {
|
|
return apiutil.ErrMissingPolicyAct
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type policyReq struct {
|
|
Sub string
|
|
Obj string
|
|
Act string
|
|
}
|
|
|
|
func (req policyReq) validate() error {
|
|
if req.Sub == "" {
|
|
return apiutil.ErrMissingPolicySub
|
|
}
|
|
|
|
if req.Obj == "" {
|
|
return apiutil.ErrMissingPolicyObj
|
|
}
|
|
|
|
if req.Act == "" {
|
|
return apiutil.ErrMissingPolicyAct
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listPoliciesReq struct {
|
|
Sub string
|
|
Obj string
|
|
Act string
|
|
}
|