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
|
|
|
|
|
2023-06-14 12:40:37 +02:00
|
|
|
import (
|
2023-07-07 10:59:50 +03:00
|
|
|
"context"
|
2023-06-14 12:40:37 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux/pkg/clients"
|
|
|
|
)
|
|
|
|
|
2019-01-09 15:42:23 +01:00
|
|
|
// 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 {
|
2023-07-31 15:17:14 +03:00
|
|
|
ThingID string `json:"thing_id"`
|
2023-06-14 12:40:37 +02:00
|
|
|
Owner string `json:"owner,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
ClientCert string `json:"client_cert,omitempty"`
|
|
|
|
ClientKey string `json:"client_key,omitempty"`
|
|
|
|
CACert string `json:"ca_cert,omitempty"`
|
2023-07-31 15:17:14 +03:00
|
|
|
ThingKey string `json:"thing_key"`
|
|
|
|
Channels []Channel `json:"channels,omitempty"`
|
2023-06-14 12:40:37 +02:00
|
|
|
ExternalID string `json:"external_id"`
|
|
|
|
ExternalKey string `json:"external_key"`
|
|
|
|
Content string `json:"content,omitempty"`
|
|
|
|
State State `json:"state"`
|
2019-01-09 15:42:23 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:40:37 +01:00
|
|
|
// Channel represents Mainflux channel corresponding Mainflux Thing is connected to.
|
|
|
|
type Channel struct {
|
2023-06-14 12:40:37 +02:00
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
|
|
Owner string `json:"owner_id"`
|
|
|
|
Parent string `json:"parent_id,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
|
|
UpdatedBy string `json:"updated_by,omitempty"`
|
|
|
|
Status clients.Status `json:"status"`
|
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 {
|
2023-06-14 12:40:37 +02:00
|
|
|
Total uint64 `json:"total"`
|
|
|
|
Offset uint64 `json:"offset"`
|
|
|
|
Limit uint64 `json:"limit"`
|
|
|
|
Configs []Config `json:"configs"`
|
2019-02-22 14:54:09 +01:00
|
|
|
}
|
|
|
|
|
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.
|
2023-07-07 10:59:50 +03:00
|
|
|
Save(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
RetrieveByID(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
RetrieveAll(ctx context.Context, owner string, filter Filter, offset, limit uint64) ConfigsPage
|
2019-01-09 15:42:23 +01:00
|
|
|
|
|
|
|
// RetrieveByExternalID returns Config for given external ID.
|
2023-07-07 10:59:50 +03:00
|
|
|
RetrieveByExternalID(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
Update(ctx context.Context, cfg Config) error
|
2019-01-09 15:42:23 +01:00
|
|
|
|
2023-07-31 15:17:14 +03:00
|
|
|
// UpdateCerts updates and returns an existing Config certificate and owner.
|
2019-05-22 23:22:19 +02:00
|
|
|
// A non-nil error is returned to indicate operation failure.
|
2023-07-31 15:17:14 +03:00
|
|
|
UpdateCert(ctx context.Context, owner, thingID, clientCert, clientKey, caCert string) (Config, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
UpdateConnections(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
Remove(ctx context.Context, owner, id string) error
|
2019-01-09 15:42:23 +01:00
|
|
|
|
|
|
|
// ChangeState changes of the Config, that is owned by the specific user.
|
2023-07-07 10:59:50 +03:00
|
|
|
ChangeState(ctx context.Context, owner, id string, state State) error
|
2020-04-16 12:32:21 +02:00
|
|
|
|
|
|
|
// ListExisting retrieves those channels from the given list that exist in DB.
|
2023-07-07 10:59:50 +03:00
|
|
|
ListExisting(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
RemoveThing(ctx context.Context, id string) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
|
|
|
// UpdateChannel updates channel with the given ID.
|
2023-07-07 10:59:50 +03:00
|
|
|
UpdateChannel(ctx context.Context, c Channel) error
|
2019-03-04 17:41:38 +01:00
|
|
|
|
|
|
|
// RemoveChannel removes channel with the given ID.
|
2023-07-07 10:59:50 +03:00
|
|
|
RemoveChannel(ctx context.Context, 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.
|
2023-07-07 10:59:50 +03:00
|
|
|
DisconnectThing(ctx context.Context, channelID, thingID string) error
|
2019-01-09 15:42:23 +01:00
|
|
|
}
|