mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:00:25 +00:00
dcd5ff914d
* initial implementation Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * initial implementation Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * add remove report from nats handler Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * add license header Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * fix failing linter Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * remove unused code Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update docker compose Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * address comments Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * fix failing linter Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * move runinfo to pkg Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update report handler Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update reports handler Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update handler in reports Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update repo method from time to due Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * fix validation methods Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * address comments Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update reports port to 9017 Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update nginx to support reports Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * fix reports location in nginx Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> * update env variable Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> --------- Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
108 lines
1.7 KiB
Go
108 lines
1.7 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/absmach/magistrala/pkg/schedule"
|
|
"github.com/absmach/magistrala/re"
|
|
api "github.com/absmach/supermq/api/http"
|
|
apiutil "github.com/absmach/supermq/api/http/util"
|
|
)
|
|
|
|
const (
|
|
maxLimitSize = 1000
|
|
MaxNameSize = 1024
|
|
MaxTitleSize = 37
|
|
)
|
|
|
|
type addRuleReq struct {
|
|
re.Rule
|
|
}
|
|
|
|
func (req addRuleReq) validate() error {
|
|
if len(req.Name) > api.MaxNameSize || req.Name == "" {
|
|
return apiutil.ErrNameSize
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type viewRuleReq struct {
|
|
id string
|
|
}
|
|
|
|
func (req viewRuleReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listRulesReq struct {
|
|
re.PageMeta
|
|
}
|
|
|
|
func (req listRulesReq) validate() error {
|
|
if req.Limit > maxLimitSize {
|
|
return apiutil.ErrLimitSize
|
|
}
|
|
if req.Dir != "" && (req.Dir != api.AscDir && req.Dir != api.DescDir) {
|
|
return apiutil.ErrInvalidDirection
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateRuleReq struct {
|
|
Rule re.Rule
|
|
}
|
|
|
|
func (req updateRuleReq) validate() error {
|
|
if req.Rule.ID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
if len(req.Rule.Name) > api.MaxNameSize {
|
|
return apiutil.ErrNameSize
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateRuleScheduleReq struct {
|
|
id string
|
|
Schedule schedule.Schedule `json:"schedule,omitempty"`
|
|
}
|
|
|
|
func (req updateRuleScheduleReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateRuleStatusReq struct {
|
|
id string
|
|
}
|
|
|
|
func (req updateRuleStatusReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type deleteRuleReq struct {
|
|
id string
|
|
}
|
|
|
|
func (req deleteRuleReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|