2018-08-26 13:15:48 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2018-05-10 23:53:25 +02:00
|
|
|
package http
|
2017-10-01 01:07:37 +02:00
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
import "github.com/mainflux/mainflux/things"
|
2017-10-01 01:07:37 +02:00
|
|
|
|
2018-04-18 22:36:24 +02:00
|
|
|
const maxLimitSize = 100
|
|
|
|
|
2017-10-01 01:07:37 +02:00
|
|
|
type apiReq interface {
|
|
|
|
validate() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type identityReq struct {
|
|
|
|
key string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (req identityReq) validate() error {
|
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
type addThingReq struct {
|
2018-10-24 11:21:03 +02:00
|
|
|
key string
|
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Metadata string `json:"metadata,omitempty"`
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
func (req addThingReq) validate() error {
|
2017-10-01 01:07:37 +02:00
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
if req.Type == "" {
|
|
|
|
return things.ErrMalformedEntity
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
type updateThingReq struct {
|
2018-10-24 11:21:03 +02:00
|
|
|
key string
|
|
|
|
id string
|
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Metadata string `json:"metadata,omitempty"`
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
func (req updateThingReq) validate() error {
|
2017-10-01 01:07:37 +02:00
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
if req.Type == "" {
|
|
|
|
return things.ErrMalformedEntity
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
return nil
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type createChannelReq struct {
|
2018-10-24 11:21:03 +02:00
|
|
|
key string
|
|
|
|
Name string `json:"name,omitempty"`
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req createChannelReq) validate() error {
|
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type updateChannelReq struct {
|
2018-10-24 11:21:03 +02:00
|
|
|
key string
|
|
|
|
id string
|
|
|
|
Name string `json:"name,omitempty"`
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req updateChannelReq) validate() error {
|
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type viewResourceReq struct {
|
|
|
|
key string
|
2018-10-24 11:21:03 +02:00
|
|
|
id string
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req viewResourceReq) validate() error {
|
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type listResourcesReq struct {
|
|
|
|
key string
|
2018-10-24 11:21:03 +02:00
|
|
|
offset uint64
|
|
|
|
limit uint64
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 22:36:24 +02:00
|
|
|
func (req *listResourcesReq) validate() error {
|
2017-10-01 01:07:37 +02:00
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
if req.limit == 0 || req.limit > maxLimitSize {
|
|
|
|
return things.ErrMalformedEntity
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:21:03 +02:00
|
|
|
return nil
|
2017-10-01 01:07:37 +02:00
|
|
|
}
|
2018-03-11 18:06:01 +01:00
|
|
|
|
|
|
|
type connectionReq struct {
|
2018-05-15 17:13:09 +02:00
|
|
|
key string
|
2018-10-24 11:21:03 +02:00
|
|
|
chanID string
|
|
|
|
thingID string
|
2018-03-11 18:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (req connectionReq) validate() error {
|
|
|
|
if req.key == "" {
|
2018-05-15 17:13:09 +02:00
|
|
|
return things.ErrUnauthorizedAccess
|
2018-03-11 18:06:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|