2019-10-07 08:14:47 -06:00
|
|
|
// Copyright (c) Mainflux
|
2019-01-09 15:42:23 +01:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
// Config represents Configuration entity. It wraps information about external entity
|
|
|
|
// as well as info about corresponding Mainflux entities.
|
|
|
|
// MFThing represents corresponding Mainflux Thing ID.
|
|
|
|
// MFKey is key of corresponding Mainflux Thing.
|
|
|
|
// MFChannels is a list of Mainflux Channels corresponding Mainflux Thing connects to.
|
|
|
|
type Config struct {
|
|
|
|
MFThing string
|
|
|
|
Owner string
|
2019-02-06 10:28:54 +01:00
|
|
|
Name string
|
2019-05-22 23:22:19 +02:00
|
|
|
ClientCert string
|
|
|
|
ClientKey string
|
|
|
|
CACert string
|
2019-01-09 15:42:23 +01:00
|
|
|
MFKey string
|
2019-01-30 16:40:37 +01:00
|
|
|
MFChannels []Channel
|
2019-01-09 15:42:23 +01:00
|
|
|
ExternalID string
|
|
|
|
ExternalKey string
|
|
|
|
Content string
|
|
|
|
State State
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:40:37 +01:00
|
|
|
// Channel represents Mainflux channel corresponding Mainflux Thing is connected to.
|
|
|
|
type Channel struct {
|
|
|
|
ID string
|
|
|
|
Name string
|
2019-04-16 14:58:56 +02:00
|
|
|
Metadata map[string]interface{}
|
2019-01-30 16:40:37 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 15:42:23 +01:00
|
|
|
// Filter is used for the search filters.
|
2019-02-06 10:28:54 +01:00
|
|
|
type Filter struct {
|
|
|
|
FullMatch map[string]string
|
|
|
|
PartialMatch map[string]string
|
|
|
|
}
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2019-02-22 14:54:09 +01:00
|
|
|
// ConfigsPage contains page related metadata as well as list of Configs that
|
|
|
|
// belong to this page.
|
|
|
|
type ConfigsPage struct {
|
|
|
|
Total uint64
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
Configs []Config
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:42:23 +01:00
|
|
|
// ConfigRepository specifies a Config persistence API.
|
|
|
|
type ConfigRepository interface {
|
|
|
|
// Save persists the Config. Successful operation is indicated by non-nil
|
|
|
|
// error response.
|
2020-04-16 12:32:21 +02:00
|
|
|
Save(cfg Config, chsConnIDs []string) (string, error)
|
2019-01-09 15:42:23 +01:00
|
|
|
|
|
|
|
// RetrieveByID retrieves the Config having the provided identifier, that is owned
|
|
|
|
// by the specified user.
|
2020-04-16 12:32:21 +02:00
|
|
|
RetrieveByID(owner, id string) (Config, error)
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2019-02-22 14:54:09 +01:00
|
|
|
// RetrieveAll retrieves a subset of Configs that are owned
|
|
|
|
// by the specific user, with given filter parameters.
|
2020-04-16 12:32:21 +02:00
|
|
|
RetrieveAll(owner string, filter Filter, offset, limit uint64) ConfigsPage
|
2019-01-09 15:42:23 +01:00
|
|
|
|
|
|
|
// RetrieveByExternalID returns Config for given external ID.
|
2020-04-16 12:32:21 +02:00
|
|
|
RetrieveByExternalID(externalID string) (Config, error)
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2019-05-22 23:22:19 +02:00
|
|
|
// Update updates an existing Config. A non-nil error is returned
|
2019-01-09 15:42:23 +01:00
|
|
|
// to indicate operation failure.
|
2020-04-16 12:32:21 +02:00
|
|
|
Update(cfg Config) error
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2020-04-16 12:32:21 +02:00
|
|
|
// UpdateCerts updates an existing Config certificate and owner.
|
2019-05-22 23:22:19 +02:00
|
|
|
// A non-nil error is returned to indicate operation failure.
|
2020-04-16 12:32:21 +02:00
|
|
|
UpdateCert(owner, thingID, clientCert, clientKey, caCert string) error
|
2019-05-22 23:22:19 +02:00
|
|
|
|
2019-03-04 17:41:38 +01:00
|
|
|
// UpdateConnections updates a list of Channels the Config is connected to
|
|
|
|
// adding new Channels if needed.
|
2020-04-16 12:32:21 +02:00
|
|
|
UpdateConnections(owner, id string, channels []Channel, connections []string) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
2019-01-09 15:42:23 +01:00
|
|
|
// Remove removes the Config having the provided identifier, that is owned
|
|
|
|
// by the specified user.
|
2020-04-16 12:32:21 +02:00
|
|
|
Remove(owner, id string) error
|
2019-01-09 15:42:23 +01:00
|
|
|
|
|
|
|
// ChangeState changes of the Config, that is owned by the specific user.
|
2020-04-16 12:32:21 +02:00
|
|
|
ChangeState(owner, id string, state State) error
|
|
|
|
|
|
|
|
// ListExisting retrieves those channels from the given list that exist in DB.
|
|
|
|
ListExisting(owner string, ids []string) ([]Channel, error)
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2019-03-04 17:41:38 +01:00
|
|
|
// Methods RemoveThing, UpdateChannel, and RemoveChannel are related to
|
|
|
|
// event sourcing. That's why these methods surpass ownership check.
|
|
|
|
|
|
|
|
// RemoveThing removes Config of the Thing with the given ID.
|
2020-04-16 12:32:21 +02:00
|
|
|
RemoveThing(id string) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
|
|
|
// UpdateChannel updates channel with the given ID.
|
2020-04-16 12:32:21 +02:00
|
|
|
UpdateChannel(c Channel) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
|
|
|
// RemoveChannel removes channel with the given ID.
|
2020-04-16 12:32:21 +02:00
|
|
|
RemoveChannel(id string) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
|
|
|
// DisconnectHandler changes state of the Config when the corresponding Thing is
|
|
|
|
// disconnected from the Channel.
|
2020-04-16 12:32:21 +02:00
|
|
|
DisconnectThing(channelID, thingID string) error
|
2019-01-09 15:42:23 +01:00
|
|
|
}
|