things

package
v0.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

Things

Things service provides an HTTP API for managing platform resources: things and profiles. Through this API clients are able to do the following actions:

  • provision new things
  • create new profiles
  • "connect" things into the profiles

For an in-depth explanation of the aforementioned scenarios, as well as thorough understanding of Mainflux, please check out the official documentation.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_THINGS_LOG_LEVEL Log level for Things (debug, info, warn, error) error
MF_THINGS_DB_HOST Database host address localhost
MF_THINGS_DB_PORT Database host port 5432
MF_THINGS_DB_USER Database user mainflux
MF_THINGS_DB_PASS Database password mainflux
MF_THINGS_DB Name of the database used by the service things
MF_THINGS_DB_SSL_MODE Database connection SSL mode (disable, require, verify-ca, verify-full) disable
MF_THINGS_DB_SSL_CERT Path to the PEM encoded certificate file
MF_THINGS_DB_SSL_KEY Path to the PEM encoded key file
MF_THINGS_DB_SSL_ROOT_CERT Path to the PEM encoded root certificate file
MF_THINGS_CLIENT_TLS Flag that indicates if TLS should be turned on false
MF_THINGS_CA_CERTS Path to trusted CAs in PEM format
MF_THINGS_CACHE_URL Cache database URL localhost:6379
MF_THINGS_CACHE_PASS Cache database password
MF_THINGS_CACHE_DB Cache instance name 0
MF_THINGS_ES_URL Event store URL localhost:6379
MF_THINGS_ES_PASS Event store password
MF_THINGS_ES_DB Event store instance name 0
MF_THINGS_HTTP_PORT Things service HTTP port 8182
MF_THINGS_AUTH_HTTP_PORT Things service Auth HTTP port 8989
MF_THINGS_AUTH_GRPC_PORT Things service Auth gRPC port 8181
MF_THINGS_SERVER_CERT Path to server certificate in pem format
MF_THINGS_SERVER_KEY Path to server key in pem format
MF_THINGS_STANDALONE_EMAIL User email for standalone mode (no gRPC communication with users)
MF_THINGS_STANDALONE_TOKEN User token for standalone mode that should be passed in auth header
MF_JAEGER_URL Jaeger server URL localhost:6831
MF_AUTH_GRPC_URL Auth service gRPC URL localhost:8181
MF_AUTH_GRPC_TIMEOUT Auth service gRPC request timeout in seconds 1s

Note that if you want things service to have only one user locally, you should use MF_THINGS_STANDALONE env vars. By specifying these, you don't need auth service in your deployment for users' authorization.

Deployment

The service itself is distributed as Docker container. Check the things service section in docker-compose to see how service is deployed.

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
git clone https://github.com/MainfluxLabs/mainflux

cd mainflux

# compile the things
make things

# copy binary to bin
make install

# set the environment variables and run the service
MF_THINGS_LOG_LEVEL=[Things log level] \
MF_THINGS_DB_HOST=[Database host address] \
MF_THINGS_DB_PORT=[Database host port] \
MF_THINGS_DB_USER=[Database user] \
MF_THINGS_DB_PASS=[Database password] \
MF_THINGS_DB=[Name of the database used by the service] \
MF_THINGS_DB_SSL_MODE=[SSL mode to connect to the database with] \
MF_THINGS_DB_SSL_CERT=[Path to the PEM encoded certificate file] \
MF_THINGS_DB_SSL_KEY=[Path to the PEM encoded key file] \
MF_THINGS_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] \
MF_HTTP_ADAPTER_CA_CERTS=[Path to trusted CAs in PEM format] \
MF_THINGS_CACHE_URL=[Cache database URL] \
MF_THINGS_CACHE_PASS=[Cache database password] \
MF_THINGS_CACHE_DB=[Cache instance name] \
MF_THINGS_ES_URL=[Event store URL] \
MF_THINGS_ES_PASS=[Event store password] \
MF_THINGS_ES_DB=[Event store instance name] \
MF_THINGS_HTTP_PORT=[Things service HTTP port] \
MF_THINGS_AUTH_HTTP_PORT=[Things service Auth HTTP port] \
MF_THINGS_AUTH_GRPC_PORT=[Things service Auth gRPC port] \
MF_THINGS_SERVER_CERT=[Path to server certificate] \
MF_THINGS_SERVER_KEY=[Path to server key] \
MF_THINGS_STANDALONE_EMAIL=[User email for standalone mode (no gRPC communication with auth)] \
MF_THINGS_STANDALONE_TOKEN=[User token for standalone mode that should be passed in auth header] \
MF_JAEGER_URL=[Jaeger server URL] \
MF_AUTH_GRPC_URL=[Auth service gRPC URL] \
MF_AUTH_GRPC_TIMEOUT=[Auth service gRPC request timeout in seconds] \
$GOBIN/mainfluxlabs-things

Setting MF_THINGS_CA_CERTS expects a file in PEM format of trusted CAs. This will enable TLS against the Users gRPC endpoint trusting only those CAs that are provided.

In constrained environments, sometimes it makes sense to run Things service as a standalone to reduce network traffic and simplify deployment. This means that Things service operates only using a single user and is able to authorize it without gRPC communication with Auth service. To run service in a standalone mode, set MF_THINGS_STANDALONE_EMAIL and MF_THINGS_STANDALONE_TOKEN.

Usage

For more information about service capabilities and its usage, please check out the API documentation.

Documentation

Overview

Package things contains the domain concept definitions needed to support Mainflux things service functionality.

Index

Constants

View Source
const (
	Viewer = "viewer"
	Editor = "editor"
	Admin  = "admin"
	Owner  = "owner"
)
View Source
const (
	KeyTypeInternal = "internal"
	KeyTypeExternal = "external"
)

Variables

View Source
var ErrGroupMembershipExists = errors.New("group membership already exists")

ErrGroupMembershipExists indicates that membership already exists.

View Source
var (
	ErrProfileAssigned = errors.New("profile currently assigned to thing(s)")
)

Functions

This section is empty.

Types

type Backup

type Backup struct {
	Things           []Thing
	Profiles         []Profile
	Groups           []Group
	GroupMemberships []GroupMembership
}

type Config added in v0.24.0

type Config struct {
	ContentType string      `json:"content_type"`
	Transformer Transformer `json:"transformer"`
}

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 GroupCache added in v0.25.0

type GroupCache interface {
	// RemoveGroupEntities removes all entities related to the group identified by groupID.
	RemoveGroupEntities(context.Context, string) error

	// SaveGroupMembership stores role for given groupID and memberID.
	SaveGroupMembership(context.Context, string, string, string) error

	// ViewRole returns role for given groupID and memberID.
	ViewRole(context.Context, string, string) (string, error)

	// RemoveGroupMembership removes group membership for given groupID and memberID.
	RemoveGroupMembership(context.Context, string, string) error

	// RetrieveGroupIDsByMember returns group IDs for given memberID.
	RetrieveGroupIDsByMember(context.Context, string) ([]string, error)
}

GroupCache contains group caching interface.

type GroupMembership added in v0.29.0

type GroupMembership struct {
	GroupID  string
	MemberID string
	Email    string
	Role     string
}

type GroupMemberships added in v0.29.0

type GroupMemberships interface {
	// CreateGroupMemberships adds memberships to a group identified by the provided ID.
	CreateGroupMemberships(ctx context.Context, token string, gms ...GroupMembership) error

	// ListGroupMemberships retrieves a paginated list of group memberships for the given group.
	ListGroupMemberships(ctx context.Context, token, groupID string, pm apiutil.PageMetadata) (GroupMembershipsPage, error)

	// UpdateGroupMemberships updates roles of a specific group membership.
	UpdateGroupMemberships(ctx context.Context, token string, gms ...GroupMembership) error

	// RemoveGroupMemberships removes memberships from the given group.
	RemoveGroupMemberships(ctx context.Context, token, groupID string, memberIDs ...string) error
}

GroupMemberships defines a service for managing group memberships.

type GroupMembershipsBackup added in v0.29.0

type GroupMembershipsBackup struct {
	GroupMemberships []GroupMembership
}

type GroupMembershipsPage added in v0.29.0

type GroupMembershipsPage struct {
	Total            uint64
	GroupMemberships []GroupMembership
}

type GroupMembershipsRepository added in v0.29.0

type GroupMembershipsRepository interface {
	// Save persists group memberships.
	Save(ctx context.Context, gms ...GroupMembership) error

	// RetrieveRole retrieves role of a specific group membership.
	RetrieveRole(ctx context.Context, gm GroupMembership) (string, error)

	// RetrieveByGroup retrieves a paginated list of group memberships by group ID.
	RetrieveByGroup(ctx context.Context, groupID string, pm apiutil.PageMetadata) (GroupMembershipsPage, error)

	// BackupAll retrieves all group memberships. Used for backup.
	BackupAll(ctx context.Context) ([]GroupMembership, error)

	// BackupByGroup retrieves all group memberships by group ID. This is used for backup.
	BackupByGroup(ctx context.Context, groupID string) ([]GroupMembership, error)

	// RetrieveGroupIDsByMember retrieves IDs of groups where the member belongs.
	RetrieveGroupIDsByMember(ctx context.Context, memberID string) ([]string, error)

	// Remove removes the provided group memberships.
	Remove(ctx context.Context, groupID string, memberIDs ...string) error

	// Update updates existing group memberships.
	Update(ctx context.Context, gms ...GroupMembership) error
}

GroupMembershipsRepository specifies an interface for managing group memberships in persistence.

type GroupPage

type GroupPage struct {
	Total  uint64
	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 apiutil.PageMetadata) (GroupPage, error)

	// BackupAll retrieves all groups.
	BackupAll(ctx context.Context) ([]Group, error)

	// BackupByOrg retrieves all groups by organization ID.
	BackupByOrg(ctx context.Context, orgID string) ([]Group, error)

	// RetrieveIDsByOrgMembership retrieves group IDs by org membership
	RetrieveIDsByOrgMembership(ctx context.Context, orgID, memberID string) ([]string, error)

	// RetrieveIDsByOrg retrieves all group IDs by org
	RetrieveIDsByOrg(ctx context.Context, orgID string) ([]string, error)

	// RetrieveAll retrieves all groups with pagination.
	RetrieveAll(ctx context.Context, pm apiutil.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, orgID 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 page of all groups.
	ListGroups(ctx context.Context, token string, pm apiutil.PageMetadata) (GroupPage, error)

	// ListGroupsByOrg retrieves page of groups that are assigned to an org identified by ID.
	ListGroupsByOrg(ctx context.Context, token, orgID string, pm apiutil.PageMetadata) (GroupPage, error)

	// ListThingsByGroup retrieves page of things that are assigned to a group identified by ID.
	ListThingsByGroup(ctx context.Context, token, groupID string, pm apiutil.PageMetadata) (ThingsPage, error)

	// ListProfilesByGroup retrieves page of profiles that are assigned to a group identified by ID.
	ListProfilesByGroup(ctx context.Context, token, groupID string, pm apiutil.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 GroupsBackup added in v0.29.0

type GroupsBackup struct {
	Groups []Group
}

type Identity

type Identity struct {
	ID    string
	Email string
}

Identity contains ID and Email.

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 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 {
	// SaveGroup stores group ID by given profile ID.
	SaveGroup(context.Context, string, string) error

	// RemoveGroup removes group ID by given profile ID.
	RemoveGroup(context.Context, string) error

	// ViewGroup returns group ID by given profile ID.
	ViewGroup(context.Context, string) (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

	// BackupAll retrieves all profiles for all users.
	BackupAll(ctx context.Context) ([]Profile, error)

	// BackupByGroups retrieves all profiles specified by given group ids.
	BackupByGroups(ctx context.Context, groupIDs []string) ([]Profile, error)

	// RetrieveAll retrieves all profiles for all users with pagination.
	RetrieveAll(ctx context.Context, pm apiutil.PageMetadata) (ProfilesPage, error)

	// RetrieveByGroups retrieves the subset of profiles specified by given group ids.
	RetrieveByGroups(ctx context.Context, groupIDs []string, pm apiutil.PageMetadata) (ProfilesPage, error)
}

ProfileRepository specifies a profile persistence API.

type ProfilesBackup added in v0.29.0

type ProfilesBackup struct {
	Profiles []Profile
}

type ProfilesPage added in v0.24.0

type ProfilesPage struct {
	Total    uint64
	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 PubConfInfo struct {
	PublisherID   string
	ProfileConfig map[string]interface{}
}

type Service

type Service interface {
	// CreateThings adds things to the user identified by the token.
	// The group ID for each thing is assigned based on the provided profile ID.
	CreateThings(ctx context.Context, token, profileID string, things ...Thing) ([]Thing, error)

	// UpdateThing updates the Thing identified by the provided ID, as the user authenticated by 'token',
	// who must possess required permissions in the Thing's belonging Group.
	UpdateThing(ctx context.Context, token string, thing Thing) error

	// UpdateThingGroupAndProfile updates the Thing's belonging Profile or Group.
	UpdateThingGroupAndProfile(ctx context.Context, token string, thing Thing) error

	// UpdateThingsMetadata updates the things metadata identified by the provided IDs, that
	// belongs to the user identified by the provided token.
	UpdateThingsMetadata(ctx context.Context, token string, things ...Thing) 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 apiutil.PageMetadata) (ThingsPage, error)

	// ListThingsByOrg retrieves page of things that belong to an org identified by ID.
	ListThingsByOrg(ctx context.Context, token string, orgID string, pm apiutil.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 apiutil.PageMetadata) (ThingsPage, error)

	// BackupThingsByGroup retrieves all things for given group ID.
	BackupThingsByGroup(ctx context.Context, token string, groupID string) (ThingsBackup, error)

	// RestoreThingsByGroup adds all things for a given group ID from a backup.
	RestoreThingsByGroup(ctx context.Context, token string, groupID string, backup ThingsBackup) error

	// BackupThingsByOrg retrieves all things for given org ID.
	BackupThingsByOrg(ctx context.Context, token string, orgID string) (ThingsBackup, error)

	// RestoreThingsByOrg adds all things for a given org ID from a backup.
	RestoreThingsByOrg(ctx context.Context, token string, orgID string, backup ThingsBackup) 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 token.
	// The group ID is assigned to each profile.
	CreateProfiles(ctx context.Context, token, groupID 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 apiutil.PageMetadata) (ProfilesPage, error)

	// ListProfilesByOrg retrieves page of profiles that belong to an org identified by ID.
	ListProfilesByOrg(ctx context.Context, token string, orgID string, pm apiutil.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)

	// ViewMetadataByKey retrieves metadata about the thing identified by the given key.
	ViewMetadataByKey(ctx context.Context, key ThingKey) (Metadata, 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 ThingKey) (PubConfInfo, error)

	// GetConfigByThingID returns profile config for given thing ID.
	GetConfigByThingID(ctx context.Context, thingID string) (map[string]interface{}, error)

	// CanUserAccessThing determines whether a user has access to a thing.
	CanUserAccessThing(ctx context.Context, req UserAccessReq) error

	// CanUserAccessProfile determines whether a user has access to a profile.
	CanUserAccessProfile(ctx context.Context, req UserAccessReq) error

	// CanUserAccessGroup determines whether a user has access to a group.
	CanUserAccessGroup(ctx context.Context, req UserAccessReq) error

	// CanThingAccessGroup determines whether a given thing has access to a group with a key.
	CanThingAccessGroup(ctx context.Context, req ThingAccessReq) error

	// Identify returns thing ID for given thing key.
	Identify(ctx context.Context, key ThingKey) (string, error)

	// GetGroupIDByThingID returns a thing's group ID for given thing ID.
	GetGroupIDByThingID(ctx context.Context, thingID string) (string, error)

	// GetGroupIDByProfileID returns a profile's group ID for given profile ID.
	GetGroupIDByProfileID(ctx context.Context, profileID string) (string, error)

	// GetGroupIDsByOrg returns all group IDs belonging to an org.
	GetGroupIDsByOrg(ctx context.Context, orgID string, token string) ([]string, error)

	// UpdateExternalKey updates the external key of the Thing identified by `thingID`. The authenticated user must have Editor rights within the Thing's belonging Group.
	UpdateExternalKey(ctx context.Context, token, key, thingID string) error

	// RemoveExternalKey removes the external thing key of the Thing identified by `thingID`.
	// The authenticated user must have Editor rights within the Thing's belonging Group.
	RemoveExternalKey(ctx context.Context, token, thingID string) error

	// Backup retrieves all things, profiles, groups, and groups memberships for all users. Only accessible by admin.
	Backup(ctx context.Context, token string) (Backup, error)

	// BackupGroupsByOrg retrieves all groups for given org ID.
	BackupGroupsByOrg(ctx context.Context, token string, orgID string) (GroupsBackup, error)

	// RestoreGroupsByOrg adds all groups for given org ID from a backup.
	RestoreGroupsByOrg(ctx context.Context, token string, orgID string, backup GroupsBackup) error

	// BackupGroupMemberships retrieves all group memberships for given group ID.
	BackupGroupMemberships(ctx context.Context, token string, groupID string) (GroupMembershipsBackup, error)

	// RestoreGroupMemberships adds all group memberships for given group ID from a backup.
	RestoreGroupMemberships(ctx context.Context, token string, groupID string, backup GroupMembershipsBackup) error

	// BackupProfilesByOrg retrieves all profiles for given org ID.
	BackupProfilesByOrg(ctx context.Context, token string, orgID string) (ProfilesBackup, error)

	// RestoreProfilesByOrg adds all profiles for given org ID from a backup.
	RestoreProfilesByOrg(ctx context.Context, token string, orgID string, backup ProfilesBackup) error

	// BackupProfilesByGroup retrieves all profiles for given group ID.
	BackupProfilesByGroup(ctx context.Context, token string, groupID string) (ProfilesBackup, error)

	// RestoreProfilesByGroup adds all profiles for given group ID from a backup.
	RestoreProfilesByGroup(ctx context.Context, token string, groupID string, backup ProfilesBackup) error

	// Restore adds things, profiles, groups, and groups memberships from a backup. Only accessible by admin.
	Restore(ctx context.Context, token string, backup Backup) error

	// GetThingIDsByProfile returns the IDs of all things associated with the given profile ID.
	GetThingIDsByProfile(ctx context.Context, profileID string) ([]string, error)

	Groups

	GroupMemberships
}

Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).

func New

New instantiates the things service implementation.

type Thing

type Thing struct {
	ID          string
	GroupID     string
	ProfileID   string
	Name        string
	Key         string
	ExternalKey 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 ThingAccessReq added in v0.25.0

type ThingAccessReq struct {
	ThingKey
	ID string
}

type ThingCache

type ThingCache interface {
	// Save stores the pair (thing key, thing id).
	Save(ctx context.Context, key ThingKey, thingID string) error

	// ID returns thing ID for a given thing key.
	ID(ctx context.Context, key ThingKey) (string, error)

	// RemoveThing removes thing from cache.
	RemoveThing(context.Context, string) error

	// RemoveKey removes a specific thing key from the cache.
	RemoveKey(ctx context.Context, key ThingKey) error

	// SaveGroup stores group ID by given thing ID.
	SaveGroup(context.Context, string, string) error

	// ViewGroup returns group ID by given thing ID.
	ViewGroup(context.Context, string) (string, error)

	// RemoveGroup removes group ID by given thing ID.
	RemoveGroup(context.Context, string) error
}

ThingCache contains thing caching interface.

type ThingKey added in v0.30.1

type ThingKey struct {
	Value string `json:"key"`
	Type  string `json:"type"`
}

ThingKey represents a Thing authentication key and its type

func ExtractThingKey added in v0.30.1

func ExtractThingKey(r *http.Request) ThingKey

ExtractThingKey returns the supplied thing key and its type, from the request's HTTP 'Authorization' header. If the provided key type is invalid an empty instance of ThingKey is returned.

func (ThingKey) Validate added in v0.30.1

func (tk ThingKey) Validate() error

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

	// UpdateGroupAndProfile performs a an update of an existing Thing's Profile and/or Group. A non-nil error is
	// returned to indicate operation failure.
	UpdateGroupAndProfile(ctx context.Context, t Thing) 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 based on its type.
	RetrieveByKey(ctx context.Context, key ThingKey) (string, error)

	// RetrieveByGroups retrieves the subset of things specified by given group ids.
	RetrieveByGroups(ctx context.Context, groupIDs []string, pm apiutil.PageMetadata) (ThingsPage, error)

	// RetrieveByProfile retrieves the subset of things assigned to the specified profile.
	RetrieveByProfile(ctx context.Context, prID string, pm apiutil.PageMetadata) (ThingsPage, error)

	// BackupByGroups retrieves all things specified by given group ids.
	BackupByGroups(ctx context.Context, groupIDs []string) ([]Thing, error)

	// Remove removes the things having the provided identifiers, that is owned
	// by the specified user.
	Remove(ctx context.Context, ids ...string) error

	// BackupAll retrieves all things for all users.
	BackupAll(ctx context.Context) ([]Thing, error)

	// RetrieveAll retrieves all things for all users with pagination.
	RetrieveAll(ctx context.Context, pm apiutil.PageMetadata) (ThingsPage, error)

	// UpdateExternalKey sets/updates the external key of the Thing identified by `thingID`.
	UpdateExternalKey(ctx context.Context, key, thingID string) error

	// RemoveExternalKey removes an external key from the thing identified by `thingID`.
	RemoveExternalKey(ctx context.Context, thingID string) error
}

ThingRepository specifies a thing persistence API.

type ThingsBackup added in v0.29.0

type ThingsBackup struct {
	Things []Thing
}

type ThingsPage

type ThingsPage struct {
	Total  uint64
	Things []Thing
}

ThingsPage contains page related metadata as well as list of things that belong to this page.

type Transformer

type Transformer struct {
	DataFilters  []string `json:"data_filters"`
	DataField    string   `json:"data_field"`
	TimeField    string   `json:"time_field"`
	TimeFormat   string   `json:"time_format"`
	TimeLocation string   `json:"time_location"`
}

type UserAccessReq added in v0.25.0

type UserAccessReq struct {
	Token  string
	ID     string
	Action string
}

Directories

Path Synopsis
api
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL