1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-01 13:48:56 +08:00
Manuel Imperiale 9e0947a355
MF-1261 - Use StatusUnauthorized for authn and StatusForbidden for authz (#1538)
* MF-1261 - Use StatusUnauthorized for authn and StatusForbidden for authz

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* ErrExternalKey typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Rename ErrUnauthorizedAcces -> ErrAuthentication

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix bootstrap error

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix status code in openapi

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix test description

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix test description

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix test description

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add errors cases

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix status codes

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add gRPC stutus code

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix tests description

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix openapi and encodeError

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix grpc message

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix test descriptions

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Revert sdk error

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2022-02-01 17:33:23 +01:00

126 lines
2.1 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package http
import (
"github.com/mainflux/mainflux/pkg/errors"
"github.com/mainflux/mainflux/twins"
)
const (
maxNameSize = 1024
maxLimitSize = 100
)
type apiReq interface {
validate() error
}
type addTwinReq struct {
token string
Name string `json:"name,omitempty"`
Definition twins.Definition `json:"definition,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req addTwinReq) validate() error {
if req.token == "" {
return errors.ErrAuthentication
}
if len(req.Name) > maxNameSize {
return errors.ErrMalformedEntity
}
return nil
}
type updateTwinReq struct {
token string
id string
Name string `json:"name,omitempty"`
Definition twins.Definition `json:"definition,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req updateTwinReq) validate() error {
if req.token == "" {
return errors.ErrAuthentication
}
if req.id == "" {
return errors.ErrMalformedEntity
}
if len(req.Name) > maxNameSize {
return errors.ErrMalformedEntity
}
return nil
}
type viewTwinReq struct {
token string
id string
}
func (req viewTwinReq) validate() error {
if req.token == "" {
return errors.ErrAuthentication
}
if req.id == "" {
return errors.ErrMalformedEntity
}
return nil
}
type listReq struct {
token string
offset uint64
limit uint64
name string
metadata map[string]interface{}
}
func (req *listReq) validate() error {
if req.token == "" {
return errors.ErrAuthentication
}
if req.limit == 0 || req.limit > maxLimitSize {
return errors.ErrMalformedEntity
}
if len(req.name) > maxNameSize {
return errors.ErrMalformedEntity
}
return nil
}
type listStatesReq struct {
token string
offset uint64
limit uint64
id string
}
func (req *listStatesReq) validate() error {
if req.token == "" {
return errors.ErrAuthentication
}
if req.id == "" {
return errors.ErrMalformedEntity
}
if req.limit == 0 || req.limit > maxLimitSize {
return errors.ErrMalformedEntity
}
return nil
}