1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Manuel Imperiale e5278c463f
MF-1348 - Add transport errors logging (#1544)
* 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>
2022-03-03 17:13:46 +01:00

145 lines
2.3 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package api
import (
"github.com/mainflux/mainflux/internal/apiutil"
"github.com/mainflux/mainflux/users"
)
type userReq struct {
user users.User
}
func (req userReq) validate() error {
return req.user.Validate()
}
type createUserReq struct {
user users.User
token string
}
func (req createUserReq) validate() error {
return req.user.Validate()
}
type viewUserReq struct {
token string
userID string
}
func (req viewUserReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
return nil
}
type listUsersReq struct {
token string
offset uint64
limit uint64
email string
metadata users.Metadata
}
func (req listUsersReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
return nil
}
type updateUserReq struct {
token string
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req updateUserReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
return nil
}
type passwResetReq struct {
Email string `json:"email"`
Host string `json:"host"`
}
func (req passwResetReq) validate() error {
if req.Email == "" {
return apiutil.ErrMissingEmail
}
if req.Host == "" {
return apiutil.ErrMissingHost
}
return nil
}
type resetTokenReq struct {
Token string `json:"token"`
Password string `json:"password"`
ConfPass string `json:"confirm_password"`
}
func (req resetTokenReq) validate() error {
if req.Password == "" {
return apiutil.ErrMissingPass
}
if req.ConfPass == "" {
return apiutil.ErrMissingConfPass
}
if req.Token == "" {
return apiutil.ErrBearerToken
}
if req.Password != req.ConfPass {
return apiutil.ErrInvalidResetPass
}
return nil
}
type passwChangeReq struct {
token string
Password string `json:"password"`
OldPassword string `json:"old_password"`
}
func (req passwChangeReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.OldPassword == "" {
return apiutil.ErrMissingPass
}
return nil
}
type listMemberGroupReq struct {
token string
offset uint64
limit uint64
metadata users.Metadata
groupID string
}
func (req listMemberGroupReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.groupID == "" {
return apiutil.ErrMissingID
}
return nil
}