Documentation
¶
Overview ¶
Package things contains the domain concept definitions needed to support Mainflux things service functionality.
Index ¶
- Constants
- Variables
- type Backup
- type Channel
- type ChannelCache
- type ChannelRepository
- type ChannelsPage
- type Connection
- type Group
- type GroupMembers
- type GroupMetadata
- type GroupPage
- type GroupRepository
- type GroupRoles
- type GroupRolesPage
- type Groups
- type Identity
- type Metadata
- type Notifier
- type PageMetadata
- type Policies
- type Profile
- type RolesRepository
- type Service
- type Thing
- type ThingCache
- type ThingRepository
- type ThingsPage
- type Transformer
Constants ¶
const ( Viewer = "viewer" Editor = "editor" Admin = "admin" )
Variables ¶
var ( // ErrRetrieveGroupThings indicates failure to retrieve group things. ErrRetrieveGroupThings = errors.New("failed to retrieve group things") // ErrRetrieveGroupChannels indicates failure to retrieve group channels. ErrRetrieveGroupChannels = errors.New("failed to retrieve group channels") )
var ( // ErrConnect indicates error in adding connection ErrConnect = errors.New("add connection failed") // ErrDisconnect indicates error in removing connection ErrDisconnect = errors.New("remove connection failed") // ErrEntityConnected indicates error while checking connection in database ErrEntityConnected = errors.New("check thing-channel connection in database error") )
Functions ¶
This section is empty.
Types ¶
type Backup ¶
type Backup struct { Things []Thing Channels []Channel Connections []Connection Groups []Group GroupRoles []GroupMembers }
type Channel ¶
type Channel struct { ID string OwnerID string GroupID string Name string Profile map[string]interface{} Metadata map[string]interface{} }
Channel represents a Mainflux "communication group". This group contains the things that can exchange messages between each other.
type ChannelCache ¶
type ChannelCache interface { // Connect channel thing connection. Connect(context.Context, string, string) error // HasThing checks if thing is connected to channel. HasThing(context.Context, string, string) bool // Disconnects thing from channel. Disconnect(context.Context, string, string) error // Removes channel from cache. Remove(context.Context, string) error }
ChannelCache contains channel-thing connection caching interface.
type ChannelRepository ¶
type ChannelRepository interface { // Save persists multiple channels. Channels are saved using a transaction. If one channel // fails then none will be saved. Successful operation is indicated by non-nil // error response. Save(ctx context.Context, chs ...Channel) ([]Channel, error) // Update performs an update to the existing channel. A non-nil error is // returned to indicate operation failure. Update(ctx context.Context, c Channel) error // RetrieveByID retrieves the channel having the provided identifier, that is owned // by the specified user. RetrieveByID(ctx context.Context, id string) (Channel, error) // RetrieveByOwner retrieves the subset of channels owned by the specified user. RetrieveByOwner(ctx context.Context, owner string, pm PageMetadata) (ChannelsPage, error) // RetrieveByThing retrieves the channel connected to the given thing id. RetrieveByThing(ctx context.Context, thID string) (Channel, error) // Remove removes the channels having the provided identifiers, that is owned // by the specified user. Remove(ctx context.Context, owner string, id ...string) error // Connect connects a list of things to a channel. Connect(ctx context.Context, chID string, thIDs []string) error // Disconnect disconnects a list of things from a channel. Disconnect(ctx context.Context, chID string, thIDs []string) error // RetrieveConnByThingKey retrieves connections IDs by ThingKey RetrieveConnByThingKey(ctx context.Context, key string) (Connection, error) // RetrieveAll retrieves all channels for all users. RetrieveAll(ctx context.Context) ([]Channel, error) // RetrieveByAdmin retrieves all channels for all users with pagination. RetrieveByAdmin(ctx context.Context, pm PageMetadata) (ChannelsPage, error) // RetrieveAllConnections retrieves all connections between channels and things for all users. RetrieveAllConnections(ctx context.Context) ([]Connection, error) }
ChannelRepository specifies a channel persistence API.
type ChannelsPage ¶
type ChannelsPage struct { PageMetadata Channels []Channel }
ChannelsPage contains page related metadata as well as list of channels that belong to this page.
type Connection ¶
Connection represents a connection between a channel and a thing.
type Group ¶
type Group struct { ID string OwnerID string OrgID string Name string Description string Metadata GroupMetadata CreatedAt time.Time UpdatedAt time.Time }
Group represents the group information.
type GroupMembers ¶
type GroupMetadata ¶
type GroupMetadata map[string]interface{}
GroupMetadata defines the Metadata type.
type GroupPage ¶
type GroupPage struct { PageMetadata Groups []Group }
GroupPage contains page related metadata as well as list of groups that belong to this page.
type GroupRepository ¶
type GroupRepository interface { // Save group Save(ctx context.Context, g Group) (Group, error) // Update a group Update(ctx context.Context, g Group) (Group, error) // Remove a groups Remove(ctx context.Context, groupIDs ...string) error // RetrieveByID retrieves group by its id RetrieveByID(ctx context.Context, id string) (Group, error) // RetrieveByIDs retrieves groups by their ids RetrieveByIDs(ctx context.Context, groupIDs []string) (GroupPage, error) // RetrieveByOwner retrieves all groups. RetrieveByOwner(ctx context.Context, ownerID, orgID string, pm PageMetadata) (GroupPage, error) // RetrieveThingsByGroup retrieves page of things that are assigned to a group identified by ID. RetrieveThingsByGroup(ctx context.Context, groupID string, pm PageMetadata) (ThingsPage, error) // RetrieveChannelsByGroup retrieves page of channels that are assigned to a group identified by ID. RetrieveChannelsByGroup(ctx context.Context, groupID string, pm PageMetadata) (ChannelsPage, error) // RetrieveAll retrieves all groups. RetrieveAll(ctx context.Context) ([]Group, error) // RetrieveByAdmin retrieves all groups with pagination. RetrieveByAdmin(ctx context.Context, orgID string, pm PageMetadata) (GroupPage, error) }
GroupRepository specifies a group persistence API.
type GroupRoles ¶
type GroupRolesPage ¶
type GroupRolesPage struct { PageMetadata GroupRoles []GroupMembers }
type Groups ¶
type Groups interface { // CreateGroups adds groups to the user identified by the provided key. CreateGroups(ctx context.Context, token string, groups ...Group) ([]Group, error) // UpdateGroup updates the group identified by the provided ID. UpdateGroup(ctx context.Context, token string, g Group) (Group, error) // ViewGroup retrieves data about the group identified by ID. ViewGroup(ctx context.Context, token, id string) (Group, error) // ListGroups retrieves groups. ListGroups(ctx context.Context, token, orgID string, pm PageMetadata) (GroupPage, error) // ListGroupsByIDs retrieves groups by their IDs. ListGroupsByIDs(ctx context.Context, ids []string) ([]Group, error) // ListThingsByGroup retrieves page of things that are assigned to a group identified by ID. ListThingsByGroup(ctx context.Context, token string, groupID string, pm PageMetadata) (ThingsPage, error) // ListChannelsByGroup retrieves page of channels that are assigned to a group identified by ID. ListChannelsByGroup(ctx context.Context, token string, groupID string, pm PageMetadata) (ChannelsPage, error) // ViewGroupByThing retrieves group that thing belongs to. ViewGroupByThing(ctx context.Context, token, thingID string) (Group, error) // RemoveGroups removes the groups identified with the provided IDs. RemoveGroups(ctx context.Context, token string, ids ...string) error // ViewGroupByChannel retrieves group that channel belongs to. ViewGroupByChannel(ctx context.Context, token, channelID string) (Group, error) }
type Metadata ¶
type Metadata map[string]interface{}
Metadata to be used for Mainflux thing or channel for customized describing of particular thing or channel.
type PageMetadata ¶
type PageMetadata struct { Total uint64 Offset uint64 `json:"offset,omitempty"` Limit uint64 `json:"limit,omitempty"` Name string `json:"name,omitempty"` Order string `json:"order,omitempty"` Dir string `json:"dir,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
PageMetadata contains page metadata that helps navigation.
type Policies ¶
type Policies interface { // CreateRolesByGroup creates policies of the group identified by the provided ID. CreateRolesByGroup(ctx context.Context, token, groupID string, gps ...GroupRoles) error // ListRolesByGroup retrieves a page of policies for a group that is identified by the provided ID. ListRolesByGroup(ctx context.Context, token, groupID string, pm PageMetadata) (GroupRolesPage, error) // UpdateRolesByGroup updates policies of the group identified by the provided ID. UpdateRolesByGroup(ctx context.Context, token, groupID string, gps ...GroupRoles) error // RemoveRolesByGroup removes policies of the group identified by the provided ID. RemoveRolesByGroup(ctx context.Context, token, groupID string, memberIDs ...string) error }
type RolesRepository ¶
type RolesRepository interface { // SaveRolesByGroup saves group roles by group ID. SaveRolesByGroup(ctx context.Context, groupID string, gps ...GroupRoles) error // RetrieveRole retrieves group role by group ID. RetrieveRole(ctc context.Context, gp GroupMembers) (string, error) // RetrieveRolesByGroup retrieves page of group roles by groupID. RetrieveRolesByGroup(ctx context.Context, groupID string, pm PageMetadata) (GroupRolesPage, error) // RetrieveAllRolesByGroup retrieves all group roles by group ID. This is used for backup. RetrieveAllRolesByGroup(ctx context.Context) ([]GroupMembers, error) // RemoveRolesByGroup removes group roles by group ID. RemoveRolesByGroup(ctx context.Context, groupID string, memberIDs ...string) error // UpdateRolesByGroup updates group roles by group ID. UpdateRolesByGroup(ctx context.Context, groupID string, gps ...GroupRoles) error }
type Service ¶
type Service interface { // CreateThings adds things to the user identified by the provided key. CreateThings(ctx context.Context, token string, things ...Thing) ([]Thing, error) // UpdateThing updates the thing identified by the provided ID, that // belongs to the user identified by the provided key. UpdateThing(ctx context.Context, token string, thing Thing) error // UpdateKey updates key value of the existing thing. A non-nil error is // returned to indicate operation failure. UpdateKey(ctx context.Context, token, id, key string) error // ViewThing retrieves data about the thing identified with the provided // ID, that belongs to the user identified by the provided key. ViewThing(ctx context.Context, token, id string) (Thing, error) // ListThings retrieves data about subset of things that belongs to the // user identified by the provided key. ListThings(ctx context.Context, token string, pm PageMetadata) (ThingsPage, error) // ListThingsByIDs retrieves data about subset of things that are identified ListThingsByIDs(ctx context.Context, ids []string) (ThingsPage, error) // ListThingsByChannel retrieves data about subset of things that are // connected or not connected to specified channel and belong to the user identified by // the provided key. ListThingsByChannel(ctx context.Context, token, chID string, pm PageMetadata) (ThingsPage, error) // RemoveThings removes the things identified with the provided IDs, that // belongs to the user identified by the provided key. RemoveThings(ctx context.Context, token string, id ...string) error // CreateChannels adds channels to the user identified by the provided key. CreateChannels(ctx context.Context, token string, channels ...Channel) ([]Channel, error) // UpdateChannel updates the channel identified by the provided ID, that // belongs to the user identified by the provided key. UpdateChannel(ctx context.Context, token string, channel Channel) error // ViewChannel retrieves data about the channel identified by the provided // ID, that belongs to the user identified by the provided key. ViewChannel(ctx context.Context, token, id string) (Channel, error) // ListChannels retrieves data about subset of channels that belongs to the // user identified by the provided key. ListChannels(ctx context.Context, token string, pm PageMetadata) (ChannelsPage, error) // ViewChannelByThing retrieves data about channel that have // specified thing connected or not connected to it and belong to the user identified by // the provided key. ViewChannelByThing(ctx context.Context, token, thID string) (Channel, error) // RemoveChannels removes the things identified by the provided IDs, that // belongs to the user identified by the provided key. RemoveChannels(ctx context.Context, token string, ids ...string) error // ViewChannelProfile retrieves channel profile. ViewChannelProfile(ctx context.Context, chID string) (Profile, error) // Connect connects a list of things to a channel. Connect(ctx context.Context, token, chID string, thIDs []string) error // Disconnect disconnects a list of things from a channel. Disconnect(ctx context.Context, token, chID string, thIDs []string) error // GetConnByKey determines whether the channel can be accessed using the // provided key and returns thing's id if access is allowed. GetConnByKey(ctx context.Context, key string) (Connection, error) // IsChannelOwner determines whether the channel can be accessed by // the given user and returns error if it cannot. IsChannelOwner(ctx context.Context, owner, chanID string) error // CanAccessGroup determines whether the thing can be accessed by // the given user and returns error if it cannot. CanAccessGroup(ctx context.Context, token, groupID, action string) error // Identify returns thing ID for given thing key. Identify(ctx context.Context, key string) (string, error) // Backup retrieves all things, channels and connections for all users. Only accessible by admin. Backup(ctx context.Context, token string) (Backup, error) // Restore adds things, channels and connections from a backup. Only accessible by admin. Restore(ctx context.Context, token string, backup Backup) error Groups Policies }
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func New ¶
func New(auth protomfx.AuthServiceClient, users protomfx.UsersServiceClient, things ThingRepository, channels ChannelRepository, groups GroupRepository, roles RolesRepository, ccache ChannelCache, tcache ThingCache, idp uuid.IDProvider) Service
New instantiates the things service implementation.
type Thing ¶
type Thing struct { ID string OwnerID string GroupID string Name string Key string Metadata Metadata }
Thing represents a Mainflux thing. Each thing is owned by one user, and it is assigned with the unique identifier and (temporary) access key.
type ThingCache ¶
type ThingCache interface { // Save stores pair thing key, thing id. Save(context.Context, string, string) error // ID returns thing ID for given key. ID(context.Context, string) (string, error) // Removes thing from cache. Remove(context.Context, string) error }
ThingCache contains thing caching interface.
type ThingRepository ¶
type ThingRepository interface { // Save persists multiple things. Things are saved using a transaction. If one thing // fails then none will be saved. Successful operation is indicated by non-nil // error response. Save(ctx context.Context, ths ...Thing) ([]Thing, error) // Update performs an update to the existing thing. A non-nil error is // returned to indicate operation failure. Update(ctx context.Context, t Thing) error // UpdateKey updates key value of the existing thing. A non-nil error is // returned to indicate operation failure. UpdateKey(ctx context.Context, owner, id, key string) error // RetrieveByID retrieves the thing having the provided identifier, that is owned // by the specified user. RetrieveByID(ctx context.Context, id string) (Thing, error) // RetrieveByKey returns thing ID for given thing key. RetrieveByKey(ctx context.Context, key string) (string, error) // RetrieveByOwner retrieves the subset of things owned by the specified user RetrieveByOwner(ctx context.Context, owner string, pm PageMetadata) (ThingsPage, error) // RetrieveByIDs retrieves the subset of things specified by given thing ids. RetrieveByIDs(ctx context.Context, thingIDs []string, pm PageMetadata) (ThingsPage, error) // RetrieveByChannel retrieves the subset of things owned by the specified // user and connected or not connected to specified channel. RetrieveByChannel(ctx context.Context, chID string, pm PageMetadata) (ThingsPage, error) // Remove removes the things having the provided identifiers, that is owned // by the specified user. Remove(ctx context.Context, owner string, ids ...string) error // RetrieveAll retrieves all things for all users. RetrieveAll(ctx context.Context) ([]Thing, error) // RetrieveByAdmin retrieves all things for all users with pagination. RetrieveByAdmin(ctx context.Context, pm PageMetadata) (ThingsPage, error) }
ThingRepository specifies a thing persistence API.
type ThingsPage ¶
type ThingsPage struct { PageMetadata Things []Thing }
ThingsPage contains page related metadata as well as list of things that belong to this page.
Directories
¶
Path | Synopsis |
---|---|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
grpc
Package grpc contains implementation of things service gRPC API.
|
Package grpc contains implementation of things service gRPC API. |
http
Package http contains implementation of things service HTTP API.
|
Package http contains implementation of things service HTTP API. |
Package postgres contains repository implementations using PostgreSQL as the underlying database.
|
Package postgres contains repository implementations using PostgreSQL as the underlying database. |
Package redis contains cache implementations using Redis as the underlying database.
|
Package redis contains cache implementations using Redis as the underlying database. |
Package standalone contains implementation for auth service in single-user scenario.
|
Package standalone contains implementation for auth service in single-user scenario. |
Package tracing contains middlewares that will add spans to existing traces.
|
Package tracing contains middlewares that will add spans to existing traces. |