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>
145 lines
2.9 KiB
Go
145 lines
2.9 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/absmach/magistrala"
|
|
"github.com/absmach/magistrala/bootstrap"
|
|
)
|
|
|
|
var (
|
|
_ magistrala.Response = (*removeRes)(nil)
|
|
_ magistrala.Response = (*configRes)(nil)
|
|
_ magistrala.Response = (*stateRes)(nil)
|
|
_ magistrala.Response = (*viewRes)(nil)
|
|
_ magistrala.Response = (*listRes)(nil)
|
|
)
|
|
|
|
type removeRes struct{}
|
|
|
|
func (res removeRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res removeRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res removeRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type configRes struct {
|
|
id string
|
|
created bool
|
|
}
|
|
|
|
func (res configRes) Code() int {
|
|
if res.created {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res configRes) Headers() map[string]string {
|
|
if res.created {
|
|
return map[string]string{
|
|
"Location": fmt.Sprintf("/things/configs/%s", res.id),
|
|
}
|
|
}
|
|
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res configRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type channelRes struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
Metadata interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
type viewRes struct {
|
|
ThingID string `json:"thing_id,omitempty"`
|
|
ThingKey string `json:"thing_key,omitempty"`
|
|
Channels []channelRes `json:"channels,omitempty"`
|
|
ExternalID string `json:"external_id"`
|
|
ExternalKey string `json:"external_key,omitempty"`
|
|
Content string `json:"content,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
State bootstrap.State `json:"state"`
|
|
ClientCert string `json:"client_cert,omitempty"`
|
|
CACert string `json:"ca_cert,omitempty"`
|
|
}
|
|
|
|
func (res viewRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res viewRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res viewRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type listRes struct {
|
|
Total uint64 `json:"total"`
|
|
Offset uint64 `json:"offset"`
|
|
Limit uint64 `json:"limit"`
|
|
Configs []viewRes `json:"configs"`
|
|
}
|
|
|
|
func (res listRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res listRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res listRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type stateRes struct{}
|
|
|
|
func (res stateRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res stateRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res stateRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type updateConfigRes struct {
|
|
ThingID string `json:"thing_id,omitempty"`
|
|
ClientCert string `json:"client_cert,omitempty"`
|
|
CACert string `json:"ca_cert,omitempty"`
|
|
ClientKey string `json:"client_key,omitempty"`
|
|
}
|
|
|
|
func (res updateConfigRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res updateConfigRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res updateConfigRes) Empty() bool {
|
|
return false
|
|
}
|