mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:10:19 +00:00
ec71a5edfd
* refactor: aligh bootstrap with new supermq architecture Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * feat: add sdk and update api docs Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: rename env variables Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * style: add empty line to config files and bootstrap docker compose file Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: add supermq sdk to magistrala sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * refactor: extend supermq sdk in magistrala sdk Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * reafctor: update responses Signed-off-by: Felix Gateru <felix.gateru@gmail.com> * ci: update api docs dir in swagger-ui deployment Signed-off-by: Felix Gateru <felix.gateru@gmail.com> --------- Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
164 lines
2.7 KiB
Go
164 lines
2.7 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/absmach/magistrala/bootstrap"
|
|
apiutil "github.com/absmach/supermq/api/http/util"
|
|
)
|
|
|
|
const maxLimitSize = 100
|
|
|
|
type addReq struct {
|
|
token string
|
|
ClientID string `json:"client_id"`
|
|
ExternalID string `json:"external_id"`
|
|
ExternalKey string `json:"external_key"`
|
|
Channels []string `json:"channels"`
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
ClientCert string `json:"client_cert"`
|
|
ClientKey string `json:"client_key"`
|
|
CACert string `json:"ca_cert"`
|
|
}
|
|
|
|
func (req addReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.ExternalID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
if req.ExternalKey == "" {
|
|
return apiutil.ErrBearerKey
|
|
}
|
|
|
|
if len(req.Channels) == 0 {
|
|
return apiutil.ErrEmptyList
|
|
}
|
|
|
|
for _, channel := range req.Channels {
|
|
if channel == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type entityReq struct {
|
|
id string
|
|
}
|
|
|
|
func (req entityReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateReq struct {
|
|
id string
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
func (req updateReq) validate() error {
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateCertReq struct {
|
|
clientID string
|
|
ClientCert string `json:"client_cert"`
|
|
ClientKey string `json:"client_key"`
|
|
CACert string `json:"ca_cert"`
|
|
}
|
|
|
|
func (req updateCertReq) validate() error {
|
|
if req.clientID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateConnReq struct {
|
|
token string
|
|
id string
|
|
Channels []string `json:"channels"`
|
|
}
|
|
|
|
func (req updateConnReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listReq struct {
|
|
filter bootstrap.Filter
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req listReq) validate() error {
|
|
if req.limit > maxLimitSize {
|
|
return apiutil.ErrLimitSize
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type bootstrapReq struct {
|
|
key string
|
|
id string
|
|
}
|
|
|
|
func (req bootstrapReq) validate() error {
|
|
if req.key == "" {
|
|
return apiutil.ErrBearerKey
|
|
}
|
|
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type changeStateReq struct {
|
|
token string
|
|
id string
|
|
State bootstrap.State `json:"state"`
|
|
}
|
|
|
|
func (req changeStateReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
if req.State != bootstrap.Inactive &&
|
|
req.State != bootstrap.Active {
|
|
return bootstrap.ErrBootstrapState
|
|
}
|
|
|
|
return nil
|
|
}
|