mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

* 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>
80 lines
1.3 KiB
Go
80 lines
1.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
)
|
|
|
|
const maxLimitSize = 100
|
|
|
|
type addCertsReq struct {
|
|
token string
|
|
ThingID string `json:"thing_id"`
|
|
KeyBits int `json:"key_bits"`
|
|
KeyType string `json:"key_type"`
|
|
TTL string `json:"ttl"`
|
|
}
|
|
|
|
func (req addCertsReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
|
|
if req.ThingID == "" || req.TTL == "" || req.KeyType == "" || req.KeyBits == 0 {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listReq struct {
|
|
thingID string
|
|
token string
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req *listReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
if req.limit == 0 || req.limit > maxLimitSize {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type viewReq struct {
|
|
serialID string
|
|
token string
|
|
}
|
|
|
|
func (req *viewReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
if req.serialID == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type revokeReq struct {
|
|
token string
|
|
certID string
|
|
}
|
|
|
|
func (req *revokeReq) validate() error {
|
|
if req.token == "" {
|
|
return errors.ErrAuthentication
|
|
}
|
|
|
|
if req.certID == "" {
|
|
return errors.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|