Documentation ¶
Overview ¶
Package things contains the domain concept definitions needed to support Mainflux things service functionality.
Index ¶
- Constants
- type AuthorizeReq
- type Backup
- type Config
- type Group
- type GroupMember
- type GroupMembersPage
- type GroupPage
- type GroupRepository
- type Groups
- type Identity
- type Metadata
- type Notifier
- type NotifiersPage
- type PageMetadata
- type Profile
- type ProfileCache
- type ProfileRepository
- type ProfilesPage
- type PubConfInfo
- type Roles
- type RolesRepository
- type Service
- type Thing
- type ThingCache
- type ThingRepository
- type ThingsPage
- type Transformer
Constants ¶
const ( Viewer = "viewer" Editor = "editor" Admin = "admin" Owner = "owner" ThingSub = "thing" ProfileSub = "profile" GroupSub = "group" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorizeReq ¶ added in v0.22.0
type Backup ¶
type Backup struct { Things []Thing Profiles []Profile Groups []Group GroupRoles []GroupMember }
type Group ¶
type Group struct { ID string OrgID string Name string Description string Metadata Metadata CreatedAt time.Time UpdatedAt time.Time }
Group represents the group information.
type GroupMember ¶ added in v0.24.0
type GroupMembersPage ¶ added in v0.24.0
type GroupMembersPage struct { PageMetadata GroupMembers []GroupMember }
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, pm PageMetadata) (GroupPage, 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 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) // ListProfilesByGroup retrieves page of profiles that are assigned to a group identified by ID. ListProfilesByGroup(ctx context.Context, token string, groupID string, pm PageMetadata) (ProfilesPage, 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 // ViewGroupByProfile retrieves group that profile belongs to. ViewGroupByProfile(ctx context.Context, token, profileID string) (Group, error) }
type Metadata ¶
type Metadata map[string]interface{}
Metadata to be used for Mainflux thing or profile for customized describing of particular thing or profile.
type NotifiersPage ¶ added in v0.23.0
type NotifiersPage struct { PageMetadata Notifiers []Notifier }
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 Profile ¶
type Profile struct { ID string GroupID string Name string Config map[string]interface{} Metadata map[string]interface{} }
Profile represents a Mainflux "communication group". This group contains the things that can exchange messages between each other.
type ProfileCache ¶ added in v0.24.0
type ProfileCache interface { // Remove removes profile from cache. Remove(context.Context, string) error }
ProfileCache contains profile caching interface.
type ProfileRepository ¶ added in v0.24.0
type ProfileRepository interface { // Save persists multiple profiles. Profiles are saved using a transaction. If one profile // fails then none will be saved. Successful operation is indicated by non-nil // error response. Save(ctx context.Context, prs ...Profile) ([]Profile, error) // Update performs an update to the existing profile. A non-nil error is // returned to indicate operation failure. Update(ctx context.Context, c Profile) error // RetrieveByID retrieves the profile having the provided identifier, that is owned // by the specified user. RetrieveByID(ctx context.Context, id string) (Profile, error) // RetrieveByThing retrieves the profile connected to the given thing id. RetrieveByThing(ctx context.Context, thID string) (Profile, error) // Remove removes the profiles having the provided identifiers, that is owned // by the specified user. Remove(ctx context.Context, id ...string) error // RetrieveAll retrieves all profiles for all users. RetrieveAll(ctx context.Context) ([]Profile, error) // RetrieveByAdmin retrieves all profiles for all users with pagination. RetrieveByAdmin(ctx context.Context, pm PageMetadata) (ProfilesPage, error) // RetrieveByGroupIDs retrieves the subset of profiles specified by given group ids. RetrieveByGroupIDs(ctx context.Context, groupIDs []string, pm PageMetadata) (ProfilesPage, error) }
ProfileRepository specifies a profile persistence API.
type ProfilesPage ¶ added in v0.24.0
type ProfilesPage struct { PageMetadata Profiles []Profile }
ProfilesPage contains page related metadata as well as list of profiles that belong to this page.
type PubConfInfo ¶ added in v0.24.0
type Roles ¶ added in v0.24.0
type Roles interface { // CreateRolesByGroup creates roles of the group identified by the provided ID. CreateRolesByGroup(ctx context.Context, token string, gms ...GroupMember) error // ListRolesByGroup retrieves a page of roles for a group that is identified by the provided ID. ListRolesByGroup(ctx context.Context, token, groupID string, pm PageMetadata) (GroupMembersPage, error) // UpdateRolesByGroup updates roles of the group identified by the provided ID. UpdateRolesByGroup(ctx context.Context, token string, gms ...GroupMember) error // RemoveRolesByGroup removes roles 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, gms ...GroupMember) error // RetrieveRole retrieves group role by group ID. RetrieveRole(ctc context.Context, gp GroupMember) (string, error) // RetrieveRolesByGroup retrieves page of group roles by groupID. RetrieveRolesByGroup(ctx context.Context, groupID string, pm PageMetadata) (GroupMembersPage, error) // RetrieveAllRolesByGroup retrieves all group roles by group ID. This is used for backup. RetrieveAllRolesByGroup(ctx context.Context) ([]GroupMember, error) // RetrieveGroupIDsByMember retrieves the IDs of the groups to which the member belongs RetrieveGroupIDsByMember(ctx context.Context, memberID string) ([]string, 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, gms ...GroupMember) 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) // ListThingsByProfile retrieves data about subset of things that are // connected or not connected to specified profile and belong to the user identified by // the provided key. ListThingsByProfile(ctx context.Context, token, prID 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 // CreateProfiles adds profiles to the user identified by the provided key. CreateProfiles(ctx context.Context, token string, profiles ...Profile) ([]Profile, error) // UpdateProfile updates the profile identified by the provided ID, that // belongs to the user identified by the provided key. UpdateProfile(ctx context.Context, token string, profile Profile) error // ViewProfile retrieves data about the profile identified by the provided // ID, that belongs to the user identified by the provided key. ViewProfile(ctx context.Context, token, id string) (Profile, error) // ListProfiles retrieves data about subset of profiles that belongs to the // user identified by the provided key. ListProfiles(ctx context.Context, token string, pm PageMetadata) (ProfilesPage, error) // ViewProfileByThing retrieves data about profile that have // specified thing connected or not connected to it and belong to the user identified by // the provided key. ViewProfileByThing(ctx context.Context, token, thID string) (Profile, error) // RemoveProfiles removes the things identified by the provided IDs, that // belongs to the user identified by the provided key. RemoveProfiles(ctx context.Context, token string, ids ...string) error // GetPubConfByKey determines whether the profile can be accessed using the // provided key and returns thing's id if access is allowed. GetPubConfByKey(ctx context.Context, key string) (PubConfInfo, error) // GetConfigByThingID returns profile config for given thing ID. GetConfigByThingID(ctx context.Context, thingID string) (map[string]interface{}, error) // Authorize determines whether the group and its things and profiles can be accessed by // the given user and returns error if it cannot. Authorize(ctx context.Context, req AuthorizeReq) error // Identify returns thing ID for given thing key. Identify(ctx context.Context, key string) (string, error) // GetGroupIDByThingID returns a thing's group ID for given thing ID. GetGroupIDByThingID(ctx context.Context, thingID string) (string, error) // Backup retrieves all things, profiles, groups, and groups roles for all users. Only accessible by admin. Backup(ctx context.Context, token string) (Backup, error) // Restore adds things, profiles, groups, and groups roles from a backup. Only accessible by admin. Restore(ctx context.Context, token string, backup Backup) error Groups Roles }
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, profiles ProfileRepository, groups GroupRepository, roles RolesRepository, pcache ProfileCache, tcache ThingCache, idp uuid.IDProvider) Service
New instantiates the things service implementation.
type Thing ¶
type Thing struct { ID string GroupID string ProfileID 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) // Remove removes thing from cache. Remove(context.Context, string) error // SaveRole stores pair groupID:memberID, role. SaveRole(context.Context, string, string, string) error // Role returns group member role by given groupID and memberID. Role(context.Context, string, string) (string, error) // RemoveRole removes group member role from cache. RemoveRole(context.Context, string, 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, 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) // RetrieveByGroupIDs retrieves the subset of things specified by given group ids. RetrieveByGroupIDs(ctx context.Context, groupIDs []string, pm PageMetadata) (ThingsPage, error) // RetrieveByProfile retrieves the subset of things assigned to the specified profile. RetrieveByProfile(ctx context.Context, prID string, pm PageMetadata) (ThingsPage, error) // Remove removes the things having the provided identifiers, that is owned // by the specified user. Remove(ctx context.Context, 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. |