mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
a0c40ba462
* chore(license): update copyright notices Add CI check for non go files to check that the files contain a license Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix(ci): log failed files When the CI fails during check for license header, log the failed file to console so that someone can check on the actual file. Also simplify the grep check to make it more human readable and understandable Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
198 lines
3.4 KiB
Go
198 lines
3.4 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package domains
|
|
|
|
import (
|
|
"github.com/absmach/magistrala/internal/apiutil"
|
|
mfclients "github.com/absmach/magistrala/pkg/clients"
|
|
)
|
|
|
|
type page struct {
|
|
offset uint64
|
|
limit uint64
|
|
order string
|
|
dir string
|
|
name string
|
|
metadata map[string]interface{}
|
|
tag string
|
|
permission string
|
|
status mfclients.Status
|
|
}
|
|
|
|
type createDomainReq struct {
|
|
token string
|
|
Name string `json:"name"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
Tags []string `json:"tags,omitempty"`
|
|
Alias string `json:"alias,omitempty"`
|
|
}
|
|
|
|
func (req createDomainReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.Name == "" {
|
|
return apiutil.ErrMissingName
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type retrieveDomainRequest struct {
|
|
token string
|
|
domainID string
|
|
}
|
|
|
|
func (req retrieveDomainRequest) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateDomainReq struct {
|
|
token string
|
|
domainID string
|
|
Name *string `json:"name,omitempty"`
|
|
Metadata *map[string]interface{} `json:"metadata,omitempty"`
|
|
Tags *[]string `json:"tags,omitempty"`
|
|
Alias *string `json:"alias,omitempty"`
|
|
}
|
|
|
|
func (req updateDomainReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listDomainsReq struct {
|
|
token string
|
|
page
|
|
}
|
|
|
|
func (req listDomainsReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type enableDomainReq struct {
|
|
token string
|
|
domainID string
|
|
}
|
|
|
|
func (req enableDomainReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type disableDomainReq struct {
|
|
token string
|
|
domainID string
|
|
}
|
|
|
|
func (req disableDomainReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type assignUsersReq struct {
|
|
token string
|
|
domainID string
|
|
UserIDs []string `json:"user_ids"`
|
|
Relation string `json:"relation"`
|
|
}
|
|
|
|
func (req assignUsersReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
if len(req.UserIDs) == 0 {
|
|
return apiutil.ErrMalformedPolicy
|
|
}
|
|
|
|
if req.Relation == "" {
|
|
return apiutil.ErrMalformedPolicy
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type unassignUsersReq struct {
|
|
token string
|
|
domainID string
|
|
UserIDs []string `json:"user_ids"`
|
|
Relation string `json:"relation"`
|
|
}
|
|
|
|
func (req unassignUsersReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.domainID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
if len(req.UserIDs) == 0 {
|
|
return apiutil.ErrMalformedPolicy
|
|
}
|
|
|
|
if req.Relation == "" {
|
|
return apiutil.ErrMalformedPolicy
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listUserDomainsReq struct {
|
|
token string
|
|
userID string
|
|
page
|
|
}
|
|
|
|
func (req listUserDomainsReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.userID == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
|
|
return nil
|
|
}
|