mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-28 13:48:49 +08:00

* Add cert fields to the BS Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add cert fields when creating a config Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add update cert endpoint Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix key column name Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add cert fields to db converters Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Secure cert update endpoint Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Authroize cert update methods Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix Bootstrap service tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add cert update service tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update endpoit tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update API docs Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update request tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix request tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update repository tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix typo in repo tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package bootstrap
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
)
|
|
|
|
// bootstrapRes represent Mainflux Response to the Bootatrap request.
|
|
// This is used as a response from ConfigReader and can easily be
|
|
// replace with any other response format.
|
|
type bootstrapRes struct {
|
|
MFThing string `json:"mainflux_id"`
|
|
MFKey string `json:"mainflux_key"`
|
|
MFChannels []channelRes `json:"mainflux_channels"`
|
|
ClientCert string `json:"client_cert,omitempty"`
|
|
ClientKey string `json:"client_key,omitempty"`
|
|
CaCert string `json:"ca_cert,omitempty"`
|
|
Content string `json:"content,omitempty"`
|
|
}
|
|
|
|
type channelRes struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
Metadata interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (res bootstrapRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res bootstrapRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res bootstrapRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type reader struct{}
|
|
|
|
// NewConfigReader return new reader which is used to generate response
|
|
// from the config.
|
|
func NewConfigReader() ConfigReader {
|
|
return reader{}
|
|
}
|
|
|
|
func (r reader) ReadConfig(cfg Config) (mainflux.Response, error) {
|
|
var channels []channelRes
|
|
for _, ch := range cfg.MFChannels {
|
|
channels = append(channels, channelRes{ID: ch.ID, Name: ch.Name, Metadata: ch.Metadata})
|
|
}
|
|
|
|
res := bootstrapRes{
|
|
MFKey: cfg.MFKey,
|
|
MFThing: cfg.MFThing,
|
|
MFChannels: channels,
|
|
ClientCert: cfg.ClientCert,
|
|
ClientKey: cfg.ClientKey,
|
|
CaCert: cfg.CACert,
|
|
Content: cfg.Content,
|
|
}
|
|
|
|
return res, nil
|
|
}
|